From f9e6bd2e8dac6fb423c0c4eb8696787f3ad9b0f0 Mon Sep 17 00:00:00 2001 From: Lorenzo Battistini Date: Sat, 11 May 2013 11:12:34 +0200 Subject: [PATCH] [imp] tests --- stock_lot_valuation/stock.py | 32 ++++++++++-------------------- stock_lot_valuation/test/stock.yml | 5 +++++ 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/stock_lot_valuation/stock.py b/stock_lot_valuation/stock.py index 76ade3835..980854cb4 100644 --- a/stock_lot_valuation/stock.py +++ b/stock_lot_valuation/stock.py @@ -178,39 +178,30 @@ class stock_move(orm.Model): 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.product_id.lot_valuation and move.prodlot_id: - product_uom_obj = self.pool.get('product.uom') - qty = product_uom_obj._compute_qty(cr, uid, move.product_uom.id, - move.product_qty, move.product_id.uom_id.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 - new_res = (reference_amount, res[1]) - res = new_res + if move.product_id.lot_valuation and move.prodlot_id: + product_uom_obj = self.pool.get('product.uom') + qty = product_uom_obj._compute_qty(cr, uid, move.product_uom.id, + move.product_qty, move.product_id.uom_id.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 + new_res = (reference_amount, res[1]) + res = new_res return res def do_partial(self, cr, uid, ids, partial_datas, context=None): if context is None: context = {} - modified_products = [] prod_obj = self.pool.get('product.product') for pick in self.browse(cr, uid, ids, context=context): for move in pick.move_lines: if move.prodlot_id and move.product_id.lot_valuation and ( pick.type == 'in') and (move.prodlot_id.cost_method == 'average'): - - # Hack to avoid Average price computation on product - move.product_id.write({'cost_method': 'standard'}) - modified_products.append(move.product_id.id) - self.pool.get('stock.picking').compute_price( cr, uid, partial_datas, move, context=context) - res = super(stock_picking,self).do_partial(cr, uid, ids, partial_datas, context=context) - prod_obj.write(cr, uid, modified_products, {'cost_method': 'average'}) return res class stock_picking(orm.Model): @@ -256,7 +247,6 @@ class stock_picking(orm.Model): 'price_currency_id': product_currency}) def do_partial(self, cr, uid, ids, partial_datas, context=None): - import pdb; pdb.set_trace() if context is None: context = {} prod_obj = self.pool.get('product.product') diff --git a/stock_lot_valuation/test/stock.yml b/stock_lot_valuation/test/stock.yml index c49287338..2af374681 100644 --- a/stock_lot_valuation/test/stock.yml +++ b/stock_lot_valuation/test/stock.yml @@ -209,6 +209,7 @@ location_id: location_convenience_shop location_dest_id: location_refrigerator prodlot_id: lot_icecream_0 + cost: 100 - !python {model: stock.partial.picking }: | self.do_partial(cr, uid, [ref('partial_incomming')], context=context) @@ -216,6 +217,8 @@ I check backorder shipment after received partial shipment. - !python {model: stock.picking}: | + lot = self.pool.get('stock.production.lot').browse(cr, uid, ref('lot_icecream_0'), context=context) + assert lot.standard_price == 111.11, "Price is not updated to 111.11 (((120*50)+(100*40))/(50+40))" shipment = self.browse(cr, uid, ref("incomming_shipment")) backorder = shipment.backorder_id assert backorder, "Backorder should be created after partial shipment." @@ -223,3 +226,5 @@ for move_line in backorder.move_lines: assert move_line.product_qty == 40, "Qty in backorder does not correspond." assert move_line.state == 'done', "Move line of backorder should be closed." + balance = self.pool.get('account.account').browse(cr, uid, ref('account.stk')).balance + assert balance == 10444.4, "Purchased Stocks balance is %s, not 10444.4 (old balance + 111.11×40)" % balance