Launchpad automatic translations update.
[odoo/odoo.git] / addons / account_anglo_saxon / product.py
index aa39710..7cfb641 100644 (file)
@@ -89,7 +89,7 @@ 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
@@ -97,94 +97,19 @@ class product_product(osv.osv):
         @return:
 
         """
-        location_obj = self.pool.get('stock.location')
-        move_obj = self.pool.get('account.move')
-        move_line_obj = self.pool.get('account.move.line')
-        if context is None:
-            context = {}
-
-        new_price = datas.get('new_price', 0.0)
-        journal_id = datas.get('stock_journal', False)
         product_obj=self.browse(cr, uid, ids, context=context)[0]
-        account_variation = product_obj.categ_id.property_stock_variation
-        account_variation_id = account_variation and account_variation.id or False
-        stock_price_diff_account = datas.get('stock_price_diff_account',False)
-        
-        if not account_variation_id: raise osv.except_osv(_('Error!'), _('Variation Account is not specified for Product Category: %s') % (product_obj.categ_id.name))
+        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 diffrent account defined ' \
+            raise osv.except_osv(_('Error!'),_('There is no price difference account defined ' \
                                                'for this product: "%s" (id: %d)') % (product_obj.name, product_obj.id,))
-        move_ids = []
-        loc_ids = location_obj.search(cr, uid,[('usage','=','internal')])
-        for rec_id in ids:
-            for location in location_obj.browse(cr, uid, loc_ids, context=context):
-                c = context.copy()
-                c.update({
-                    'location': location.id,
-                    'compute_child': False
-                })
-
-                product = self.browse(cr, uid, rec_id, context=c)
-                qty = product.qty_available
-                diff = product.standard_price - new_price
-                if not diff: raise osv.except_osv(_('Error!'), _("Could not find any difference between standard price and new price!"))
-                if qty:
-                    company_id = location.company_id and location.company_id.id or False
-                    if not company_id: raise osv.except_osv(_('Error!'), _('Company is not specified in Location'))
-                    #
-                    # Accounting Entries
-                    #
-                    if not journal_id:
-                        journal_id = product.categ_id.property_stock_journal and product.categ_id.property_stock_journal.id or False
-                    if not journal_id:
-                        raise osv.except_osv(_('Error!'),
-                            _('There is no journal defined '\
-                                'on the product category: "%s" (id: %d)') % \
-                                (product.categ_id.name,
-                                    product.categ_id.id,))
-                    move_id = move_obj.create(cr, uid, {
-                                'journal_id': journal_id,
-                                'company_id': company_id
-                                })
-
-                    move_ids.append(move_id)
-
-
-                    if diff > 0:
-                        amount_diff = qty * diff
-                        move_line_obj.create(cr, uid, {
-                                    'name': product.name,
-                                    'account_id': stock_price_diff_account,
-                                    'debit': amount_diff,
-                                    'move_id': move_id,
-                                    })
-                        move_line_obj.create(cr, uid, {
-                                    'name': product.categ_id.name,
-                                    'account_id': account_variation_id,
-                                    'credit': amount_diff,
-                                    'move_id': move_id
-                                    })
-                    elif diff < 0:
-                        amount_diff = qty * -diff
-                        move_line_obj.create(cr, uid, {
-                                        'name': product.name,
-                                        'account_id': stock_price_diff_account,
-                                        'credit': amount_diff,
-                                        'move_id': move_id
-                                    })
-                        move_line_obj.create(cr, uid, {
-                                        'name': product.categ_id.name,
-                                        'account_id': account_variation_id,
-                                        'debit': amount_diff,
-                                        'move_id': move_id
-                                    })
+        datas['stock_input_account'] = stock_price_diff_account
+        datas['stock_output_account'] = stock_price_diff_account
 
-            self.write(cr, uid, rec_id, {'standard_price': new_price})
+        return super(product_product, self).do_change_standard_price(cr, uid, ids, datas, context)
 
-        return move_ids
-    
 product_product()