[ADD] stock: If changing cost of a product, to take this valuation delta into account with a corresponding accounting entry.
bzr revid: uco@tinyerp.co.in-20100316133419-9zzx22kcxyaoosab
This commit is contained in:
parent
70848a33ce
commit
04b333863c
|
@ -48,6 +48,7 @@ Thanks to the double entry management, the inventory controlling is powerful and
|
|||
"wizard/stock_invoice_onshipping_view.xml",
|
||||
"wizard/stock_location_product_view.xml",
|
||||
"wizard/stock_inventory_line_split_view.xml",
|
||||
"wizard/stock_change_standard_price_view.xml",
|
||||
"stock_workflow.xml",
|
||||
"stock_incoterms.xml",
|
||||
"stock_wizard.xml",
|
||||
|
|
|
@ -54,6 +54,20 @@
|
|||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_product_standard_price_form" model="ir.ui.view">
|
||||
<field name="name">product.product.standard.price.form.inherit</field>
|
||||
<field name="model">product.product</field>
|
||||
<field name="type">form</field>
|
||||
<field name="inherit_id" ref="product.product_normal_form_view"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="standard_price" position="replace">
|
||||
<group col="4" colspan="2">
|
||||
<field name="standard_price" readonly="True"/>
|
||||
<button name="%(action_view_change_standard_price)d" string="Change Price" type="action" icon="gtk-execute"/>
|
||||
</group>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_normal_property_acc_form" model="ir.ui.view">
|
||||
<field name="name">product.normal.stock.acc.property.form.inherit</field>
|
||||
|
|
|
@ -36,5 +36,7 @@ import stock_inventory_line_split
|
|||
import stock_invoice_onshipping
|
||||
import stock_location_product
|
||||
|
||||
import stock_change_standard_price
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
|
|
|
@ -0,0 +1,132 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
from osv import fields, osv
|
||||
from tools.translate import _
|
||||
|
||||
class change_standard_price(osv.osv_memory):
|
||||
_name = "stock.change.standard.price"
|
||||
_description = "Change Standard Price"
|
||||
_columns = {
|
||||
'new_price': fields.float('Price', required=True),
|
||||
}
|
||||
|
||||
def default_get(self, cr, uid, fields, context):
|
||||
"""
|
||||
@summary: To get default values for the object.
|
||||
|
||||
@param self: The object pointer.
|
||||
@param cr: A database cursor
|
||||
@param uid: ID of the user currently logged in
|
||||
@param fields: List of fields for which we want default values
|
||||
@param context: A standard dictionary
|
||||
|
||||
@return: A dictionary which of fields with values.
|
||||
|
||||
"""
|
||||
rec_id = context and context.get('active_id', False)
|
||||
res = {}
|
||||
price = self.pool.get('product.product').browse(cr, uid, rec_id)
|
||||
res['new_price'] = price.standard_price
|
||||
return res
|
||||
|
||||
def change_price(self, cr, uid, ids, context):
|
||||
"""
|
||||
@summary: Changes the Standard Price of Product.
|
||||
And creates an account move accordingly.
|
||||
|
||||
@param self: The object pointer.
|
||||
@param cr: A database cursor
|
||||
@param uid: ID of the user currently logged in
|
||||
@param ids: List of IDs selected
|
||||
@param context: A standard dictionary
|
||||
|
||||
@return:
|
||||
|
||||
"""
|
||||
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')
|
||||
|
||||
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:
|
||||
move_id = move_obj.create(cr, uid, {'journal_id': data.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.'))
|
||||
return {}
|
||||
|
||||
change_standard_price()
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
|
@ -0,0 +1,31 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
<record id="view_change_standard_price" model="ir.ui.view">
|
||||
<field name="name">Change Standard Price</field>
|
||||
<field name="model">stock.change.standard.price</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Change Standard Price">
|
||||
<field name="new_price"/>
|
||||
<newline/>
|
||||
<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>
|
||||
</record>
|
||||
|
||||
<record id="action_view_change_standard_price" model="ir.actions.act_window">
|
||||
<field name="name">Change Standard Price</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">stock.change.standard.price</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="view_id" ref="view_change_standard_price"/>
|
||||
<field name="target">new</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</openerp>
|
Loading…
Reference in New Issue