Class: Comee::Core::SalesOrder
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Comee::Core::SalesOrder
- Defined in:
- app/models/comee/core/sales_order.rb
Constant Summary collapse
Class Method Summary collapse
- .ransackable_associations(_auth_object = nil) ⇒ Object
- .ransackable_attributes(_auth_object = nil) ⇒ Object
Instance Method Summary collapse
- #calculate_total ⇒ Object
- #calculate_total_price ⇒ Object
- #calculate_vat ⇒ Object
- #files_url ⇒ Object
- #generate_order_number ⇒ Object
- #set_parent_client_name ⇒ Object
Class Method Details
.ransackable_associations(_auth_object = nil) ⇒ Object
76 77 78 |
# File 'app/models/comee/core/sales_order.rb', line 76 def self.ransackable_associations(_auth_object = nil) %w[client customer_order shipment_address] end |
.ransackable_attributes(_auth_object = nil) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'app/models/comee/core/sales_order.rb', line 62 def self.ransackable_attributes(_auth_object = nil) %w[ id order_number status purchase_status consignee destination customer_order_id consolidator_date shipping_date ] end |
Instance Method Details
#calculate_total ⇒ Object
52 53 54 55 56 |
# File 'app/models/comee/core/sales_order.rb', line 52 def calculate_total order_items = SalesOrderItem.where(sales_order_id: id) services = AdditionalService.where(sales_order_id: id) (order_items.sum(&:total_price) + services.sum(&:total_price)).round(2) end |
#calculate_total_price ⇒ Object
42 43 44 |
# File 'app/models/comee/core/sales_order.rb', line 42 def calculate_total_price self.total_price = calculate_total end |
#calculate_vat ⇒ Object
46 47 48 49 50 |
# File 'app/models/comee/core/sales_order.rb', line 46 def calculate_vat return unless client.tax_code == "Inland" self.vat = (calculate_total * 0.19).round(2) end |
#files_url ⇒ Object
80 81 82 |
# File 'app/models/comee/core/sales_order.rb', line 80 def files_url files.attached? ? files.map { |file| Rails.application.routes.url_helpers.rails_blob_url(file, only_path: false) } : [] end |
#generate_order_number ⇒ Object
84 85 86 |
# File 'app/models/comee/core/sales_order.rb', line 84 def generate_order_number self.order_number = Util.generate_number("SalesOrder", "order_number", "SO") end |
#set_parent_client_name ⇒ Object
58 59 60 |
# File 'app/models/comee/core/sales_order.rb', line 58 def set_parent_client_name self.parent_client_name = client.parent&.name end |