summaryrefslogtreecommitdiff
path: root/addons
diff options
context:
space:
mode:
authorNicolas Martinelli <nim@odoo.com>2019-04-02 08:33:15 +0000
committerNicolas Martinelli <nim@odoo.com>2019-04-02 08:33:15 +0000
commit9f2dd49c57f70f0ee1651aa19637f6c2e35cae8f (patch)
tree7f7f58eefef3e1c1cbd2a77f1dd9256a94ece5b6 /addons
parent9fc21c9b61b13e19533557656735f3d303201b26 (diff)
[FIX] product, purchase: seller in multi-company
- Create 2 companies A & B - For a product P, create a supplier info for each company using the same partner, with a different price and delay. - Order the supplier so that the one for A has a higher priority than the one for B. - Create a reordering rule for P in company B. - Run the scheduler as admin (e.g. thanks to the cron). The price taken is the price for company A instead of B. `_select_seller` is not company-aware, therefore the first matching supplier is chosen. opw-1959263 closes odoo/odoo#32328 Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
Diffstat (limited to 'addons')
-rw-r--r--addons/product/models/product.py5
-rw-r--r--addons/purchase/models/purchase.py8
2 files changed, 10 insertions, 3 deletions
diff --git a/addons/product/models/product.py b/addons/product/models/product.py
index ecf48deeb33..dba77cc1937 100644
--- a/addons/product/models/product.py
+++ b/addons/product/models/product.py
@@ -516,7 +516,10 @@ class ProductProduct(models.Model):
if date is None:
date = fields.Date.today()
res = self.env['product.supplierinfo']
- for seller in self.seller_ids:
+ sellers = self.seller_ids
+ if self.env.context.get('force_company'):
+ sellers = sellers.filtered(lambda s: not s.company_id or s.company_id.id == self.env.context['force_company'])
+ for seller in sellers:
# Set quantity in UoM of seller
quantity_uom_seller = quantity
if quantity_uom_seller and uom_id and uom_id != seller.product_uom:
diff --git a/addons/purchase/models/purchase.py b/addons/purchase/models/purchase.py
index 8f80e112b32..efab0354cbf 100644
--- a/addons/purchase/models/purchase.py
+++ b/addons/purchase/models/purchase.py
@@ -958,7 +958,11 @@ class ProcurementOrder(models.Model):
"""Return the datetime value to use as Order Date (``date_order``) for the
Purchase Order created to satisfy the given procurement. """
self.ensure_one()
- seller_delay = int(self.product_id._select_seller(quantity=self.product_qty, uom_id=self.product_uom).delay)
+ seller_delay = int(
+ self.product_id.with_context(force_company=self.company_id.id)._select_seller(
+ quantity=self.product_qty, uom_id=self.product_uom
+ ).delay
+ )
return schedule_date - relativedelta(days=seller_delay)
@api.multi
@@ -966,7 +970,7 @@ class ProcurementOrder(models.Model):
self.ensure_one()
procurement_uom_po_qty = self.product_uom._compute_quantity(self.product_qty, self.product_id.uom_po_id)
- seller = self.product_id._select_seller(
+ seller = self.product_id.with_context(force_company=self.company_id.id)._select_seller(
partner_id=supplier.name,
quantity=procurement_uom_po_qty,
date=po.date_order and po.date_order[:10],