Skip to content

Commit 84106a1

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#114588 X-original-commit: db701c2 Signed-off-by: Merel Geens <mege@odoo.com> Signed-off-by: Victor Feyens (vfe) <vfe@odoo.com>
1 parent 09091dd commit 84106a1

File tree

1 file changed

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

1 file changed

+15
-10
lines changed

addons/website_sale/controllers/main.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,16 +1040,21 @@ def _checkout_form_save(self, mode, checkout, all_values):
10401040
return partner_id
10411041

10421042
def values_preprocess(self, values):
1043-
""" Convert the values for many2one fields to integer since they are used as IDs.
1044-
1045-
:param dict values: partner fields to pre-process.
1046-
:return dict: partner fields pre-processed.
1047-
"""
1043+
new_values = dict()
10481044
partner_fields = request.env['res.partner']._fields
1049-
return {
1050-
k: (bool(v) and int(v)) if k in partner_fields and partner_fields[k].type == 'many2one' else v
1051-
for k, v in values.items()
1052-
}
1045+
1046+
for k, v in values.items():
1047+
# Convert the values for many2one fields to integer since they are used as IDs
1048+
if k in partner_fields and partner_fields[k].type == 'many2one':
1049+
new_values[k] = bool(v) and int(v)
1050+
# Store empty fields as `False` instead of empty strings `''` for consistency with other applications like
1051+
# Contacts.
1052+
elif v == '':
1053+
new_values[k] = False
1054+
else:
1055+
new_values[k] = v
1056+
1057+
return new_values
10531058

10541059
def values_postprocess(self, order, mode, values, errors, error_msg):
10551060
new_values = {}
@@ -1146,7 +1151,7 @@ def address(self, **kw):
11461151
(not order.only_services and (mode[0] == 'edit' and '/shop/checkout' or '/shop/address'))
11471152
# We need to update the pricelist(by the one selected by the customer), because onchange_partner reset it
11481153
# We only need to update the pricelist when it is not redirected to /confirm_order
1149-
if kw.get('callback', '') != '/shop/confirm_order':
1154+
if kw.get('callback', False) != '/shop/confirm_order':
11501155
request.website.sale_get_order(update_pricelist=True)
11511156
elif mode[1] == 'shipping':
11521157
order.partner_shipping_id = partner_id

0 commit comments

Comments
 (0)