From 2d8aef4bf5cd1c766b1b7c16a845b93e9dd83976 Mon Sep 17 00:00:00 2001 From: Tran Thanh Phuc Date: Sat, 13 Feb 2021 14:01:35 +0700 Subject: [PATCH] [IMP] partner_identification: Add python validation, improve view and fix default partner --- .../models/res_partner_id_category.py | 14 +------- .../models/res_partner_id_number.py | 11 ++++++ .../views/res_partner_id_category_view.xml | 36 ++++++++++++++++--- 3 files changed, 44 insertions(+), 17 deletions(-) diff --git a/partner_identification/models/res_partner_id_category.py b/partner_identification/models/res_partner_id_category.py index 6a04a8b86..aab64ac9b 100644 --- a/partner_identification/models/res_partner_id_category.py +++ b/partner_identification/models/res_partner_id_category.py @@ -33,21 +33,9 @@ class ResPartnerIdCategory(models.Model): ) active = fields.Boolean(string="Active", default=True) validation_code = fields.Text( - "Python validation code", - help="Python code called to validate an id number.", - default=lambda self: self._default_validation_code(), + "Python validation code", help="Python code called to validate an id number." ) - def _default_validation_code(self): - return _( - "\n# Python code. Use failed = True to specify that the id " - "number is not valid.\n" - "# You can use the following variables :\n" - "# - self: browse_record of the current ID Category " - "browse_record\n" - "# - id_number: browse_record of ID number to validate" - ) - def _validation_eval_context(self, id_number): self.ensure_one() return {"self": self, "id_number": id_number} diff --git a/partner_identification/models/res_partner_id_number.py b/partner_identification/models/res_partner_id_number.py index c5c3d7fe3..22323e9aa 100644 --- a/partner_identification/models/res_partner_id_number.py +++ b/partner_identification/models/res_partner_id_number.py @@ -68,3 +68,14 @@ class ResPartnerIdNumber(models.Model): ] ) active = fields.Boolean(string="Active", default=True) + + @api.model + def default_get(self, fields): + res = super(ResPartnerIdNumber, self).default_get(fields) + # It seems to be a bug in native odoo that the field partner_id + # is not in the fields list by default. A workaround is required + # to force this. + if "default_partner_id" in self._context and "partner_id" not in fields: + fields.append("partner_id") + res["partner_id"] = self._context.get("default_partner_id") + return res diff --git a/partner_identification/views/res_partner_id_category_view.xml b/partner_identification/views/res_partner_id_category_view.xml index d9763608b..78952e71c 100644 --- a/partner_identification/views/res_partner_id_category_view.xml +++ b/partner_identification/views/res_partner_id_category_view.xml @@ -7,10 +7,38 @@ form
- - - - + + + + + + + + + + + +