[FIX] stock: change in stock_change_standard_price
bzr revid: mso@mso-20100430114246-cbrtz0v6tdsv4cdw
This commit is contained in:
@@ -91,68 +91,16 @@ 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:
|
||||
pass
|
||||
return {}
|
||||
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 {}
|
||||
|
||||
change_standard_price()
|
||||
|
||||
@@ -7,12 +7,17 @@
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Change Standard Price">
|
||||
<field name="new_price"/>
|
||||
<separator string="" colspan="4" />
|
||||
<label string="" colspan="2"/>
|
||||
<group col="2" colspan="2">
|
||||
<button special="cancel" string="_Cancel" icon="gtk-cancel"/>
|
||||
<button name="change_price" string="_Apply" type="object" icon="gtk-apply"/>
|
||||
<field name="new_price" on_change="onchange_price(new_price, context)" context="{'active_id': active_id}"/>
|
||||
<newline/>
|
||||
<field name="stock_account_input" domain="[('type','<>','view'),('type','<>','consolidation')]" attrs="{'readonly':[('enable_stock_in_out_acc','=',False)]}"/>
|
||||
<newline/>
|
||||
<field name="stock_account_output" domain="[('type','<>','view'),('type','<>','consolidation')]" attrs="{'readonly':[('enable_stock_in_out_acc','=',True)]}"/>
|
||||
<newline/>
|
||||
<field name="stock_journal"/>
|
||||
<field name="enable_stock_in_out_acc" invisible="1"/>
|
||||
<group col="2" colspan="4">
|
||||
<button special="cancel" string="Cancel" icon="gtk-cancel"/>
|
||||
<button name="change_price" string="Change" type="object" icon="gtk-ok"/>
|
||||
</group>
|
||||
</form>
|
||||
</field>
|
||||
@@ -30,3 +35,4 @@
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user