summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Martinelli <nim@odoo.com>2015-08-04 15:22:55 +0200
committerNicolas Martinelli <nim@odoo.com>2015-08-05 10:39:56 +0200
commitf26b94fd7da07aa384c250d4eaa8ff3bad8a8f1a (patch)
tree6dc70c3fceeaf5fdd9f4f6e4ecfe5f04191c0be8
parent663be8118f818190b329eba2120f8b0d78f5f0ef (diff)
[FIX] sale: filter taxes to keep the ones applying to the partner company
The problem originally arises in the frontend (eCommerce). In this case, it is necessary to switch the user id to the SUPERUSER_ID in order to be allowed to create a SO. This is done in the method sale_get_order in the module website_sale. The consequence is that in a multicompany configuration, all taxes of the product will be retrieved and applied in the frontend. This fix filters the taxes retrieved to keep only the ones which apply to the company of the partner, when the user id is SUPERUSER_ID. opw-645258 opw-645915
-rw-r--r--addons/sale/sale.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/addons/sale/sale.py b/addons/sale/sale.py
index 69448d945ab..0457abc0fa1 100644
--- a/addons/sale/sale.py
+++ b/addons/sale/sale.py
@@ -21,6 +21,7 @@
from datetime import datetime, timedelta
import time
+from openerp import SUPERUSER_ID
from openerp.osv import fields, osv
from openerp.tools.translate import _
from openerp.tools import DEFAULT_SERVER_DATE_FORMAT, DEFAULT_SERVER_DATETIME_FORMAT
@@ -1130,7 +1131,14 @@ class sale_order_line(osv.osv):
else:
fpos = self.pool.get('account.fiscal.position').browse(cr, uid, fiscal_position)
if update_tax: #The quantity only have changed
- result['tax_id'] = self.pool.get('account.fiscal.position').map_tax(cr, uid, fpos, product_obj.taxes_id)
+ # The superuser is used by website_sale in order to create a sale order. We need to make
+ # sure we only select the taxes related to the company of the partner. This should only
+ # apply if the partner is linked to a company.
+ if uid == SUPERUSER_ID and partner.company_id:
+ taxes = product_obj.taxes_id.filtered(lambda r: r.company_id == partner.company_id)
+ else:
+ taxes = product_obj.taxes_id
+ result['tax_id'] = self.pool.get('account.fiscal.position').map_tax(cr, uid, fpos, taxes)
if not flag:
result['name'] = self.pool.get('product.product').name_get(cr, uid, [product_obj.id], context=context_partner)[0][1]