From 9047db401dbdb7c849db9bd172af3a8f7611a931 Mon Sep 17 00:00:00 2001 From: Denis Ledoux Date: Thu, 24 Sep 2015 12:18:44 +0200 Subject: [PATCH] [FIX] inter_company_rules: use correct sequence and warehouse With: - Two companies 'Company A' & 'Company B' - Sequences for SO & PO for each company - `so_from_po` & `po_from_so` set to True for both companies When: - Company A created a PO with Company B as supplier, and validated it, - A SO was created for Company B, but with the sequence of Company A - And the warehouse of company A - Potentially, any fields that are company dependent (e.g. pricelist) used Company A - Company A created a SO with Company B as customer, and validated it, - A PO was created for company B, but with the sequence of Company A - Potentially, any fields that are company dependent (e.g. pricelist) used Company A This revision now ensure to force the right company for sequences and properties field. opw-649378 --- addons/inter_company_rules/models/purchase_order.py | 5 +++++ addons/inter_company_rules/models/sale_order.py | 1 + 2 files changed, 6 insertions(+) diff --git a/addons/inter_company_rules/models/purchase_order.py b/addons/inter_company_rules/models/purchase_order.py index b59592a2a1d..24151ec4117 100644 --- a/addons/inter_company_rules/models/purchase_order.py +++ b/addons/inter_company_rules/models/purchase_order.py @@ -30,6 +30,7 @@ class purchase_order(models.Model): :param company : the company of the created PO :rtype company : res.company record """ + self = self.with_context(force_company=company.id) SaleOrder = self.env['sale.order'] company_partner = self.company_id.partner_id @@ -75,9 +76,13 @@ class purchase_order(models.Model): :rtype direct_delivery_address : res.partner record """ partner_addr = partner.sudo().address_get(['default', 'invoice', 'delivery', 'contact']) + warehouse = company.warehouse_id and company.warehouse_id.company_id.id == company.id and company.warehouse_id or False + if not warehouse: + raise Warning(_('Configure correct warehouse for company(%s) from Menu: Settings/companies/companies' % (company.name))) return { 'name': self.env['ir.sequence'].sudo().next_by_code('sale.order') or '/', 'company_id': company.id, + 'warehouse_id': warehouse.id, 'client_order_ref': name, 'partner_id': partner.id, 'pricelist_id': partner.property_product_pricelist.id, diff --git a/addons/inter_company_rules/models/sale_order.py b/addons/inter_company_rules/models/sale_order.py index a8070e270ad..473dea16b0c 100644 --- a/addons/inter_company_rules/models/sale_order.py +++ b/addons/inter_company_rules/models/sale_order.py @@ -31,6 +31,7 @@ class sale_order(models.Model): :param company : the company of the created PO :rtype company : res.company record """ + self = self.with_context(force_company=company.id) PurchaseOrder = self.env['purchase.order'] company_partner = self.company_id and self.company_id.partner_id or False if not company or not company_partner.id: