diff --git a/addons/stock/wizard/stock_change_standard_price.py b/addons/stock/wizard/stock_change_standard_price.py index b5b66f8f758..75a449cbfa4 100644 --- a/addons/stock/wizard/stock_change_standard_price.py +++ b/addons/stock/wizard/stock_change_standard_price.py @@ -98,88 +98,17 @@ class change_standard_price(osv.osv_memory): """ rec_id = context and context.get('active_id', False) - prod_obj = self.pool.get('product.template') - location_obj = self.pool.get('stock.location') - lot_obj = self.pool.get('stock.report.prodlots') - move_obj = self.pool.get('account.move') - move_line_obj = self.pool.get('account.move.line') - data_obj = self.pool.get('ir.model.data') - - res = self.read(cr, uid, ids[0], ['new_price']) - new_price = res.get('new_price',[]) - data = prod_obj.browse(cr, uid, rec_id) - diff = data.standard_price - new_price - prod_obj.write(cr, uid, rec_id, {'standard_price': new_price}) - - loc_ids = location_obj.search(cr, uid, [('account_id','<>',False),('usage','=','internal')]) - lot_ids = lot_obj.search(cr, uid, [('location_id', 'in', loc_ids),('product_id','=',rec_id)]) - qty = 0 - debit = 0.0 - credit = 0.0 - stock_input_acc = data.property_stock_account_input.id or data.categ_id.property_stock_account_input_categ.id - stock_output_acc = data.property_stock_account_output.id or data.categ_id.property_stock_account_output_categ.id - - for lots in lot_obj.browse(cr, uid, lot_ids): - qty += lots.name - - if stock_input_acc and stock_output_acc and lot_ids: - move_id = move_obj.create(cr, uid, {'journal_id': data.categ_id.property_stock_journal.id}) - if diff > 0: - credit = qty * diff - move_line_obj.create(cr, uid, { - 'name': data.name, - 'account_id': stock_input_acc, - 'credit': credit, - 'move_id': move_id - }) - for lots in lot_obj.browse(cr, uid, lot_ids): - credit = lots.name * diff - move_line_obj.create(cr, uid, { - 'name': 'Expense', - 'account_id': lots.location_id.account_id.id, - 'debit': credit, - 'move_id': move_id - }) - elif diff < 0: - debit = qty * -diff - move_line_obj.create(cr, uid, { - 'name': data.name, - 'account_id': stock_output_acc, - 'debit': debit, - 'move_id': move_id - }) - for lots in lot_obj.browse(cr, uid, lot_ids): - debit = lots.name * -diff - move_line_obj.create(cr, uid, { - 'name': 'Income', - 'account_id': lots.location_id.account_id.id, - 'credit': debit, - 'move_id': move_id - }) - else: - raise osv.except_osv(_('Warning!'),_('No Change in Price.')) - else: - raise osv.except_osv(_('Warning!'),_('No Accounts are defined for ' - 'this product on its location.\nCan\'t create Move.')) - - id2 = data_obj._get_id(cr, uid, 'account', 'view_move_tree') - id3 = data_obj._get_id(cr, uid, 'account', 'view_move_form') - - if id2: - id2 = data_obj.browse(cr, uid, id2, context=context).res_id - if id3: - id3 = data_obj.browse(cr, uid, id3, context=context).res_id - - return { - 'view_type': 'form', - 'view_mode': 'tree,form', - 'res_model': 'account.move', - 'res_id' : move_id, - 'views': [(id3,'form'),(id2,'tree')], - 'type': 'ir.actions.act_window', + assert rec_id, _('Active ID is not set in Context') + prod_obj = self.pool.get('product.product') + res = self.browse(cr, uid, ids) + datas = { + 'new_price' : res[0].new_price, + 'stock_output_account' : res[0].stock_account_output.id, + 'stock_input_account' : res[0].stock_account_input.id, + 'stock_journal' : res[0].stock_journal.id } prod_obj.do_change_standard_price(cr, uid, [rec_id], datas, context) - return {} + return {} change_standard_price()