[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.
This commit is contained in:
Josse Colpaert
2017-04-04 17:36:02 +02:00
parent 42e1efded5
commit 11f0a5c29f
2 changed files with 44 additions and 2 deletions
+23 -2
View File
@@ -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 += "<b>" + _('The ordered quantity has been decreased. Do not forget to take it into account on your bills and receipts.') + '</b><br/>'
msg += "<ul>"
for line in order_lines:
msg += "<li> %s:" % (line.product_id.display_name,)
msg += "<br/>" + _("Ordered Quantity") + ": %s -> %s <br/>" % (line.product_qty, float(values['product_qty']),)
if line.product_id.type in ('product', 'consu'):
msg += _("Received Quantity") + ": %s <br/>" % (line.qty_received,)
msg += _("Billed Quantity") + ": %s <br/></li>" % (line.qty_invoiced,)
msg += "</ul>"
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)
+21
View File
@@ -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 += "<b>" + _('The ordered quantity has been decreased. Do not forget to take it into account on your invoices and delivery orders.') + '</b>'
msg += "<ul>"
for line in order_lines:
msg += "<li> %s:" % (line.product_id.display_name,)
msg += "<br/>" + _("Ordered Quantity") + ": %s -> %s <br/>" % (line.product_uom_qty, float(values['product_uom_qty']),)
if line.product_id.type in ('consu', 'product'):
msg += _("Delivered Quantity") + ": %s <br/>" % (line.qty_delivered,)
msg += _("Invoiced Quantity") + ": %s <br/>" % (line.qty_invoiced,)
msg += "</ul>"
order.message_post(body=msg)
result = super(SaleOrderLine, self).write(values)
if lines:
lines._action_procurement_create()