[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>
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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],
|
||||
|
||||
Reference in New Issue
Block a user