From 392ae4ac5236b506bf6b3e14678a5e930f29cdd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Valyi?= Date: Fri, 16 Aug 2024 01:43:06 +0000 Subject: [PATCH] [REF] l10n_br_fiscal: extract l10n_br_fiscal_notification --- l10n_br_fiscal/__manifest__.py | 2 - l10n_br_fiscal/hooks.py | 1 - l10n_br_fiscal/models/document.py | 73 ---------------- l10n_br_fiscal/views/document_view.xml | 4 +- .../views/l10n_br_fiscal_action.xml | 19 +---- l10n_br_fiscal/views/l10n_br_fiscal_menu.xml | 9 -- l10n_br_fiscal_notification/__init__.py | 1 + l10n_br_fiscal_notification/__manifest__.py | 28 +++++++ .../data/l10n_br_fiscal_email_template.xml | 0 .../demo/l10n_br_fiscal_document_email.xml | 8 +- .../models/__init__.py | 1 + .../models/document.py | 83 +++++++++++++++++++ .../views/document_email_view.xml | 0 .../views/l10n_br_fiscal_action.xml | 21 +++++ .../views/l10n_br_fiscal_menu.xml | 13 +++ .../odoo/addons/l10n_br_fiscal_notification | 1 + setup/l10n_br_fiscal_notification/setup.py | 6 ++ 17 files changed, 161 insertions(+), 109 deletions(-) create mode 100644 l10n_br_fiscal_notification/__init__.py create mode 100644 l10n_br_fiscal_notification/__manifest__.py rename {l10n_br_fiscal => l10n_br_fiscal_notification}/data/l10n_br_fiscal_email_template.xml (100%) rename {l10n_br_fiscal => l10n_br_fiscal_notification}/demo/l10n_br_fiscal_document_email.xml (81%) create mode 100644 l10n_br_fiscal_notification/models/__init__.py create mode 100644 l10n_br_fiscal_notification/models/document.py rename {l10n_br_fiscal => l10n_br_fiscal_notification}/views/document_email_view.xml (100%) create mode 100644 l10n_br_fiscal_notification/views/l10n_br_fiscal_action.xml create mode 100644 l10n_br_fiscal_notification/views/l10n_br_fiscal_menu.xml create mode 120000 setup/l10n_br_fiscal_notification/odoo/addons/l10n_br_fiscal_notification create mode 100644 setup/l10n_br_fiscal_notification/setup.py diff --git a/l10n_br_fiscal/__manifest__.py b/l10n_br_fiscal/__manifest__.py index 998e94370538..5c216a2071b3 100644 --- a/l10n_br_fiscal/__manifest__.py +++ b/l10n_br_fiscal/__manifest__.py @@ -21,7 +21,6 @@ "security/ir.model.access.csv", # Data # Some data is being loaded via post_init_hook in hook file - "data/l10n_br_fiscal_email_template.xml", "data/l10n_br_fiscal_data.xml", "data/uom_data.xml", "data/uom_alternative_data.xml", @@ -62,7 +61,6 @@ "views/product_genre_view.xml", "views/document_type_view.xml", "views/document_serie_view.xml", - "views/document_email_view.xml", "views/simplified_tax_view.xml", "views/simplified_tax_range_view.xml", "views/operation_view.xml", diff --git a/l10n_br_fiscal/hooks.py b/l10n_br_fiscal/hooks.py index c1b0ae474d87..5ba390c0b053 100644 --- a/l10n_br_fiscal/hooks.py +++ b/l10n_br_fiscal/hooks.py @@ -55,7 +55,6 @@ def post_init_hook(cr, registry): "demo/fiscal_document_nfse_demo.xml", "demo/fiscal_operation_demo.xml", "demo/subsequent_operation_demo.xml", - "demo/l10n_br_fiscal_document_email.xml", "demo/res_users_demo.xml", "demo/icms_tax_definition_demo.xml", ] diff --git a/l10n_br_fiscal/models/document.py b/l10n_br_fiscal/models/document.py index 58e72ef08323..51935ba8f3c5 100644 --- a/l10n_br_fiscal/models/document.py +++ b/l10n_br_fiscal/models/document.py @@ -404,36 +404,6 @@ def action_create_return(self): return action - def _get_email_template(self, state): - self.ensure_one() - return self.document_type_id.document_email_ids.search( - [ - "|", - ("state_edoc", "=", False), - ("state_edoc", "=", state), - ("issuer", "=", self.issuer), - "|", - ("document_type_id", "=", False), - ("document_type_id", "=", self.document_type_id.id), - ], - limit=1, - order="state_edoc, document_type_id", - ).mapped("email_template_id") - - def send_email(self, state): - self.ensure_one() - email_template = self._get_email_template(state) - if email_template: - email_template.with_context( - default_attachment_ids=self._get_mail_attachment() - ).send_mail(self.id) - - def _after_change_state(self, old_state, new_state): - self.ensure_one() - result = super()._after_change_state(old_state, new_state) - self.send_email(new_state) - return result - @api.onchange("fiscal_operation_id") def _onchange_fiscal_operation_id(self): result = super()._onchange_fiscal_operation_id() @@ -510,46 +480,3 @@ def cancel_edoc(self): "associated documents have already been authorized." ) raise UserWarning(message) - - def _get_mail_attachment(self): - self.ensure_one() - attachment_ids = [] - if self.state_edoc == SITUACAO_EDOC_AUTORIZADA: - if self.file_report_id: - attachment_ids.append(self.file_report_id.id) - if self.authorization_file_id: - attachment_ids.append(self.authorization_file_id.id) - return attachment_ids - - def action_send_email(self): - """Open a window to compose an email, with the fiscal document_type - template message loaded by default - """ - self.ensure_one() - template = self._get_email_template(self.state) - compose_form = self.env.ref("mail.email_compose_message_wizard_form", False) - lang = self.env.context.get("lang") - if template and template.lang: - lang = template._render_template(template.lang, self._name, [self.id]) - self = self.with_context(lang=lang) - ctx = dict( - default_model="l10n_br_fiscal.document", - default_res_id=self.id, - default_use_template=bool(template), - default_attachment_ids=self._get_mail_attachment(), - default_template_id=template and template.id or False, - default_composition_mode="comment", - model_description=self.document_type_id.name or self._name, - force_email=True, - ) - return { - "name": _("Send Fiscal Document Email Notification"), - "type": "ir.actions.act_window", - "view_type": "form", - "view_mode": "form", - "res_model": "mail.compose.message", - "views": [(compose_form.id, "form")], - "view_id": compose_form.id, - "target": "new", - "context": ctx, - } diff --git a/l10n_br_fiscal/views/document_view.xml b/l10n_br_fiscal/views/document_view.xml index b18079200a01..5ac1ffe7f087 100644 --- a/l10n_br_fiscal/views/document_view.xml +++ b/l10n_br_fiscal/views/document_view.xml @@ -171,13 +171,13 @@ groups="l10n_br_fiscal.group_user" attrs="{'invisible': [('state_edoc', '!=', 'autorizada')]}" /> -