From b6fa479000f7afdcaf4b4a48dbf9db9fc6bf9002 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9rome=20Maes?= Date: Thu, 10 Dec 2015 10:34:13 +0100 Subject: [PATCH] [FIX] inter_company_rules : misplaced sudo to prepare value to create PO/SO lines The initial problem is when generating a PO from SO (or the inverse) the taxes were not propagated to the new created line. Taxes are company dependent field : so when we create a PO in company A, the PO line contains the taxes of company A, but we want the corresponding SO line in company B to have the taxes of company B, which wasn't the case. This commit makes the taxes propagation works. The initial line is now browse as sudo() to get all the taxes related to this line (or its product). Then we filter them to keep only the ones from the right company. Do not forward port this commit, since the same patch will be applied in 9.0e --- addons/inter_company_rules/models/purchase_order.py | 5 +++-- addons/inter_company_rules/models/sale_order.py | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/addons/inter_company_rules/models/purchase_order.py b/addons/inter_company_rules/models/purchase_order.py index 24151ec4117..2665a8e69c4 100644 --- a/addons/inter_company_rules/models/purchase_order.py +++ b/addons/inter_company_rules/models/purchase_order.py @@ -51,8 +51,9 @@ class purchase_order(models.Model): # read it as sudo, because inter-compagny user can not have the access right on PO sale_order_data = self.sudo()._prepare_sale_order_data(self.name, company_partner, company, self.dest_address_id and self.dest_address_id.id or False) sale_order = SaleOrder.sudo(intercompany_uid).create(sale_order_data[0]) - for line in self.order_line: - so_line_vals = self.sudo()._prepare_sale_order_line_data(line, company, sale_order.id) + # lines are browse as sudo to access all data required to be copied on SO line (mainly for company dependent field like taxes) + for line in self.order_line.sudo(): + so_line_vals = self._prepare_sale_order_line_data(line, company, sale_order.id) SaleOrderLine.sudo(intercompany_uid).create(so_line_vals) # write supplier reference field on PO diff --git a/addons/inter_company_rules/models/sale_order.py b/addons/inter_company_rules/models/sale_order.py index 685cd70861a..a52bb404e53 100644 --- a/addons/inter_company_rules/models/sale_order.py +++ b/addons/inter_company_rules/models/sale_order.py @@ -54,8 +54,8 @@ class sale_order(models.Model): # read it as sudo, because inter-compagny user can not have the access right on PO po_vals = self.sudo()._prepare_purchase_order_data(company, company_partner) purchase_order = PurchaseOrder.sudo(intercompany_uid).create(po_vals[0]) - for line in self.order_line: - po_line_vals = self.sudo()._prepare_purchase_order_line_data(line, self.date_order, purchase_order.id, company) + for line in self.order_line.sudo(): + po_line_vals = self._prepare_purchase_order_line_data(line, self.date_order, purchase_order.id, company) PurchaseOrderLine.sudo(intercompany_uid).create(po_line_vals) # write customer reference field on SO