Class: Caboose::InvoicePackageCalculator
- Inherits:
-
Object
- Object
- Caboose::InvoicePackageCalculator
- Defined in:
- app/models/caboose/invoice_package_calculator.rb
Class Method Summary collapse
- .custom_invoice_packages(store_config, invoice) ⇒ Object
- .invoice_packages(invoice) ⇒ Object
- .rate(invoice) ⇒ Object
Class Method Details
.custom_invoice_packages(store_config, invoice) ⇒ Object
7 8 9 |
# File 'app/models/caboose/invoice_package_calculator.rb', line 7 def self.custom_invoice_packages(store_config, invoice) return eval(store_config.custom_packages_function) end |
.invoice_packages(invoice) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/models/caboose/invoice_package_calculator.rb', line 11 def self.invoice_packages(invoice) return [] if Caboose::store_shipping.nil? sc = invoice.site.store_config if !sc.auto_calculate_packages invoice_packages = self.custom_invoice_packages(sc, invoice) return invoice_packages end # Remove any invoice packages LineItem.where(:invoice_id => invoice.id).update_all(:invoice_package_id => nil) InvoicePackage.where(:invoice_id => invoice.id).destroy_all # Calculate what shipping packages we'll need InvoicePackage.create_for_invoice(invoice) return all_rates end |
.rate(invoice) ⇒ Object
30 31 32 33 34 |
# File 'app/models/caboose/invoice_package_calculator.rb', line 30 def self.rate(invoice) return nil if !invoice.shipping_service_code self.rates(invoice).each { |rate| return rate if rate[:service_code] == invoice.shipping_service_code } return nil end |