Skip to content

Commit bad3144

Browse files
committed
[FIX] portal, point_of_sale: return new instance of fields list
This commit contains a backport of odoo@1e39d5c to fix the following issue: In the l10n_mx localization, the field RFC(VAT) and zipcode should be required to prevent the field from being defaulted to "public en general". How to reproduce: -Install l10n_mx -Go to POS and sell an article to generate the ticket -Go to the POS portal to request an invoice -Fill all the fields except for RFC -Odoo does not request this field and allows the client to submit the information -The invoice will be generated to "public en general" and not to the client requesting the invoice (Expected when there is no RFC) In addons/portal/views/portal_templates.xml, zip was used which was not part of OPTIONAL_BILLING_FIELDS in addons/portal/controllers/portal.py. This forces us to manually inject data['zipcode'] to data['zip'] in `details_form_validate` opw-4332357 closes odoo#192167 X-original-commit: 4b1cf43 Signed-off-by: Guillaume Teboul-Tornezy (gute) <gute@odoo.com>
1 parent 900846f commit bad3144

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

addons/l10n_mx/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Part of Odoo. See LICENSE file for full copyright and licensing details.
33

44
from . import models
5-
5+
from . import controllers
66

77
def _enable_group_uom_post_init(env):
88
env['res.config.settings'].create({
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import portal
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from odoo.addons.portal.controllers import portal
2+
from odoo.http import request
3+
4+
class CustomerPortal(portal.CustomerPortal):
5+
6+
def _get_mandatory_fields(self):
7+
# EXTENDS 'portal'
8+
try:
9+
country_id = int(request.env.context.get('portal_form_country_id', ''))
10+
except ValueError:
11+
country_id = None
12+
13+
mandatory_fields = super()._get_mandatory_fields()
14+
if country_id and request.env['res.country'].sudo().browse(country_id).code == 'MX':
15+
mandatory_fields += ['zipcode', 'vat']
16+
return mandatory_fields
17+
18+
def _get_optional_fields(self):
19+
# EXTENDS 'portal'
20+
try:
21+
country_id = int(request.env.context.get('portal_form_country_id', ''))
22+
except ValueError:
23+
country_id = None
24+
25+
optional_fields = super()._get_optional_fields()
26+
if country_id and request.env['res.country'].sudo().browse(country_id).code == 'MX':
27+
optional_fields = [field for field in optional_fields if field not in ['zipcode', 'vat']]
28+
return optional_fields

addons/portal/controllers/portal.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,10 +382,13 @@ def details_form_validate(self, data, partner_creation=False):
382382
error = dict()
383383
error_message = []
384384

385+
request.update_context(portal_form_country_id=data['country_id'])
385386
# Validation
386387
for field_name in self._get_mandatory_fields():
387388
if not data.get(field_name):
388389
error[field_name] = 'missing'
390+
if field_name == 'zipcode':
391+
error['zip'] = 'missing'
389392

390393
# email validation
391394
if data.get('email') and not tools.single_email_re.match(data.get('email')):

0 commit comments

Comments
 (0)