From d8a8768acd47b56a8315f263896ffa8538b554f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Mon, 22 Dec 2008 18:54:37 +0100 Subject: [PATCH] Add cost_price on move and fill it with the current cost_price at the move done --- move.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/move.py b/move.py index 9a1f0c8d64..9d3711d234 100644 --- a/move.py +++ b/move.py @@ -57,6 +57,7 @@ class Move(OSV): 'required': "unit_price_required", 'readonly': "state != 'draft'", }) + cost_price = fields.Numeric('Cost Price', digits=(16, 4), readonly=True) currency = fields.Many2One('currency.currency', 'Currency', states={ 'invisible': "not unit_price_required", @@ -386,6 +387,8 @@ class Move(OSV): location_obj = self.pool.get('stock.location') product_obj = self.pool.get('product.product') + vals = vals.copy() + if vals.get('state') == 'done': if not vals.get('effective_date'): vals['effective_date'] = datetime.date.today() @@ -407,6 +410,10 @@ class Move(OSV): cursor, user, vals['product'], -vals['quantity'], vals['uom'], vals['unit_price'], vals['currency'], vals['company'], context=context) + #Re-read the product because cost_price has been updated + product = product_obj.browse(cursor, user, vals['product'], + context=context) + vals['cost_price'] = product.cost_price return super(Move, self).create(cursor, user, vals, context=context) def write(self, cursor, user, ids, vals, context=None): @@ -463,8 +470,16 @@ class Move(OSV): cursor, user, move.product.id, -move.quantity, move.uom, move.unit_price, move.currency, move.company, context=context) + res = super(Move, self).write(cursor, user, ids, vals, context=context) - return super(Move, self).write(cursor, user, ids, vals, context=context) + if vals.get('state', '') == 'done': + #Re-read the move because cost_price has been updated + for move in self.browse(cursor, user, ids, context=context): + if not move.cost_price: + self.write(cursor, user, move.id, { + 'cost_price': move.product.cost_price, + }, context=context) + return res def delete(self, cursor, user, ids, context=None): for move in self.browse(cursor, user, ids, context=context):