[FIX] account_anglo_saxon: price difference, discount and taxes
authorMartin Trigaux <mat@openerp.com>
Mon, 29 Sep 2014 12:48:11 +0000 (14:48 +0200)
committerMartin Trigaux <mat@openerp.com>
Fri, 3 Oct 2014 10:19:01 +0000 (12:19 +0200)
When computing the price difference amount do not integrate the eventual discount and taxes included in the price.
Otherwise the total of the generated accounting enty would be higher than the total of the invoice. opw 611350

addons/account_anglo_saxon/invoice.py

index 8a816b0..ec455fc 100644 (file)
@@ -110,14 +110,18 @@ class account_invoice_line(osv.osv):
                                 if inv.currency_id.id != company_currency:
                                     standard_price = self.pool.get('res.currency').compute(cr, uid, company_currency, inv.currency_id.id, standard_price, context={'date': inv.date_invoice})
                                 if standard_price != i_line.price_unit and line['price_unit'] == i_line.price_unit and acc:
-                                    price_diff = round(i_line.price_unit - standard_price, account_prec)
-                                    line.update({'price': round(standard_price * line['quantity'], account_prec)})
+                                    # price with discount and without tax included
+                                    price_unit = self.pool['account.tax'].compute_all(cr, uid, line['taxes'],
+                                        i_line.price_unit * (1-(i_line.discount or 0.0)/100.0), line['quantity'])['total']
+                                    price_line = round(standard_price * line['quantity'], account_prec)
+                                    price_diff = round(price_unit - price_line, account_prec)
+                                    line.update({'price': price_line})
                                     diff_res.append({
                                         'type':'src',
                                         'name': i_line.name[:64],
-                                        'price_unit':price_diff,
+                                        'price_unit': round(price_diff / line['quantity'], account_prec),
                                         'quantity':line['quantity'],
-                                        'price': round(price_diff * line['quantity'], account_prec),
+                                        'price': price_diff,
                                         'account_id':acc,
                                         'product_id':line['product_id'],
                                         'uos_id':line['uos_id'],