-
-
Notifications
You must be signed in to change notification settings - Fork 248
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[REF] l10n_br_fiscal: extract l10n_br_fiscal_notification
- Loading branch information
Showing
17 changed files
with
161 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html | ||
|
||
{ | ||
"name": "Fiscal Document Notifications", | ||
"summary": "Define fiscal document notifications", | ||
"category": "Localisation", | ||
"license": "AGPL-3", | ||
"author": "KMEE, Odoo Community Association (OCA)", | ||
"maintainers": ["mileo"], | ||
"website": "https://github.com/OCA/l10n-brazil", | ||
"development_status": "Production/Stable", | ||
"version": "14.0.1.0.0", | ||
"depends": [ | ||
"l10n_br_fiscal", | ||
], | ||
"data": [ | ||
# Data | ||
"data/l10n_br_fiscal_email_template.xml", | ||
# Views | ||
"views/document_email_view.xml", | ||
# Actions | ||
"views/l10n_br_fiscal_action.xml", | ||
# Menus | ||
"views/l10n_br_fiscal_menu.xml", | ||
], | ||
"demo": ["demo/l10n_br_fiscal_document_email.xml"], | ||
"installable": True, | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import document |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# Copyright (C) 2019 KMEE | ||
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html | ||
|
||
from odoo import _, models | ||
|
||
from odoo.addons.l10n_br_fiscal.constants.fiscal import SITUACAO_EDOC_AUTORIZADA | ||
|
||
|
||
class Document(models.Model): | ||
_inherit = "l10n_br_fiscal.document" | ||
|
||
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 | ||
|
||
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, | ||
} |
File renamed without changes.
21 changes: 21 additions & 0 deletions
21
l10n_br_fiscal_notification/views/l10n_br_fiscal_action.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<odoo> | ||
|
||
<!-- Fiscal Document Email --> | ||
<record id="document_email_action" model="ir.actions.act_window"> | ||
<field name="name">Fiscal Document Email</field> | ||
<field name="type">ir.actions.act_window</field> | ||
<field name="res_model">l10n_br_fiscal.document.email</field> | ||
<field name="view_mode">tree,form</field> | ||
<field name="view_id" ref="document_email_tree" /> | ||
<field name="help" type="html"> | ||
<p class="o_view_nocontent_smiling_face"> | ||
Add a new Fiscal Document Email Definition | ||
</p><p> | ||
All Document Email Definitions supported by the Brazilian | ||
Fiscal module for Odoo. | ||
</p> | ||
</field> | ||
</record> | ||
|
||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<odoo> | ||
|
||
<!-- Fiscal Document Email --> | ||
<menuitem | ||
id="document_email_menu" | ||
action="document_email_action" | ||
groups="l10n_br_fiscal.group_manager" | ||
parent="l10n_br_fiscal.others_config_menu" | ||
sequence="30" | ||
/> | ||
|
||
</odoo> |
1 change: 1 addition & 0 deletions
1
setup/l10n_br_fiscal_notification/odoo/addons/l10n_br_fiscal_notification
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../l10n_br_fiscal_notification |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import setuptools | ||
|
||
setuptools.setup( | ||
setup_requires=['setuptools-odoo'], | ||
odoo_addon=True, | ||
) |