From bac4fcbd8f82484853d532d99c47fb4eef177d39 Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Thu, 10 Dec 2015 16:39:48 +1100 Subject: [PATCH] Make sure that adjustments for billable periods have a valid order to attach to when creating/updating --- app/jobs/update_account_invoices.rb | 2 +- app/models/billable_period.rb | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/jobs/update_account_invoices.rb b/app/jobs/update_account_invoices.rb index 70ba5e53c1..4f53bec6ee 100644 --- a/app/jobs/update_account_invoices.rb +++ b/app/jobs/update_account_invoices.rb @@ -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 diff --git a/app/models/billable_period.rb b/app/models/billable_period.rb index 062f70dde8..d66c51aa48 100644 --- a/app/models/billable_period.rb +++ b/app/models/billable_period.rb @@ -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 )