Make sure that adjustments for billable periods have a valid order to attach to when creating/updating

This commit is contained in:
Rob Harrington
2015-12-10 16:39:48 +11:00
parent ecd11702c3
commit bac4fcbd8f
2 changed files with 2 additions and 1 deletions

View File

@@ -38,7 +38,7 @@ class UpdateAccountInvoices
oldest_enterprise = billable_periods.first.enterprise
address = oldest_enterprise.address.dup
first, space, last = (oldest_enterprise.contact || "").partition(' ')
address.update_attributes(phone: oldest_enterprise.phone || "none")
address.update_attributes(phone: oldest_enterprise.phone) if oldest_enterprise.phone.present?
address.update_attributes(firstname: first, lastname: last) if first.present? && last.present?
account_invoice.order.update_attributes(bill_address: address, ship_address: address)
end

View File

@@ -44,6 +44,7 @@ class BillablePeriod < ActiveRecord::Base
def ensure_correct_adjustment_for(invoice)
if adjustment
# adjustment.originator = enterprise.package
adjustment.adjustable = invoice
adjustment.update_attributes( label: adjustment_label, amount: bill )
else
self.adjustment = invoice.adjustments.new( adjustment_attrs, :without_protection => true )