From 0cd88f4d451f157fb70f640425a9073bc6a7a28b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Wed, 3 Dec 2008 12:44:33 +0100 Subject: [PATCH] Handle average price for products return to supplier --- move.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/move.py b/move.py index 506a12a625..2dcb6b2523 100644 --- a/move.py +++ b/move.py @@ -343,6 +343,8 @@ class Move(OSV): vals['effective_date'] = datetime.date.today() from_location = location_obj.browse(cursor, user, vals['from_location'], context=context) + to_location = location_obj.browse(cursor, user, + vals['to_location'], context=context) product = product_obj.browse(cursor, user, vals['product'], context=context) if from_location.type == 'supplier' \ @@ -351,6 +353,12 @@ class Move(OSV): cursor, user, vals['product'], vals['quantity'], vals['uom'], vals['unit_price'], vals['currency'], vals['company'], context=context) + if to_location.type == 'supplier' \ + and product.cost_price_method == 'average': + self._update_product_cost_price( + cursor, user, vals['product'], -vals['quantity'], + vals['uom'], vals['unit_price'], vals['currency'], + vals['company'], context=context) return super(Move, self).create(cursor, user, vals, context=context) def write(self, cursor, user, ids, vals, context=None): @@ -371,6 +379,13 @@ class Move(OSV): cursor, user, move.product.id, -move.quantity, move.uom, move.unit_price, move.currency, move.company, context=context) + if move.to_location.type == 'supplier' \ + and move.state != 'cancel' \ + and move.product.cost_price_method == 'average': + self._update_product_cost_price( + cursor, user, move.product.id, move.quantity, + move.uom, move.unit_price, move.currency, + move.company, context=context) elif vals['state'] == 'draft': if move.state == 'done': @@ -393,6 +408,13 @@ class Move(OSV): cursor, user, move.product.id, move.quantity, move.uom, move.unit_price, move.currency, move.company, context=context) + if move.to_location.type == 'supplier' \ + and move.state != 'done' \ + and move.product.cost_price_method == 'average': + self._update_product_cost_price( + cursor, user, move.product.id, -move.quantity, + move.uom, move.unit_price, move.currency, + move.company, context=context) return super(Move, self).write(cursor, user, ids, vals, context=context)