From 283c1f102dd282feecf8a1fa9a03c554090dc0d5 Mon Sep 17 00:00:00 2001 From: "Merel Geens (mege)" Date: Wed, 15 Feb 2023 15:06:36 +0000 Subject: [PATCH] [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/odoo#114617 X-original-commit: 84106a1d43fa768429f555cd49a72e0fd2adee4b Signed-off-by: Victor Feyens (vfe) Signed-off-by: Merel Geens --- addons/website_sale/controllers/main.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/addons/website_sale/controllers/main.py b/addons/website_sale/controllers/main.py index 283c37a4abd..e3e4a105f82 100644 --- a/addons/website_sale/controllers/main.py +++ b/addons/website_sale/controllers/main.py @@ -1046,16 +1046,21 @@ class WebsiteSale(http.Controller): return partner_id def values_preprocess(self, values): - """ Convert the values for many2one fields to integer since they are used as IDs. - - :param dict values: partner fields to pre-process. - :return dict: partner fields pre-processed. - """ + new_values = dict() partner_fields = request.env['res.partner']._fields - return { - k: (bool(v) and int(v)) if k in partner_fields and partner_fields[k].type == 'many2one' else v - for k, v in values.items() - } + + for k, v in values.items(): + # Convert the values for many2one fields to integer since they are used as IDs + if k in partner_fields and partner_fields[k].type == 'many2one': + new_values[k] = bool(v) and int(v) + # Store empty fields as `False` instead of empty strings `''` for consistency with other applications like + # Contacts. + elif v == '': + new_values[k] = False + else: + new_values[k] = v + + return new_values def values_postprocess(self, order, mode, values, errors, error_msg): new_values = {} @@ -1152,7 +1157,7 @@ class WebsiteSale(http.Controller): (not order.only_services and (mode[0] == 'edit' and '/shop/checkout' or '/shop/address')) # We need to update the pricelist(by the one selected by the customer), because onchange_partner reset it # We only need to update the pricelist when it is not redirected to /confirm_order - if kw.get('callback', '') != '/shop/confirm_order': + if kw.get('callback', False) != '/shop/confirm_order': request.website.sale_get_order(update_pricelist=True) elif mode[1] == 'shipping': order.partner_shipping_id = partner_id