You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
1.3 KiB

4 years ago
  1. # Copyright 2017 - Today Coop IT Easy SCRLfs (<http://www.coopiteasy.be>)
  2. # - Rémy Taymans <remy@coopiteasy.be>
  3. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
  4. from odoo.addons.portal.controllers.portal import CustomerPortal
  5. class CustomerPortalRestrictModification(CustomerPortal):
  6. # override from `portal` module
  7. CustomerPortal.MANDATORY_BILLING_FIELDS = [
  8. "city",
  9. "country_id",
  10. "phone",
  11. "street",
  12. "zipcode",
  13. ]
  14. CustomerPortal.OPTIONAL_BILLING_FIELDS = ["state_id"]
  15. def details_form_validate(self, data):
  16. error, error_message = super().details_form_validate(data)
  17. # since we override mandatory and optional billing fields, parent
  18. # method will insert the following key/value in `error` dict and
  19. # `error_message` list, preventing from saving the form. Workaround
  20. # is to remove them from both dict and list.
  21. if (
  22. error.get("common")
  23. and error["common"].lower() == "unknown field"
  24. and any("unknown field" in s.lower() for s in error_message)
  25. ):
  26. error.pop("common")
  27. error_message = [
  28. s for s in error_message if "unknown field" not in s.lower()
  29. ]
  30. return error, error_message