From 83c1f15e20114520f98e4a71dfc3d9ca370be0ff Mon Sep 17 00:00:00 2001 From: Carmen Bianca BAKKER Date: Mon, 10 Jun 2024 19:05:38 +0200 Subject: [PATCH] [REF] l10n_be_cooperator_national_number: Convenience function for getting company setting Moved out of l10n_be_cooperator_website_national_number. Signed-off-by: Carmen Bianca BAKKER --- .../models/__init__.py | 2 +- .../models/{company.py => res_company.py} | 12 ++++++++++ .../models/subscription_request.py | 14 ++++++----- .../readme/newsfragments/133.feature.rst | 2 ++ .../controllers/main.py | 24 ++++++------------- 5 files changed, 30 insertions(+), 24 deletions(-) rename l10n_be_cooperator_national_number/models/{company.py => res_company.py} (74%) create mode 100644 l10n_be_cooperator_national_number/readme/newsfragments/133.feature.rst diff --git a/l10n_be_cooperator_national_number/models/__init__.py b/l10n_be_cooperator_national_number/models/__init__.py index 78eeb2dbc..f229a2afd 100644 --- a/l10n_be_cooperator_national_number/models/__init__.py +++ b/l10n_be_cooperator_national_number/models/__init__.py @@ -2,6 +2,6 @@ # # SPDX-License-Identifier: AGPL-3.0-or-later -from . import company from . import subscription_request +from . import res_company from . import res_partner diff --git a/l10n_be_cooperator_national_number/models/company.py b/l10n_be_cooperator_national_number/models/res_company.py similarity index 74% rename from l10n_be_cooperator_national_number/models/company.py rename to l10n_be_cooperator_national_number/models/res_company.py index 1a685b507..23ea69c39 100644 --- a/l10n_be_cooperator_national_number/models/company.py +++ b/l10n_be_cooperator_national_number/models/res_company.py @@ -23,6 +23,18 @@ def _check_national_number(self): ) ) + def get_display_national_number(self, is_company): + self.ensure_one() + if is_company: + return False + return self.display_national_number + + def get_require_national_number(self, is_company): + self.ensure_one() + if is_company: + return False + return self.require_national_number + @api.onchange("display_national_number") def _onchange_display_national_number(self): if not self.display_national_number: diff --git a/l10n_be_cooperator_national_number/models/subscription_request.py b/l10n_be_cooperator_national_number/models/subscription_request.py index ba2747e72..114b3c566 100644 --- a/l10n_be_cooperator_national_number/models/subscription_request.py +++ b/l10n_be_cooperator_national_number/models/subscription_request.py @@ -21,15 +21,17 @@ class SubscriptionRequest(models.Model): @api.depends("is_company", "company_id", "company_id.display_national_number") def _compute_display_national_number(self): - self.display_national_number = ( - self.company_id.display_national_number and not self.is_company - ) + for request in self: + request.display_national_number = ( + request.company_id.get_display_national_number(request.is_company) + ) @api.depends("is_company", "company_id", "company_id.require_national_number") def _compute_require_national_number(self): - self.require_national_number = ( - self.company_id.require_national_number and not self.is_company - ) + for request in self: + request.require_national_number = ( + request.company_id.get_require_national_number(request.is_company) + ) @api.model def _get_be_national_register_number_id_category(self): diff --git a/l10n_be_cooperator_national_number/readme/newsfragments/133.feature.rst b/l10n_be_cooperator_national_number/readme/newsfragments/133.feature.rst new file mode 100644 index 000000000..f12d059fe --- /dev/null +++ b/l10n_be_cooperator_national_number/readme/newsfragments/133.feature.rst @@ -0,0 +1,2 @@ +Added ``get_display_national_number`` and ``get_require_national_number`` +convenience methods to ``res.company``. diff --git a/l10n_be_cooperator_website_national_number/controllers/main.py b/l10n_be_cooperator_website_national_number/controllers/main.py index 4430d943a..75b1104f4 100644 --- a/l10n_be_cooperator_website_national_number/controllers/main.py +++ b/l10n_be_cooperator_website_national_number/controllers/main.py @@ -21,24 +21,14 @@ def get_values_from_user(self, values, is_company): values["national_number"] = national_number return values - def _get_display_national_number(self, is_company): - if is_company: - return False - return request.env.company.display_national_number - - def _get_require_national_number(self, is_company): - if is_company: - return False - return request.env.company.require_national_number - def fill_values(self, values, is_company, logged, load_from_user=False): values = super().fill_values(values, is_company, logged, load_from_user) - values["display_national_number"] = self._get_display_national_number( - is_company - ) - values["national_number_required"] = self._get_require_national_number( - is_company - ) + values[ + "display_national_number" + ] = request.env.company.get_display_national_number(is_company) + values[ + "national_number_required" + ] = request.env.company.get_require_national_number(is_company) return values def _additional_validate(self, kwargs, logged, values, post_file): @@ -57,7 +47,7 @@ def _additional_validate(self, kwargs, logged, values, post_file): values["error_msg"] = str(ve) else: is_company = kwargs.get("is_company") == "on" - if not self._get_require_national_number(is_company): + if not request.env.company.get_require_national_number(is_company): return True values["error_msg"] = _("Some mandatory fields have not been filled.") values["error"] = {"national_number"}