[FIX] portal: Allow to edit without state

From the user's frontend "My Account" page:
- Try to edit your details.
- Complete the form with all required fields.
- Select a country for which there are no states
(the `state_id` field is hidden)
- And confirm
=> Internal server error

The state was not filled, therefore the value sent to the server
is an empty string. This empty string is used in the UPDATE
query to register the state value. Since it's a string and
not a valid (integer) id, the query fails.

closes odoo/odoo#36272

Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
This commit is contained in:
Lucas Lefèvre
2019-08-30 10:13:29 +00:00
parent 7adc5e610b
commit 7ff683a7e1
+2
View File
@@ -175,6 +175,8 @@ class CustomerPortal(Controller):
values = {key: post[key] for key in self.MANDATORY_BILLING_FIELDS}
values.update({key: post[key] for key in self.OPTIONAL_BILLING_FIELDS if key in post})
values.update({'zip': values.pop('zipcode', '')})
if values.get('state_id') == '':
values.update({'state_id': False})
partner.sudo().write(values)
if redirect:
return request.redirect(redirect)