[FIX] website_sale: better fiscal position detection + support update during checkout

The customer can change the country and tax
number in the billing information during
checkout, and the taxes should be properly
updated according to the re-detected fiscal
position.

The fiscal position detection also depends
on the `vat_subjected` flag, which we now assume
to be implicit as soon as the customer filled
in a valid Tax Identification Number.
This commit is contained in:
Olivier Dony 2014-10-10 21:02:30 +02:00
parent ee697920f5
commit 9b67a483df
2 changed files with 12 additions and 2 deletions

View File

@ -426,7 +426,7 @@ class website_sale(http.Controller):
return values
mandatory_billing_fields = ["name", "phone", "email", "street2", "city", "country_id", "zip"]
optional_billing_fields = ["street", "state_id", "vat"]
optional_billing_fields = ["street", "state_id", "vat", "vat_subjected"]
mandatory_shipping_fields = ["name", "phone", "street", "city", "country_id", "zip"]
optional_shipping_fields = ["state_id"]
@ -457,6 +457,9 @@ class website_sale(http.Controller):
if query.get(prefix + 'country_id'):
query[prefix + 'country_id'] = int(query[prefix + 'country_id'])
if query.get(prefix + 'vat'):
query[prefix + 'vat_subjected'] = True
if not remove_prefix:
return query
@ -531,7 +534,13 @@ class website_sale(http.Controller):
'partner_invoice_id': partner_id,
}
order_info.update(order_obj.onchange_partner_id(cr, SUPERUSER_ID, [], partner_id, context=context)['value'])
order_info.update(order_obj.onchange_delivery_id(cr, SUPERUSER_ID, [], order.company_id.id, partner_id, checkout.get('shipping_id'), None, context=context)['value'])
address_change = order_obj.onchange_delivery_id(cr, SUPERUSER_ID, [], order.company_id.id, partner_id,
checkout.get('shipping_id'), None, context=context)['value']
order_info.update(address_change)
if address_change.get('fiscal_position'):
fiscal_update = order_obj.onchange_fiscal_position(cr, SUPERUSER_ID, [], address_change['fiscal_position'],
[(4, l.id) for l in order.order_line], context=None)['value']
order_info.update(fiscal_update)
order_info.pop('user_id')
order_info.update(partner_shipping_id=checkout.get('shipping_id') or partner_id)

View File

@ -49,6 +49,7 @@ class sale_order(osv.Model):
pricelist=so.pricelist_id.id,
product=product_id,
partner_id=so.partner_id.id,
fiscal_position=so.fiscal_position.id,
qty=qty,
context=context
)['value']