From 2dfedb5b67e600b4874aea30f997b25c22c0dafa Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Tue, 26 Apr 2016 13:40:00 +0200 Subject: [PATCH] [FIX] purchase: delete unnecessary PO line In v8.0, when a procurement is cancelled and the quantity remaining on the PO line is zero, the line is deleted. It was not the case anymore after the Purchase refactoring. opw-675493 --- addons/purchase/purchase.py | 8 +++++--- .../stock_dropshipping/test/cancellation_propagated.yml | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/addons/purchase/purchase.py b/addons/purchase/purchase.py index 0e7c8be4dde..a5932311c29 100644 --- a/addons/purchase/purchase.py +++ b/addons/purchase/purchase.py @@ -607,7 +607,7 @@ class PurchaseOrderLine(models.Model): raise UserError(_('Cannot delete a purchase order line which is in state \'%s\'.') %(line.state,)) for proc in line.procurement_ids: proc.message_post(body=_('Purchase order line deleted.')) - line.procurement_ids.write({'state': 'exception'}) + line.procurement_ids.filtered(lambda r: r.state != 'cancel').write({'state': 'exception'}) return super(PurchaseOrderLine, self).unlink() @api.model @@ -750,8 +750,10 @@ class ProcurementOrder(models.Model): if seller and seller.product_uom != procurement.purchase_line_id.product_uom: price_unit = self.env['product.uom']._compute_price(seller.product_uom.id, price_unit, to_uom_id=procurement.purchase_line_id.product_uom.id) - procurement.purchase_line_id.product_qty = product_qty - procurement.purchase_line_id.price_unit = price_unit + procurement.purchase_line_id.product_qty = product_qty + procurement.purchase_line_id.price_unit = price_unit + else: + procurement.purchase_line_id.unlink() return result diff --git a/addons/stock_dropshipping/test/cancellation_propagated.yml b/addons/stock_dropshipping/test/cancellation_propagated.yml index 44e5ff34e6f..64eef9143f9 100644 --- a/addons/stock_dropshipping/test/cancellation_propagated.yml +++ b/addons/stock_dropshipping/test/cancellation_propagated.yml @@ -101,7 +101,7 @@ # Cancel the Sales Order 1 self.cancel(cr, uid, [so1.order_line[0].procurement_ids[0].id], context=context) assert so1.order_line[0].procurement_ids[0].state == u'cancel', 'Procurement 1 should be cancelled !' - assert purchase_line.product_qty == 0.0, 'The product quantity of the first order line should be 5 and not %s' % (purchase_line.product_qty,) + assert len(purchase_ids.order_line) == 0, 'The PO line should have been unlinked!' # Check that all procurements related are cancelled for procu in procu_ids: