Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][REF] l10n_be_cooperator_national_number: Convenience function for getting company setting #133

Merged
merged 1 commit into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion l10n_be_cooperator_national_number/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Added ``get_display_national_number`` and ``get_require_national_number``
convenience methods to ``res.company``.
24 changes: 7 additions & 17 deletions l10n_be_cooperator_website_national_number/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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"}
Expand Down
Loading