From d76cb7d35900aa88a6abe8f3401a91e93c4b5e6b Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Mon, 9 Sep 2013 09:11:25 +0200 Subject: [PATCH] [IMP] warn when the quantity of a line with a reservation is changed that the qty of the reservation will be changed --- stock_reserve_sale/model/sale.py | 54 +++++++++++++++++++------------- 1 file changed, 33 insertions(+), 21 deletions(-) diff --git a/stock_reserve_sale/model/sale.py b/stock_reserve_sale/model/sale.py index 818d2a2a6..f1619d519 100644 --- a/stock_reserve_sale/model/sale.py +++ b/stock_reserve_sale/model/sale.py @@ -128,34 +128,46 @@ class sale_order_line(orm.Model): return result assert len(ids) == 1, "Expected 1 ID, got %r" % ids line = self.browse(cr, uid, ids[0], context=context) - if qty != line.product_uom_qty: - # TODO append to the other warnings - result['warning'] = { - 'title': _('Configuration Error!'), - 'message' : 'bla bla', - } - + if qty != line.product_uom_qty and line.reservation_id: + msg = _("As you changed the quantity of the line, " + "the quantity of the stock reservation will " + "be automatically adjusted to %.2f.") % qty + msg += "\n\n" + result.setdefault('warning', {}) + if result['warning'].get('message'): + result['warning']['message'] += msg + else: + result['warning'] = { + 'title': _('Configuration Error!'), + 'message': msg, + } return result def write(self, cr, uid, ids, vals, context=None): - # TODO: 'product_qty', 'product_uos_qty': warn on onchange block_on_reserve = ('product_id', 'product_uom', 'product_uos') - update_on_reserve = 'price_unit', + update_on_reserve = ('price_unit', 'product_uom_qty', 'product_uos_qty') keys = set(vals.keys()) test_block = keys.intersection(block_on_reserve) test_update = keys.intersection(update_on_reserve) - if test_block or test_update: + if test_block: for line in self.browse(cr, uid, ids, context=context): if not line.reservation_id: continue - if test_block: - raise orm.except_orm( - _('Error'), - _('You cannot change the product or unit of measure ' - 'of lines with a stock reservation. ' - 'Release the reservation ' - 'before changing the product.')) - if test_update: - line.reservation_id.write({'price_unit': vals['price_unit']}) - - return super(sale_order_line, self).write(cr, uid, ids, vals, context=context) + raise orm.except_orm( + _('Error'), + _('You cannot change the product or unit of measure ' + 'of lines with a stock reservation. ' + 'Release the reservation ' + 'before changing the product.')) + res = super(sale_order_line, self).write(cr, uid, ids, vals, context=context) + if test_update: + for line in self.browse(cr, uid, ids, context=context): + if not line.reservation_id: + continue + line.reservation_id.write( + {'price_unit': line.price_unit, + 'product_qty': line.product_uom_qty, + 'product_uos_qty': line.product_uos_qty, + } + ) + return res