From a3778ceada62ebb7935bbdf1ff19e5aeb12251b9 Mon Sep 17 00:00:00 2001 From: Yannick Tivisse Date: Fri, 7 Apr 2017 16:15:09 +0200 Subject: [PATCH] [FIX] account,sale: Select correclty the delivery partner To deduct the fiscal position, we should use the shipping partner. The field `partner_shipping_id` is defined in the sale module. Thus, we should choose this partner if the module sale is installed and if this field is set, or fallback to the original partner instead --- addons/account/models/account_invoice.py | 6 +++++- addons/sale/models/account_invoice.py | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/addons/account/models/account_invoice.py b/addons/account/models/account_invoice.py index 6c97617b659..0708f49f68f 100644 --- a/addons/account/models/account_invoice.py +++ b/addons/account/models/account_invoice.py @@ -484,7 +484,7 @@ class AccountInvoice(models.Model): account_id = pay_account.id payment_term_id = p.property_supplier_payment_term_id.id - delivery_partner_id = self.partner_shipping_id.id or self.partner_id.address_get(['delivery'])['delivery'] + delivery_partner_id = self.get_delivery_partner_id() fiscal_position = self.env['account.fiscal.position'].get_fiscal_position(self.partner_id.id, delivery_id=delivery_partner_id) # If partner has no warning, check its company @@ -513,6 +513,10 @@ class AccountInvoice(models.Model): return {'domain': {'partner_bank_id': [('id', 'in', bank_ids.ids)]}} return {} + @api.multi + def get_delivery_partner_id(self): + self.ensure_one() + return self.partner_id.address_get(['delivery'])['delivery'] @api.onchange('journal_id') def _onchange_journal_id(self): diff --git a/addons/sale/models/account_invoice.py b/addons/sale/models/account_invoice.py index 673f213609a..4fa848f2e79 100644 --- a/addons/sale/models/account_invoice.py +++ b/addons/sale/models/account_invoice.py @@ -84,6 +84,10 @@ class AccountInvoice(models.Model): return report_pages + @api.multi + def get_delivery_partner_id(self): + self.ensure_one() + return self.partner_shipping_id.id or super(AccountInvoice, self).get_delivery_partner_id() class AccountInvoiceLine(models.Model): _inherit = 'account.invoice.line'