[FIX] stock: automatic orderpoint creation

When checking the replenishments, it sometimes creates a new reordering
rule for a product while another already exists.

To reproduce the error:
(Need purchase,sale_management)
1. Create a product P
	- Must be storable
	- In Purchase tab, add a vendor
2. Create a reordering rule for P
	- Trigger: Manual
	- Min: 0
	- Max: 0
3. Create+Confirm a SO with P
4. Go to Inventory > Operations > Replenishment
5. On P-product's line, click on "Order Once"
6. Confirm the generated RfQ
7. Repeat 3-4

Error: There are now two lines for P-product. A second reordering rule
has been automatically created but the first one does already the job.

OPW-2431780

closes odoo/odoo#65142

X-original-commit: a9d5bd2ebb28a9bf0aa8d4adb0992582e85c54fc
Signed-off-by: Adrien Widart <adwid@users.noreply.github.com>
This commit is contained in:
Adrien Widart
2021-01-27 14:28:36 +00:00
parent f36d304473
commit 6fb5ea17ee
+2 -2
View File
@@ -344,7 +344,7 @@ class StockWarehouseOrderpoint(models.Model):
orderpoint_values_list = []
for (product, warehouse), product_qty in to_refill.items():
lot_stock_id = lot_stock_id_by_warehouse[warehouse]
orderpoint = self.filtered(lambda o: o.product_id == product and o.location_id == lot_stock_id)
orderpoint = orderpoints.filtered(lambda o: o.product_id.id == product and o.location_id.id == lot_stock_id)
if orderpoint:
orderpoint[0].qty_forecast += product_qty
else:
@@ -354,7 +354,7 @@ class StockWarehouseOrderpoint(models.Model):
'warehouse_id': warehouse,
'company_id': self.env['stock.warehouse'].browse(warehouse).company_id.id,
})
orderpoint_values_list.append(orderpoint_values)
orderpoint_values_list.append(orderpoint_values)
orderpoints = self.env['stock.warehouse.orderpoint'].with_user(SUPERUSER_ID).create(orderpoint_values_list)
for orderpoint in orderpoints: