Skip to content

Commit db701c2

Browse files
committed
[FIX] website_sale: store empty fields as False
If you specify an empty VAT number in the Contacts app, it will store it as `False` in the ORM. If a new partner is created through the shop, the VAT number is set through HTML form submission. It will use `''` for an empty VAT number. When evaluating the VAT number in Python code, it will usually be converted to a boolean, so it doesn't matter if it's `False` or `''`. But in ORM queries those are two different values and code that checks on `False` to check for the presence of a VAT number can misinterpret `''` as being one. This fix replaces `''` values submitted through the address form in the shop with `False`. opw-3114246 closes odoo#112807 Signed-off-by: Merel Geens <mege@odoo.com>
1 parent 713a46c commit db701c2

File tree

1 file changed

+15
-6
lines changed
  • addons/website_sale/controllers

1 file changed

+15
-6
lines changed

addons/website_sale/controllers/main.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -639,12 +639,21 @@ def _checkout_form_save(self, mode, checkout, all_values):
639639
return partner_id
640640

641641
def values_preprocess(self, order, mode, values):
642-
# Convert the values for many2one fields to integer since they are used as IDs
642+
new_values = dict()
643643
partner_fields = request.env['res.partner']._fields
644-
return {
645-
k: (bool(v) and int(v)) if k in partner_fields and partner_fields[k].type == 'many2one' else v
646-
for k, v in values.items()
647-
}
644+
645+
for k, v in values.items():
646+
# Convert the values for many2one fields to integer since they are used as IDs
647+
if k in partner_fields and partner_fields[k].type == 'many2one':
648+
new_values[k] = bool(v) and int(v)
649+
# Store empty fields as `False` instead of empty strings `''` for consistency with other applications like
650+
# Contacts.
651+
elif v == '':
652+
new_values[k] = False
653+
else:
654+
new_values[k] = v
655+
656+
return new_values
648657

649658
def values_postprocess(self, order, mode, values, errors, error_msg):
650659
new_values = {}
@@ -742,7 +751,7 @@ def address(self, **kw):
742751
(not order.only_services and (mode[0] == 'edit' and '/shop/checkout' or '/shop/address'))
743752
# We need to update the pricelist(by the one selected by the customer), because onchange_partner reset it
744753
# We only need to update the pricelist when it is not redirected to /confirm_order
745-
if kw.get('callback', '') != '/shop/confirm_order':
754+
if kw.get('callback', False) != '/shop/confirm_order':
746755
request.website.sale_get_order(update_pricelist=True)
747756
elif mode[1] == 'shipping':
748757
order.partner_shipping_id = partner_id

0 commit comments

Comments
 (0)