From 11f0a5c29fad6ecf71c92e20b0b258fe31da06f8 Mon Sep 17 00:00:00 2001 From: Josse Colpaert Date: Thu, 23 Feb 2017 16:51:20 +0100 Subject: [PATCH] [FIX] sale, purchase: better info on qty update in purchase/sale order line When the quantities on a purchase or sale line decrease, the amount of the receipt or delivery order is not adapted. Also, when the quantities increase, it is good to follow it up. That is why, when we change some quantity, a message is posted in the chatter of the purchase/sale to indicate about the change. There is also a message when you add a new line. --- addons/purchase/models/purchase.py | 25 +++++++++++++++++++++++-- addons/sale/models/sale.py | 21 +++++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/addons/purchase/models/purchase.py b/addons/purchase/models/purchase.py index 451823e2057..3700a2ad677 100644 --- a/addons/purchase/models/purchase.py +++ b/addons/purchase/models/purchase.py @@ -555,13 +555,34 @@ class PurchaseOrderLine(models.Model): line = super(PurchaseOrderLine, self).create(values) if line.order_id.state == 'purchase': line.order_id._create_picking() + msg = _("Extra line with %s ") % (line.product_id.display_name,) + line.order_id.message_post(body=msg) return line @api.multi def write(self, values): + orders = False + if 'product_qty' in values: + changed_lines = self.filtered(lambda x: x.order_id.state == 'purchase') + if changed_lines: + orders = changed_lines.mapped('order_id') + for order in orders: + order_lines = changed_lines.filtered(lambda x: x.order_id == order) + msg = "" + if any([values['product_qty'] < x.product_qty for x in order_lines]): + msg += "" + _('The ordered quantity has been decreased. Do not forget to take it into account on your bills and receipts.') + '
' + msg += "" + order.message_post(body=msg) result = super(PurchaseOrderLine, self).write(values) - orders = self.filtered(lambda x: x.order_id.state == 'purchase').mapped('order_id') - orders._create_picking() + if orders: + orders._create_picking() return result name = fields.Text(string='Description', required=True) diff --git a/addons/sale/models/sale.py b/addons/sale/models/sale.py index dda33048a23..b4f8286a959 100644 --- a/addons/sale/models/sale.py +++ b/addons/sale/models/sale.py @@ -684,16 +684,37 @@ class SaleOrderLine(models.Model): line = super(SaleOrderLine, self).create(values) if line.state == 'sale': line._action_procurement_create() + msg = _("Extra line with %s ") % (line.product_id.display_name,) + line.order_id.message_post(body=msg) return line @api.multi def write(self, values): lines = False + changed_lines = False if 'product_uom_qty' in values: precision = self.env['decimal.precision'].precision_get('Product Unit of Measure') lines = self.filtered( lambda r: r.state == 'sale' and float_compare(r.product_uom_qty, values['product_uom_qty'], precision_digits=precision) == -1) + changed_lines = self.filtered( + lambda r: r.state == 'sale' and float_compare(r.product_uom_qty, values['product_uom_qty'], precision_digits=precision) != 0) + if changed_lines: + orders = self.mapped('order_id') + for order in orders: + order_lines = changed_lines.filtered(lambda x: x.order_id == order) + msg = "" + if any([values['product_uom_qty'] < x.product_uom_qty for x in order_lines]): + msg += "" + _('The ordered quantity has been decreased. Do not forget to take it into account on your invoices and delivery orders.') + '' + msg += "" + order.message_post(body=msg) result = super(SaleOrderLine, self).write(values) if lines: lines._action_procurement_create()