1 ##############################################################################
3 # OpenERP, Open Source Management Solution
4 # Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU Affero General Public License as
8 # published by the Free Software Foundation, either version 3 of the
9 # License, or (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU Affero General Public License for more details.
16 # You should have received a copy of the GNU Affero General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 ##############################################################################
21 from osv import fields, osv
22 from tools.translate import _
24 class product_category(osv.osv):
25 _inherit = "product.category"
27 'property_account_creditor_price_difference_categ': fields.property(
30 relation='account.account',
31 string="Price Difference Account",
34 help="This account will be used to value price difference between purchase price and cost price."),
36 #Redefine fields to change help text for anglo saxon methodology.
37 'property_account_income_categ': fields.property(
40 relation='account.account',
41 string="Income Account",
44 help="This account will be used to value outgoing stock for the current product category using sale price"),
45 'property_account_expense_categ': fields.property(
48 relation='account.account',
49 string="Expense Account",
52 help="This account will be used to value outgoing stock for the current product category using cost price"),
57 class product_template(osv.osv):
58 _inherit = "product.template"
60 'property_account_creditor_price_difference': fields.property(
63 relation='account.account',
64 string="Price Difference Account",
67 help="This account will be used to value price difference between purchase price and cost price."),
69 #Redefine fields to change help text for anglo saxon methodology.
70 'property_account_income': fields.property(
73 relation='account.account',
74 string="Income Account",
77 help="This account will be used to value outgoing stock for the current product category using sale price"),
78 'property_account_expense': fields.property(
81 relation='account.account',
82 string="Expense Account",
85 help="This account will be used to value outgoing stock for the current product category using cost price"),
90 class product_product(osv.osv):
91 _inherit = "product.product"
93 def do_change_standard_price(self, cr, uid, ids, datas, context=None):
94 """ Changes the Standard Price of Product and creates an account move accordingly.
95 @param datas : dict. contain default datas like new_price, stock_output_account, stock_input_account, stock_journal
96 @param context: A standard dictionary
100 product_obj=self.browse(cr, uid, ids, context=context)[0]
101 stock_price_diff_account = product_obj.property_account_creditor_price_difference and product_obj.property_account_creditor_price_difference.id or False
103 if not stock_price_diff_account:
104 stock_price_diff_account = product_obj.categ_id.property_account_creditor_price_difference_categ and product_obj.categ_id.property_account_creditor_price_difference_categ.id or False
105 if not stock_price_diff_account:
106 raise osv.except_osv(_('Error!'),_('There is no price difference account defined ' \
107 'for this product: "%s" (id: %d)') % (product_obj.name, product_obj.id,))
108 datas['stock_input_account'] = stock_price_diff_account
109 datas['stock_output_account'] = stock_price_diff_account
111 return super(product_product, self).do_change_standard_price(cr, uid, ids, datas, context)
116 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: