[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
This commit is contained in:
Nicolas Martinelli 2015-08-04 15:22:55 +02:00
parent 663be8118f
commit f26b94fd7d
1 changed files with 9 additions and 1 deletions

View File

@ -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]