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 += "
"
+ for line in order_lines:
+ msg += "- %s:" % (line.product_id.display_name,)
+ msg += "
" + _("Ordered Quantity") + ": %s -> %s
" % (line.product_qty, float(values['product_qty']),)
+ if line.product_id.type in ('product', 'consu'):
+ msg += _("Received Quantity") + ": %s
" % (line.qty_received,)
+ msg += _("Billed Quantity") + ": %s
" % (line.qty_invoiced,)
+ 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 += ""
+ for line in order_lines:
+ msg += "- %s:" % (line.product_id.display_name,)
+ msg += "
" + _("Ordered Quantity") + ": %s -> %s
" % (line.product_uom_qty, float(values['product_uom_qty']),)
+ if line.product_id.type in ('consu', 'product'):
+ msg += _("Delivered Quantity") + ": %s
" % (line.qty_delivered,)
+ msg += _("Invoiced Quantity") + ": %s
" % (line.qty_invoiced,)
+ msg += "
"
+ order.message_post(body=msg)
result = super(SaleOrderLine, self).write(values)
if lines:
lines._action_procurement_create()