From fe4b7007428aa1fc8e2965beb29a8797f8116ca9 Mon Sep 17 00:00:00 2001 From: PPA Date: Thu, 5 Oct 2023 18:36:39 +0530 Subject: [PATCH 1/5] [FIX][T6622] custom_background : Changes in domain to manage the conditions based on dynamic_per_report_company_lang. --- custom_background/models/report.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/custom_background/models/report.py b/custom_background/models/report.py index f96668d..116850f 100644 --- a/custom_background/models/report.py +++ b/custom_background/models/report.py @@ -250,17 +250,14 @@ def get_bg_per_lang(self): # language and company related domains. #T6622 if self.custom_report_type == "dynamic_per_report_company_lang": lang_domain = [ + "|", ("lang_id.code", "=", lang_code), + "|", ("company_id", "=", company_background.id), + ("background_pdf", "!=", False), ] return lang_domain - # Call the method for get the custom background per company - # and per Lang. #T5886 - if self.custom_report_type == "dynamic_per_report_company_lang": - custom_background = self._get_background_per_report_company_language() - return custom_background - # If custom_report_type is report then set report(self) id. if self.custom_report_type == "report": custom_bg_from = self From 40e0fd3b3cb48660030b371016bbd82cfdc08cf9 Mon Sep 17 00:00:00 2001 From: PPA Date: Thu, 5 Oct 2023 18:41:42 +0530 Subject: [PATCH 2/5] [FIX][T6622] custom_background : Remove unnecessary method. --- custom_background/models/report.py | 38 +----------------------------- 1 file changed, 1 insertion(+), 37 deletions(-) diff --git a/custom_background/models/report.py b/custom_background/models/report.py index 116850f..1bfdc9d 100644 --- a/custom_background/models/report.py +++ b/custom_background/models/report.py @@ -254,7 +254,7 @@ def get_bg_per_lang(self): ("lang_id.code", "=", lang_code), "|", ("company_id", "=", company_background.id), - ("background_pdf", "!=", False), + ("background_pdf", "!=", False) ] return lang_domain @@ -275,42 +275,6 @@ def get_bg_per_lang(self): custom_background = custom_bg_lang[:1].background_pdf return custom_background - def _get_background_per_report_company_language(self): - """New method for get the custom background based on the report configuration - based on the per company and per Lang. #T5886""" - self.ensure_one() - lang_code = self.get_lang() - company = self._context.get("background_company") - - # Get the custom background if company and Lang are both matched. #T5886 - custom_background = self.per_report_com_lang_bg_ids.filtered( - lambda bg: bg.lang_id.code == lang_code and bg.company_id.id == company.id - ) - if custom_background: - return custom_background[:1].background_pdf - - # Get the custom background if company matched but Lang is not set. #T5886 - custom_bg_only_with_company = self.per_report_com_lang_bg_ids.filtered( - lambda bg: bg.company_id.id == company.id and not bg.lang_id.code - ) - if custom_bg_only_with_company: - return custom_bg_only_with_company[:1].background_pdf - - # Get the custom background if Lang matched but company is not set. #T5886 - custom_bg_only_with_lang = self.per_report_com_lang_bg_ids.filtered( - lambda bg: bg.lang_id.code == lang_code and not bg.company_id - ) - if custom_bg_only_with_lang: - return custom_bg_only_with_lang[:1].background_pdf - - # Get the custom background if Lang is not set and company is not set. #T5886 - default_custom_bg = self.per_report_com_lang_bg_ids.filtered( - lambda bg: not bg.lang_id and not bg.company_id - ) - if default_custom_bg: - return default_custom_bg[:1].background_pdf - return False - @api.model def _run_wkhtmltopdf( # noqa: C901 self, From 7d91d304a3269286fc1c3b093e02ae1a689585e0 Mon Sep 17 00:00:00 2001 From: PPA Date: Wed, 11 Oct 2023 16:43:27 +0530 Subject: [PATCH 3/5] [IMP][T6622] custom_background : Revert the method and modify the domain. --- custom_background/models/report.py | 66 +++++++++++++------ .../models/report_company_background_lang.py | 1 + 2 files changed, 47 insertions(+), 20 deletions(-) diff --git a/custom_background/models/report.py b/custom_background/models/report.py index 1bfdc9d..3bc9f31 100644 --- a/custom_background/models/report.py +++ b/custom_background/models/report.py @@ -246,17 +246,12 @@ def get_bg_per_lang(self): ("lang_id", "=", False), ] return lang_domain - # If custom_report_type is dynamic per report company lang then set - # language and company related domains. #T6622 + + # Call the method for get the custom background per company + # and per Lang. #T5886 if self.custom_report_type == "dynamic_per_report_company_lang": - lang_domain = [ - "|", - ("lang_id.code", "=", lang_code), - "|", - ("company_id", "=", company_background.id), - ("background_pdf", "!=", False) - ] - return lang_domain + custom_background = self._get_background_per_report_company_language() + return custom_background # If custom_report_type is report then set report(self) id. if self.custom_report_type == "report": @@ -275,6 +270,42 @@ def get_bg_per_lang(self): custom_background = custom_bg_lang[:1].background_pdf return custom_background + def _get_background_per_report_company_language(self): + """New method for get the custom background based on the report configuration + based on the per company and per Lang. #T5886""" + self.ensure_one() + lang_code = self.get_lang() + company = self._context.get("background_company") + + # Get the custom background if company and Lang are both matched. #T5886 + custom_background = self.per_report_com_lang_bg_ids.filtered( + lambda bg: bg.lang_id.code == lang_code and bg.company_id.id == company.id + ) + if custom_background: + return custom_background[:1].background_pdf + + # Get the custom background if company matched but Lang is not set. #T5886 + custom_bg_only_with_company = self.per_report_com_lang_bg_ids.filtered( + lambda bg: bg.company_id.id == company.id and not bg.lang_id.code + ) + if custom_bg_only_with_company: + return custom_bg_only_with_company[:1].background_pdf + + # Get the custom background if Lang matched but company is not set. #T5886 + custom_bg_only_with_lang = self.per_report_com_lang_bg_ids.filtered( + lambda bg: bg.lang_id.code == lang_code and not bg.company_id + ) + if custom_bg_only_with_lang: + return custom_bg_only_with_lang[:1].background_pdf + + # Get the custom background if Lang is not set and company is not set. #T5886 + default_custom_bg = self.per_report_com_lang_bg_ids.filtered( + lambda bg: not bg.lang_id and not bg.company_id + ) + if default_custom_bg: + return default_custom_bg[:1].background_pdf + return False + @api.model def _run_wkhtmltopdf( # noqa: C901 self, @@ -471,17 +502,8 @@ def _run_wkhtmltopdf( # noqa: C901 # End. #22260 for i in range(pdf_reader_content.getNumPages()): watermark = "" - # Bizzappdev customization start. #T6622 if report.custom_report_type == "dynamic_per_report_company_lang": - watermark_attachment = report.per_report_com_lang_bg_ids.search( - lang_domain - + [ - ("type_attachment", "=", "background"), - ("report_id", "=", report.id), - ], - limit=1, - ) - watermark = watermark_attachment.background_pdf + watermark = lang_domain elif first_page and i == 0: if first_page.fall_back_to_company and company_background: # Start. #22260 @@ -671,6 +693,10 @@ def _run_wkhtmltopdf( # noqa: C901 in ["dynamic", "dynamic_per_report_company_lang"] ): if report.custom_report_type == "dynamic_per_report_company_lang": + company_background = self._context.get("background_company") + lang_domain = [ + ("background_pdf", "!=", False) + ] # search append attachment record. #T6622 append_attachment = report.per_report_com_lang_bg_ids.search( lang_domain diff --git a/custom_background/models/report_company_background_lang.py b/custom_background/models/report_company_background_lang.py index 71c51ba..2bf1b1d 100644 --- a/custom_background/models/report_company_background_lang.py +++ b/custom_background/models/report_company_background_lang.py @@ -23,4 +23,5 @@ class ReportCompanyBackgroundLang(models.Model): ], string="Type", default="background", + required=True ) From fb12c50f7d9607ebd11bc5ade1e64ddc302d7b6f Mon Sep 17 00:00:00 2001 From: PPA Date: Wed, 11 Oct 2023 19:01:56 +0530 Subject: [PATCH 4/5] [IMP][T6622] custom_background : Added condition to set the correct background. --- custom_background/models/report.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/custom_background/models/report.py b/custom_background/models/report.py index 3bc9f31..5ac48f7 100644 --- a/custom_background/models/report.py +++ b/custom_background/models/report.py @@ -279,28 +279,28 @@ def _get_background_per_report_company_language(self): # Get the custom background if company and Lang are both matched. #T5886 custom_background = self.per_report_com_lang_bg_ids.filtered( - lambda bg: bg.lang_id.code == lang_code and bg.company_id.id == company.id + lambda bg: bg.type_attachment == "background" and bg.lang_id.code == lang_code and bg.company_id.id == company.id ) if custom_background: return custom_background[:1].background_pdf # Get the custom background if company matched but Lang is not set. #T5886 custom_bg_only_with_company = self.per_report_com_lang_bg_ids.filtered( - lambda bg: bg.company_id.id == company.id and not bg.lang_id.code + lambda bg: bg.type_attachment == "background" and bg.company_id.id == company.id and not bg.lang_id.code ) if custom_bg_only_with_company: return custom_bg_only_with_company[:1].background_pdf # Get the custom background if Lang matched but company is not set. #T5886 custom_bg_only_with_lang = self.per_report_com_lang_bg_ids.filtered( - lambda bg: bg.lang_id.code == lang_code and not bg.company_id + lambda bg: bg.type_attachment == "background" and bg.lang_id.code == lang_code and not bg.company_id ) if custom_bg_only_with_lang: return custom_bg_only_with_lang[:1].background_pdf # Get the custom background if Lang is not set and company is not set. #T5886 default_custom_bg = self.per_report_com_lang_bg_ids.filtered( - lambda bg: not bg.lang_id and not bg.company_id + lambda bg: bg.type_attachment == "background" and not bg.lang_id and not bg.company_id ) if default_custom_bg: return default_custom_bg[:1].background_pdf From 6ff8dcddf8e38a3399d6725141bc93386e924af0 Mon Sep 17 00:00:00 2001 From: PPA Date: Thu, 12 Oct 2023 13:03:05 +0530 Subject: [PATCH 5/5] [IMP][T6622] custom_background : Added unnecessary line. --- custom_background/models/report.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/custom_background/models/report.py b/custom_background/models/report.py index 5ac48f7..a8e2a84 100644 --- a/custom_background/models/report.py +++ b/custom_background/models/report.py @@ -246,7 +246,7 @@ def get_bg_per_lang(self): ("lang_id", "=", False), ] return lang_domain - + # Call the method for get the custom background per company # and per Lang. #T5886 if self.custom_report_type == "dynamic_per_report_company_lang": @@ -279,28 +279,36 @@ def _get_background_per_report_company_language(self): # Get the custom background if company and Lang are both matched. #T5886 custom_background = self.per_report_com_lang_bg_ids.filtered( - lambda bg: bg.type_attachment == "background" and bg.lang_id.code == lang_code and bg.company_id.id == company.id + lambda bg: bg.type_attachment == "background" + and bg.lang_id.code == lang_code + and bg.company_id.id == company.id ) if custom_background: return custom_background[:1].background_pdf # Get the custom background if company matched but Lang is not set. #T5886 custom_bg_only_with_company = self.per_report_com_lang_bg_ids.filtered( - lambda bg: bg.type_attachment == "background" and bg.company_id.id == company.id and not bg.lang_id.code + lambda bg: bg.type_attachment == "background" + and bg.company_id.id == company.id + and not bg.lang_id.code ) if custom_bg_only_with_company: return custom_bg_only_with_company[:1].background_pdf # Get the custom background if Lang matched but company is not set. #T5886 custom_bg_only_with_lang = self.per_report_com_lang_bg_ids.filtered( - lambda bg: bg.type_attachment == "background" and bg.lang_id.code == lang_code and not bg.company_id + lambda bg: bg.type_attachment == "background" + and bg.lang_id.code == lang_code + and not bg.company_id ) if custom_bg_only_with_lang: return custom_bg_only_with_lang[:1].background_pdf # Get the custom background if Lang is not set and company is not set. #T5886 default_custom_bg = self.per_report_com_lang_bg_ids.filtered( - lambda bg: bg.type_attachment == "background" and not bg.lang_id and not bg.company_id + lambda bg: bg.type_attachment == "background" + and not bg.lang_id + and not bg.company_id ) if default_custom_bg: return default_custom_bg[:1].background_pdf @@ -693,10 +701,7 @@ def _run_wkhtmltopdf( # noqa: C901 in ["dynamic", "dynamic_per_report_company_lang"] ): if report.custom_report_type == "dynamic_per_report_company_lang": - company_background = self._context.get("background_company") - lang_domain = [ - ("background_pdf", "!=", False) - ] + lang_domain = [("background_pdf", "!=", False)] # search append attachment record. #T6622 append_attachment = report.per_report_com_lang_bg_ids.search( lang_domain