From 80470b41c5510acc7798797fc58f39f0c69465f8 Mon Sep 17 00:00:00 2001 From: Lorenzo Battistini Date: Fri, 10 May 2013 11:16:54 +0200 Subject: [PATCH] [add] methods --- stock_lot_valuation/stock.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/stock_lot_valuation/stock.py b/stock_lot_valuation/stock.py index f0c9b3457..bc80286c0 100644 --- a/stock_lot_valuation/stock.py +++ b/stock_lot_valuation/stock.py @@ -21,10 +21,45 @@ from openerp.osv import fields, orm from openerp.tools.translate import _ +class stock_production_lot(osv.osv): + _inherit = "stock.production.lot" + + _columns = { + 'standard_price': fields.float('Cost', digits_compute=dp.get_precision('Lot Price'), help="Cost price (in company currency) of the lot used for standard stock valuation in accounting.", groups="base.group_user"), + 'cost_method': fields.selection([('standard','Standard Price'), ('average','Average Price')], 'Costing Method', required=True, + help="Standard Price: The cost price is manually updated at the end of a specific period (usually every year). \nAverage Price: The cost price is recomputed at each incoming shipment."), + } + + def price_get(self, cr, uid, ids, context=None): + if context is None: + context = {} + res = {} + product_uom_obj = self.pool.get('product.uom') + for lot in self.browse(cr, uid, ids, context=context): + res[lot.id] = lot['standard_price'] or 0.0 + if 'uom' in context: + uom = lot.product_id.uom_id or lot.product_id.uos_id + res[lot.id] = product_uom_obj._compute_price(cr, uid, + uom.id, res[lot.id], context['uom']) + # Convert from price_type currency to asked one + if 'currency_id' in context: + res[lot.id] = self.pool.get('res.currency').compute(cr, uid, + lot.company_id.currency_id.id, + context['currency_id'], res[lot.id],context=context) + return res + class stock_move(orm.Model): _inherit = "stock.move" def _get_reference_accounting_values_for_valuation(self, cr, uid, move, context=None): res = super(stock_move,self)._get_reference_accounting_values_for_valuation( cr, uid, move, context=context) + if not move.product_id.cost_method == 'average' or not move.price_unit: + if move.prodlot_id: + if context is None: + context = {} + currency_ctx = dict(context, currency_id = move.company_id.currency_id.id) + amount_unit = move.prodlot_id.price_get(context=currency_ctx)[move.prodlot_id.id] + reference_amount = amount_unit * qty + res[0] = reference_amount return res