1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as
9 # published by the Free Software Foundation, either version 3 of the
10 # License, or (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ##############################################################################
22 from osv import fields, osv
23 from tools.translate import _
26 class product_product(osv.osv):
27 _inherit = "product.product"
29 def get_product_accounts(self, cr, uid, product_id, context=None):
30 """ To get the stock input account, stock output account and stock journal related to product.
31 @param product_id: product id
32 @return: dictionary which contains information regarding stock input account, stock output account and stock journal
34 product_obj = self.pool.get('product.product').browse(cr, uid, product_id, False)
35 res = super(product_product,self).get_product_accounts(cr, uid, product_id, context=context)
36 stock_input_acc = product_obj.property_stock_account_input and product_obj.property_stock_account_input.id or False
37 if not stock_input_acc:
38 stock_input_acc = product_obj.categ_id.property_stock_account_input_categ and product_obj.categ_id.property_stock_account_input_categ.id or False
40 stock_output_acc = product_obj.property_stock_account_output and product_obj.property_stock_account_output.id or False
41 if not stock_output_acc:
42 stock_output_acc = product_obj.categ_id.property_stock_account_output_categ and product_obj.categ_id.property_stock_account_output_categ.id or False
44 journal_id = product_obj.categ_id.property_stock_journal and product_obj.categ_id.property_stock_journal.id or False
46 res.update({'stock_account_input': stock_input_acc})
47 res.update({'stock_account_output': stock_output_acc})
48 res.update({'stock_journal': journal_id})
54 "bom_ids": fields.one2many('mrp.bom', 'product_id','Bill of Materials'),
57 def do_change_standard_price(self, cr, uid, ids, datas, context=None):
58 """ Changes the Standard Price of Product and parent products and creates an account move accordingly.
59 @param datas: dict. contain default datas like new_price, stock_output_account, stock_input_account, stock_journal
60 @param context: A standard dictionary
65 res = super(product_product, self).do_change_standard_price(cr, uid, ids, datas, context=context)
66 bom_obj = self.pool.get('mrp.bom')
67 change = context.get('change_parent_price', False)
68 def _compute_price(bom):
70 if bom.bom_id and change:
71 if bom.bom_id.bom_lines:
72 for bom_line in bom.bom_id.bom_lines:
73 prod_price = self.read(cr, uid, bom_line.product_id.id, ['standard_price'])['standard_price']
74 price += bom_line.product_qty * prod_price
76 accounts = self.get_product_accounts(cr, uid, bom.bom_id.product_id.id, context)
80 'stock_output_account': accounts['stock_account_output'],
81 'stock_input_account': accounts['stock_account_input'],
82 'stock_journal': accounts['stock_journal']
84 super(product_product, self).do_change_standard_price(cr, uid, [bom.bom_id.product_id.id], datas, context)
85 _compute_price(bom.bom_id)
88 bom_ids = bom_obj.search(cr, uid, [('product_id', 'in', ids)])
90 for bom in bom_obj.browse(cr, uid, bom_ids, context=context):