[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) <vfe@odoo.com> Signed-off-by: Merel Geens <mege@odoo.com>
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user