Launchpad automatic translations update.
[odoo/odoo.git] / addons / account_anglo_saxon / product.py
index 8e7a42e..7cfb641 100644 (file)
@@ -19,6 +19,7 @@
 ##############################################################################
 
 from osv import fields, osv
+from tools.translate import _
 
 class product_category(osv.osv):
     _inherit = "product.category"
@@ -32,6 +33,24 @@ class product_category(osv.osv):
             view_load=True,
             help="This account will be used to value price difference between purchase price and cost price."),
 
+        #Redefine fields to change help text for anglo saxon methodology.            
+        'property_account_income_categ': fields.property(
+            'account.account',
+            type='many2one',
+            relation='account.account',
+            string="Income Account",
+            method=True,
+            view_load=True,
+            help="This account will be used to value outgoing stock for the current product category using sale price"),
+        'property_account_expense_categ': fields.property(
+            'account.account',
+            type='many2one',
+            relation='account.account',
+            string="Expense Account",
+            method=True,
+            view_load=True,
+            help="This account will be used to value outgoing stock for the current product category using cost price"),                
+
     }
 product_category()
 
@@ -46,10 +65,53 @@ class product_template(osv.osv):
             method=True,
             view_load=True,
             help="This account will be used to value price difference between purchase price and cost price."),
+            
+        #Redefine fields to change help text for anglo saxon methodology.
+        'property_account_income': fields.property(
+            'account.account',
+            type='many2one',
+            relation='account.account',
+            string="Income Account",
+            method=True,
+            view_load=True,
+            help="This account will be used to value outgoing stock for the current product category using sale price"),
+        'property_account_expense': fields.property(
+            'account.account',
+            type='many2one',
+            relation='account.account',
+            string="Expense Account",
+            method=True,
+            view_load=True,
+            help="This account will be used to value outgoing stock for the current product category using cost price"),                
 
     }
 product_template()
 
+class product_product(osv.osv):
+    _inherit = "product.product"
+
+    def do_change_standard_price(self, cr, uid, ids, datas, context=None):
+        """ Changes the Standard Price of Product 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:
+
+        """
+        product_obj=self.browse(cr, uid, ids, context=context)[0]
+        stock_price_diff_account = product_obj.property_account_creditor_price_difference and product_obj.property_account_creditor_price_difference.id or False
+
+        if not stock_price_diff_account:
+            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
+        if not stock_price_diff_account:
+            raise osv.except_osv(_('Error!'),_('There is no price difference account defined ' \
+                                               'for this product: "%s" (id: %d)') % (product_obj.name, product_obj.id,))
+        datas['stock_input_account'] = stock_price_diff_account
+        datas['stock_output_account'] = stock_price_diff_account
+
+        return super(product_product, self).do_change_standard_price(cr, uid, ids, datas, context)
+
+product_product()
+
 
 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: