Launchpad automatic translations update.
[odoo/odoo.git] / addons / account_anglo_saxon / product.py
1 ##############################################################################
2 #    
3 #    OpenERP, Open Source Management Solution
4 #    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
5 #
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.
10 #
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.
15 #
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/>.     
18 #
19 ##############################################################################
20
21 from osv import fields, osv
22 from tools.translate import _
23
24 class product_category(osv.osv):
25     _inherit = "product.category"
26     _columns = {
27         'property_account_creditor_price_difference_categ': fields.property(
28             'account.account',
29             type='many2one',
30             relation='account.account',
31             string="Price Difference Account",
32             method=True,
33             view_load=True,
34             help="This account will be used to value price difference between purchase price and cost price."),
35
36         #Redefine fields to change help text for anglo saxon methodology.            
37         'property_account_income_categ': fields.property(
38             'account.account',
39             type='many2one',
40             relation='account.account',
41             string="Income Account",
42             method=True,
43             view_load=True,
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(
46             'account.account',
47             type='many2one',
48             relation='account.account',
49             string="Expense Account",
50             method=True,
51             view_load=True,
52             help="This account will be used to value outgoing stock for the current product category using cost price"),                
53
54     }
55 product_category()
56
57 class product_template(osv.osv):
58     _inherit = "product.template"
59     _columns = {
60         'property_account_creditor_price_difference': fields.property(
61             'account.account',
62             type='many2one',
63             relation='account.account',
64             string="Price Difference Account",
65             method=True,
66             view_load=True,
67             help="This account will be used to value price difference between purchase price and cost price."),
68             
69         #Redefine fields to change help text for anglo saxon methodology.
70         'property_account_income': fields.property(
71             'account.account',
72             type='many2one',
73             relation='account.account',
74             string="Income Account",
75             method=True,
76             view_load=True,
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(
79             'account.account',
80             type='many2one',
81             relation='account.account',
82             string="Expense Account",
83             method=True,
84             view_load=True,
85             help="This account will be used to value outgoing stock for the current product category using cost price"),                
86
87     }
88 product_template()
89
90 class product_product(osv.osv):
91     _inherit = "product.product"
92
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
97         @return:
98
99         """
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
102
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
110
111         return super(product_product, self).do_change_standard_price(cr, uid, ids, datas, context)
112
113 product_product()
114
115
116 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
117