summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNans Lefebvre <len@odoo.com>2019-04-15 09:40:04 +0000
committerNans Lefebvre <len@odoo.com>2019-04-18 09:46:22 +0000
commite7ce0b43a637d0cf8bf40d1e6062bdbdf38ac4c2 (patch)
tree3986fd178f46884610c1196d7040a61c757066fc
parentc9c8f1b4b7809b4f498ecbb7622dc1b537ff933d (diff)
[FIX] stock_dropshipping: do not merge PO lines coming from a SO
Fine tuning of commit b9e3c153, for the same use-case. The route may not be passed in values, in which case the bug is still present. There are two ways to go around that. We could add the stock.rule in values, which contains the route. The solution we adopt here is to use the sale_line_id field on the purchase line If it is present, it was added through _prepare_purchase_order_line, and thus we want to keep track of the origin. opw 1957701 closes odoo/odoo#32683 Signed-off-by: Nans Lefebvre (len) <len@odoo.com>
-rw-r--r--addons/stock_dropshipping/models/purchase.py4
-rw-r--r--addons/stock_dropshipping/tests/test_dropship.py16
2 files changed, 19 insertions, 1 deletions
diff --git a/addons/stock_dropshipping/models/purchase.py b/addons/stock_dropshipping/models/purchase.py
index cefc96ee830..533ecc89187 100644
--- a/addons/stock_dropshipping/models/purchase.py
+++ b/addons/stock_dropshipping/models/purchase.py
@@ -17,7 +17,9 @@ class PurchaseOrderLine(models.Model):
return res
def _merge_in_existing_line(self, product_id, product_qty, product_uom, location_id, name, origin, values):
- if values.get('route_ids') and values['route_ids'] == self.env.ref('stock_dropshipping.route_drop_shipping'):
+ if values.get('sale_line_id') and values['sale_line_id'] != self.sale_line_id.id:
+ # if this is defined, this is a dropshipping line, so no
+ # this is to correctly map delivered quantities to the so lines
return False
return super(PurchaseOrderLine, self)._merge_in_existing_line(
product_id=product_id, product_qty=product_qty, product_uom=product_uom,
diff --git a/addons/stock_dropshipping/tests/test_dropship.py b/addons/stock_dropshipping/tests/test_dropship.py
index 7fb7a4ddf7c..5eb9bf8bf57 100644
--- a/addons/stock_dropshipping/tests/test_dropship.py
+++ b/addons/stock_dropshipping/tests/test_dropship.py
@@ -43,3 +43,19 @@ class TestDropship(TransactionCase):
# Update qty on SO and check PO
so.order_line.product_uom_qty = 2.00
self.assertAlmostEqual(po_line.product_qty, 2.00)
+
+ # Create a new so line
+ sol2 = self.env['sale.order.line'].create({
+ 'order_id': so.id,
+ 'name': prod.name,
+ 'product_id': prod.id,
+ 'product_uom_qty': 3.00,
+ 'product_uom': prod.uom_id.id,
+ 'price_unit': 12,
+ })
+ # there is a new line
+ pol2 = po.order_line - po_line
+ # the first line is unchanged
+ self.assertAlmostEqual(po_line.product_qty, 2.00)
+ # the new line matches the new line on the so
+ self.assertAlmostEqual(pol2.product_qty, sol2.product_uom_qty)