2010-03-26 10:15:01 +00:00
|
|
|
# -*- 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 product_product(osv.osv):
|
|
|
|
_inherit = "product.product"
|
|
|
|
|
|
|
|
def do_change_standard_price(self, cr, uid, ids, datas, context={}):
|
2010-04-06 08:57:06 +00:00
|
|
|
""" Changes the Standard Price of Product and parent products and creates an account move accordingly.
|
|
|
|
@param datas: dict. contain default datas like new_price, stock_output_account, stock_input_account, stock_journal
|
|
|
|
@param context: A standard dictionary
|
|
|
|
@return:
|
2010-05-05 10:01:17 +00:00
|
|
|
"""
|
2010-03-26 10:15:01 +00:00
|
|
|
#TODO : TO Check
|
|
|
|
res = super(product_product, self).do_change_standard_price(cr, uid, ids, datas, context=context)
|
|
|
|
bom_obj = self.pool.get('mrp.bom')
|
2010-05-05 10:01:17 +00:00
|
|
|
def _compute_price(bom):
|
|
|
|
price = 0.0
|
|
|
|
if bom.bom_id :
|
|
|
|
if bom.bom_id.bom_lines :
|
|
|
|
for bom_line in bom.bom_id.bom_lines :
|
|
|
|
prod_price = self.read(cr, uid, bom_line.product_id.id, ['standard_price'])['standard_price']
|
2010-04-06 08:57:06 +00:00
|
|
|
price += bom_line.product_qty * prod_price
|
2010-03-26 10:15:01 +00:00
|
|
|
|
2010-04-06 08:57:06 +00:00
|
|
|
accounts = self.get_product_accounts(cr, uid, bom.bom_id.product_id.id, context)
|
2010-05-05 10:01:17 +00:00
|
|
|
|
|
|
|
datas = {
|
2010-04-06 08:57:06 +00:00
|
|
|
'new_price': price,
|
|
|
|
'stock_output_account': accounts['stock_account_output'],
|
|
|
|
'stock_input_account': accounts['stock_account_input'],
|
|
|
|
'stock_journal': accounts['stock_journal']
|
2010-05-05 10:01:17 +00:00
|
|
|
}
|
|
|
|
super(product_product, self).do_change_standard_price(cr, uid, [bom.bom_id.product_id.id], datas, context)
|
|
|
|
_compute_price(bom.bom_id)
|
|
|
|
return price
|
2010-05-05 13:35:31 +00:00
|
|
|
|
2010-03-26 10:15:01 +00:00
|
|
|
bom_ids = bom_obj.search(cr, uid, [('product_id', 'in', ids)])
|
2010-05-05 10:01:17 +00:00
|
|
|
|
2010-03-26 10:15:01 +00:00
|
|
|
for bom in bom_obj.browse(cr, uid, bom_ids):
|
|
|
|
_compute_price(bom)
|
2010-05-05 10:01:17 +00:00
|
|
|
|
2010-03-26 10:15:01 +00:00
|
|
|
product_product()
|