diff options
| author | Victor Feyens <vfe@odoo.com> | 2019-09-14 13:11:16 +0000 |
|---|---|---|
| committer | Raphael Collet <rco@odoo.com> | 2019-11-18 12:25:05 +0000 |
| commit | 57b999d40ad89a80dd4ae40433d928c0f0d57b09 (patch) | |
| tree | 5aa5834b98c30cf3fcd3167326db8aea41201912 | |
| parent | 48b887618ccdd2950b504c8e12b77c712f4cb4c5 (diff) | |
[FIX] sale,account,purchase_requisition: multi-company
Use correct company to get fiscal positions and properties
Ensure company used to fetch fiscal positions is always the correct one
when coming from a company restricted model (company_id required, or
related.required).
NB: if the company_id isn't defined, with_company doesn't change the
environment.
purchase: get_fiscal_position doesn't consider company_id ctxt key
others: properties were accessed with potentially the wrong company.
| -rw-r--r-- | addons/account/models/account_move.py | 2 | ||||
| -rw-r--r-- | addons/purchase/models/purchase.py | 2 | ||||
| -rw-r--r-- | addons/purchase_requisition/models/purchase.py | 2 | ||||
| -rw-r--r-- | addons/sale/models/account_invoice.py | 2 | ||||
| -rw-r--r-- | addons/sale/models/sale.py | 5 | ||||
| -rw-r--r-- | addons/sale_purchase/models/sale_order.py | 2 |
6 files changed, 6 insertions, 9 deletions
diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index 2c3ff5149d6..fb1fbea2b70 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -324,7 +324,7 @@ class AccountMove(models.Model): # Find the new fiscal position. delivery_partner_id = self._get_invoice_delivery_partner_id() - new_fiscal_position_id = self.env['account.fiscal.position'].with_context(force_company=self.company_id.id).get_fiscal_position( + new_fiscal_position_id = self.env['account.fiscal.position'].with_company(self.company_id).get_fiscal_position( self.partner_id.id, delivery_id=delivery_partner_id) self.fiscal_position_id = self.env['account.fiscal.position'].browse(new_fiscal_position_id) self._recompute_dynamic_lines() diff --git a/addons/purchase/models/purchase.py b/addons/purchase/models/purchase.py index 01d58569c11..b955c1fca9a 100644 --- a/addons/purchase/models/purchase.py +++ b/addons/purchase/models/purchase.py @@ -201,7 +201,7 @@ class PurchaseOrder(models.Model): # Ensures all properties and fiscal positions # are taken with the company of the order # if not defined, with_company doesn't change anything. - self = self.with_context(force_company=self.company_id.id) + self = self.with_company(self.company_id) if not self.partner_id: self.fiscal_position_id = False self.payment_term_id = False diff --git a/addons/purchase_requisition/models/purchase.py b/addons/purchase_requisition/models/purchase.py index f424779f898..51fbe41010f 100644 --- a/addons/purchase_requisition/models/purchase.py +++ b/addons/purchase_requisition/models/purchase.py @@ -23,7 +23,7 @@ class PurchaseOrder(models.Model): payment_term = partner.property_supplier_payment_term_id FiscalPosition = self.env['account.fiscal.position'] - fpos = FiscalPosition.with_context(force_company=self.company_id.id).get_fiscal_position(partner.id) + fpos = FiscalPosition.with_company(self.company_id).get_fiscal_position(partner.id) fpos = FiscalPosition.browse(fpos) self.partner_id = partner.id diff --git a/addons/sale/models/account_invoice.py b/addons/sale/models/account_invoice.py index 4001d39cc37..31914ed894c 100644 --- a/addons/sale/models/account_invoice.py +++ b/addons/sale/models/account_invoice.py @@ -29,7 +29,7 @@ class AccountMove(models.Model): Trigger the change of fiscal position when the shipping address is modified. """ delivery_partner_id = self._get_invoice_delivery_partner_id() - fiscal_position = self.env['account.fiscal.position'].with_context(force_company=self.company_id.id).get_fiscal_position( + fiscal_position = self.env['account.fiscal.position'].with_company(self.company_id).get_fiscal_position( self.partner_id.id, delivery_id=delivery_partner_id) if fiscal_position: diff --git a/addons/sale/models/sale.py b/addons/sale/models/sale.py index 08c4f2f30f1..b528a82c43f 100644 --- a/addons/sale/models/sale.py +++ b/addons/sale/models/sale.py @@ -318,10 +318,7 @@ class SaleOrder(models.Model): """ Trigger the change of fiscal position when the shipping address is modified. """ - self.fiscal_position_id = self.env['account.fiscal.position'].with_context( - force_company=self.company_id.id).get_fiscal_position( - self.partner_id.id, - self.partner_shipping_id.id) + self.fiscal_position_id = self.env['account.fiscal.position'].with_company(self.company_id).get_fiscal_position(self.partner_id.id, self.partner_shipping_id.id) return {} @api.onchange('partner_id') diff --git a/addons/sale_purchase/models/sale_order.py b/addons/sale_purchase/models/sale_order.py index d2244ad66f2..fe54c2670c2 100644 --- a/addons/sale_purchase/models/sale_order.py +++ b/addons/sale_purchase/models/sale_order.py @@ -175,7 +175,7 @@ class SaleOrderLine(models.Model): :rtype: dict """ self.ensure_one() - self = self.with_context(force_company=self.company_id.id) + self = self.with_company(self.company_id) partner_supplier = supplierinfo.name fiscal_position_id = self.env['account.fiscal.position'].sudo().get_fiscal_position(partner_supplier.id) date_order = self._purchase_get_date_order(supplierinfo) |
