From 7ffec71af281030ba3fe48fe176aa82452a74b89 Mon Sep 17 00:00:00 2001 From: ced <> Date: Tue, 7 Aug 2007 14:30:19 +0000 Subject: [PATCH] stock: fix account move for product with average price add a column price_unit to stock.move to compute the account move line with the right price bzr revid: ced-c07540545d5966bbd0d6b48b54547c6fa9933625 --- addons/stock/stock.py | 37 +++++- addons/stock/wizard/wizard_partial_picking.py | 114 ++++++++++++++---- 2 files changed, 120 insertions(+), 31 deletions(-) diff --git a/addons/stock/stock.py b/addons/stock/stock.py index 778f4b3ff8b..096d74ee79a 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -32,6 +32,7 @@ import time import netsvc from osv import fields,osv import ir +from tools import config #---------------------------------------------------------- @@ -669,6 +670,8 @@ class stock_move(osv.osv): 'note': fields.text('Notes'), 'state': fields.selection([('draft','Draft'),('waiting','Waiting'),('confirmed','Confirmed'),('assigned','Assigned'),('done','Done'),('cancel','cancel')], 'State', readonly=True, select=True), + 'price_unit': fields.float('Unit Price', + digits=(16, int(config['price_accuracy']))), } _defaults = { 'state': lambda *a: 'draft', @@ -820,19 +823,43 @@ class stock_move(osv.osv): journal_id = move.product_id.categ_id.property_stock_journal[0] if acc_src != acc_dest: ref = move.picking_id and move.picking_id.name or False - amount = move.product_qty * move.product_id.standard_price + + if move.product_id.cost_method == 'average' and move.price_unit: + amount = move.product_qty * move.price_unit + else: + amount = move.product_qty * move.product_id.standard_price + + date = time.strftime('%Y-%m-%d') lines = [ - (0,0,{'name': move.name, 'quantity': move.product_qty, 'credit': amount, 'account_id': acc_src, 'ref': ref}), - (0,0,{'name': move.name, 'quantity': move.product_qty, 'debit': amount, 'account_id': acc_dest, 'ref': ref}) + (0, 0, { + 'name': move.name, + 'quantity': move.product_qty, + 'credit': amount, + 'account_id': acc_src, + 'ref': ref, + 'date': date}), + (0, 0, { + 'name': move.name, + 'quantity': move.product_qty, + 'debit': amount, + 'account_id': acc_dest, + 'ref': ref, + 'date': date}) ] - self.pool.get('account.move').create(cr, uid, {'name': move.name, 'journal_id': journal_id, 'line_id': lines, 'ref': ref}) + self.pool.get('account.move').create(cr, uid, + { + 'name': move.name, + 'journal_id': journal_id, + 'line_id': lines, + 'ref': ref, + }) self.write(cr, uid, ids, {'state':'done'}) wf_service = netsvc.LocalService("workflow") for id in ids: wf_service.trg_trigger(uid, 'stock.move', id, cr) - return True + stock_move() class stock_inventory(osv.osv): diff --git a/addons/stock/wizard/wizard_partial_picking.py b/addons/stock/wizard/wizard_partial_picking.py index 36802782ef5..71a29db1e98 100644 --- a/addons/stock/wizard/wizard_partial_picking.py +++ b/addons/stock/wizard/wizard_partial_picking.py @@ -38,7 +38,10 @@ from osv import osv _moves_arch = UpdateableStr() _moves_fields = {} -_moves_arch_end = '''
''' +_moves_arch_end = ''' +''' _moves_fields_end = {} def make_default(val): @@ -50,28 +53,47 @@ def _get_moves(self, cr, uid, data, context): pick_obj = pooler.get_pool(cr.dbname).get('stock.picking') pick = pick_obj.browse(cr, uid, [data['id']])[0] res = {} + _moves_fields.clear() _moves_arch_lst = ['', '') _moves_arch.string = '\n'.join(_moves_arch_lst) return res @@ -92,9 +114,7 @@ def _do_split(self, cr, uid, data, context): else: too_many.append(move) - # # Average price computation - # if (pick.type == 'in') and (move.product_id.cost_method == 'average'): product_obj = pooler.get_pool(cr.dbname).get('product.product') currency_obj = pooler.get_pool(cr.dbname).get('res.currency') @@ -112,23 +132,54 @@ def _do_split(self, cr, uid, data, context): qty = uom_obj._compute_qty(cr, uid, uom, qty, product.uom_id.id) if qty > 0: - new_price = currency_obj.compute(cr, uid, currency, user.company_id.currency_id.id, price) - new_std_price = ((product.standard_price * product.qty_available) + (new_price * qty))/(product.qty_available + qty) - product_obj.write(cr, uid, [product.id], {'standard_price': new_std_price}) + new_price = currency_obj.compute(cr, uid, currency, + user.company_id.currency_id.id, price) + new_std_price = ((product.standard_price * product.qty_available)\ + + (new_price * qty))/(product.qty_available + qty) + + product_obj.write(cr, uid, [product.id], + {'standard_price': new_std_price}) + move_obj.write(cr, uid, [move.id], {'price_unit': new_price}) for move in too_few: if not new_picking: - new_picking = pick_obj.copy(cr, uid, pick.id, {'name' : '%s (splitted)' % pick.name, 'move_lines' : [], 'state':'draft'}) - new_obj = move_obj.copy(cr, uid, move.id, {'product_qty' : data['form']['move%s' % move.id], 'product_uos_qty':data['form']['move%s' % move.id], 'picking_id' : new_picking, 'state': 'assigned', 'move_dest_id': False}) - move_obj.write(cr, uid, [move.id], {'product_qty' : move.product_qty - data['form']['move%s' % move.id], 'product_uos_qty':move.product_qty - data['form']['move%s' % move.id]}) + new_picking = pick_obj.copy(cr, uid, pick.id, + { + 'name' : '%s (splitted)' % pick.name, + 'move_lines' : [], + 'state':'draft' + }) + new_obj = move_obj.copy(cr, uid, move.id, + { + 'product_qty' : data['form']['move%s' % move.id], + 'product_uos_qty':data['form']['move%s' % move.id], + 'picking_id' : new_picking, + 'state': 'assigned', + 'move_dest_id': False, + 'price_unit': False, + }) + move_obj.write(cr, uid, [move.id], + { + 'product_qty' : move.product_qty - data['form']['move%s' % move.id], + 'product_uos_qty':move.product_qty - data['form']['move%s' % move.id], + }) if new_picking: move_obj.write(cr, uid, [c.id for c in complete], {'picking_id': new_picking}) for move in too_many: - move_obj.write(cr, uid, [move.id], {'product_qty' : data['form']['move%s' % move.id],'product_uos_qty':data['form']['move%s' % move.id] , 'picking_id': new_picking}) + move_obj.write(cr, uid, [move.id], + { + 'product_qty' : data['form']['move%s' % move.id], + 'product_uos_qty': data['form']['move%s' % move.id], + 'picking_id': new_picking, + }) else: for move in too_many: - move_obj.write(cr, uid, [move.id], {'product_qty' : data['form']['move%s' % move.id],'product_uos_qty':data['form']['move%s' % move.id]}) + move_obj.write(cr, uid, [move.id], + { + 'product_qty': data['form']['move%s' % move.id], + 'product_uos_qty': data['form']['move%s' % move.id] + }) # At first we confirm the new picking (if necessary) wf_service = netsvc.LocalService("workflow") @@ -144,20 +195,31 @@ def _do_split(self, cr, uid, data, context): wf_service.trg_validate(uid, 'stock.picking', pick.id, 'button_done', cr) return {} + class partial_picking(wizard.interface): - + states = { - 'init' : { - 'actions' : [ _get_moves ], - 'result' : { 'type' : 'form', 'arch' : _moves_arch, 'fields' : _moves_fields, 'state' : (('end', 'Cancel'),('split', 'Make Picking') )}, + 'init': { + 'actions': [ _get_moves ], + 'result': {'type': 'form', 'arch': _moves_arch, 'fields': _moves_fields, + 'state' : ( + ('end', 'Cancel'), + ('split', 'Make Picking') + ) + }, }, - 'split' : { - 'actions' : [ _do_split ], - 'result' : { 'type' : 'state', 'state' : 'end' }, + 'split': { + 'actions': [ _do_split ], + 'result': {'type': 'state', 'state': 'end'}, }, - 'end2' : { - 'actions' : [ ], - 'result' : { 'type' : 'form', 'arch' : _moves_arch_end, 'fields' : _moves_fields_end, 'state' : (('end', 'Close'),) }, + 'end2': { + 'actions': [ ], + 'result': {'type': 'form', 'arch': _moves_arch_end, + 'fields': _moves_fields_end, + 'state': ( + ('end', 'Close'), + ) + }, }, }