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

[12.0][MIG] account_invoice_ubl_email_attachment #109

Closed
Closed
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
89 changes: 89 additions & 0 deletions account_invoice_ubl_email_attachment/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
====================================
Account Invoice UBL Email Attachment
====================================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fedi-lightgray.png?logo=github
:target: https://github.com/OCA/edi/tree/12.0/account_invoice_ubl_email_attachment
:alt: OCA/edi
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/edi-12-0/edi-12-0-account_invoice_ubl_email_attachment
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/226/12.0
:alt: Try me on Runbot

|badge1| |badge2| |badge3| |badge4| |badge5|

With module `Account Invoice UBL`, when sending an invoice by mail, only the PDF file is attached to the email and the UBL (XML) file is embedded inside the PDF.

Some accounting software cannot read the embedded XML from a PDF, so the import is only possible by manually generating the XML file.

With this module, when sending an invoice by mail, also the UBL file is automatically included, so that 2 attachments (PDF and XML) are present in the invoice mail.

**Table of contents**

.. contents::
:local:

Configuration
=============

- Go to menu *Invoicing > Configuration > Settings > Invoicing*, under *Electronic Invoices*.
- Check the value of *Include UBL XML in Invoice Email*, set to `True` if you want to include
the UBL XML in the attachments when sending the invoice by email.

Usage
=====

In the invoice form click on button `Send & Print`.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/edi/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/edi/issues/new?body=module:%20account_invoice_ubl_email_attachment%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
~~~~~~~

* Onestein

Contributors
~~~~~~~~~~~~

* Andrea Stirpe <a.stirpe@onestein.nl>

Maintainers
~~~~~~~~~~~

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/edi <https://github.com/OCA/edi/tree/12.0/account_invoice_ubl_email_attachment>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
3 changes: 3 additions & 0 deletions account_invoice_ubl_email_attachment/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from . import models
19 changes: 19 additions & 0 deletions account_invoice_ubl_email_attachment/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2019 Onestein (<https://www.onestein.eu>)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
'name': 'Account Invoice UBL Email Attachment',
'summary': 'Automatically adds the UBL file to the email.',
'version': '12.0.1.0.0',
'category': 'Accounting & Finance',
'author': 'Onestein, Odoo Community Association (OCA)',
'website': 'https://github.com/OCA/edi/',
'license': 'AGPL-3',
'depends': [
'account_invoice_ubl'
],
'data': [
'views/res_config_settings.xml',
],
'installable': True,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * account_invoice_ubl_email_attachment
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 11.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: account_invoice_ubl_email_attachment
#: model:ir.model,name:account_invoice_ubl_email_attachment.model_res_company
msgid "Companies"
msgstr ""

#. module: account_invoice_ubl_email_attachment
#: model:ir.model,name:account_invoice_ubl_email_attachment.model_mail_template
msgid "Email Templates"
msgstr ""

#. module: account_invoice_ubl_email_attachment
#: model:ir.model.fields,help:account_invoice_ubl_email_attachment.field_res_company_include_ubl_attachment_in_invoice_email
#: model:ir.model.fields,help:account_invoice_ubl_email_attachment.field_res_config_settings_include_ubl_attachment_in_invoice_email
msgid "If active, the UBL Invoice XML file will be included in the attachments when sending the invoice by email."
msgstr ""

#. module: account_invoice_ubl_email_attachment
#: model:ir.model.fields,field_description:account_invoice_ubl_email_attachment.field_res_company_include_ubl_attachment_in_invoice_email
#: model:ir.model.fields,field_description:account_invoice_ubl_email_attachment.field_res_config_settings_include_ubl_attachment_in_invoice_email
msgid "Include UBL XML in Invoice Email"
msgstr ""

#. module: account_invoice_ubl_email_attachment
#: model:ir.ui.view,arch_db:account_invoice_ubl_email_attachment.view_account_config_settings
msgid "Include the UBL XML in the attachments when sending the invoice by email."
msgstr ""

#. module: account_invoice_ubl_email_attachment
#: model:ir.model,name:account_invoice_ubl_email_attachment.model_account_invoice
msgid "Invoice"
msgstr ""

#. module: account_invoice_ubl_email_attachment
#: model:ir.model,name:account_invoice_ubl_email_attachment.model_res_config_settings
msgid "res.config.settings"
msgstr ""

62 changes: 62 additions & 0 deletions account_invoice_ubl_email_attachment/i18n/nl.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * account_invoice_ubl_email_attachment
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 11.0+e\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-05-01 15:01+0000\n"
"PO-Revision-Date: 2019-05-01 17:03+0200\n"
"Last-Translator: <>\n"
"Language-Team: \n"
"Language: nl\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Generator: Poedit 2.2.1\n"

#. module: account_invoice_ubl_email_attachment
#: model:ir.model,name:account_invoice_ubl_email_attachment.model_res_company
#, fuzzy
msgid "Companies"
msgstr "Bedrijf"

#. module: account_invoice_ubl_email_attachment
#: model:ir.model,name:account_invoice_ubl_email_attachment.model_mail_template
msgid "Email Templates"
msgstr "E-mail-sjablonen"

#. module: account_invoice_ubl_email_attachment
#: model:ir.model.fields,help:account_invoice_ubl_email_attachment.field_res_company_include_ubl_attachment_in_invoice_email
#: model:ir.model.fields,help:account_invoice_ubl_email_attachment.field_res_config_settings_include_ubl_attachment_in_invoice_email
msgid ""
"If active, the UBL Invoice XML file will be included in the attachments when "
"sending the invoice by email."
msgstr ""
"Wanneer actief, wordt het UBL factuur XML bestand toegevoegd aan de bijlages "
"bij het versturen van de factuur per e-mail."

#. module: account_invoice_ubl_email_attachment
#: model:ir.model.fields,field_description:account_invoice_ubl_email_attachment.field_res_company_include_ubl_attachment_in_invoice_email
#: model:ir.model.fields,field_description:account_invoice_ubl_email_attachment.field_res_config_settings_include_ubl_attachment_in_invoice_email
msgid "Include UBL XML in Invoice Email"
msgstr "Voeg UBL XML toe aan factuur e-mail"

#. module: account_invoice_ubl_email_attachment
#: model:ir.ui.view,arch_db:account_invoice_ubl_email_attachment.view_account_config_settings
msgid ""
"Include the UBL XML in the attachments when sending the invoice by email."
msgstr ""
"Voeg de UBL XML toe aan de bijlages bij het versturen van factuur per e-mail."

#. module: account_invoice_ubl_email_attachment
#: model:ir.model,name:account_invoice_ubl_email_attachment.model_account_invoice
msgid "Invoice"
msgstr "Factuur"

#. module: account_invoice_ubl_email_attachment
#: model:ir.model,name:account_invoice_ubl_email_attachment.model_res_config_settings
msgid "res.config.settings"
msgstr "res.config.settings"
6 changes: 6 additions & 0 deletions account_invoice_ubl_email_attachment/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from . import account_invoice
from . import mail_template
from . import res_company
from . import res_config_settings
35 changes: 35 additions & 0 deletions account_invoice_ubl_email_attachment/models/account_invoice.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Copyright 2019 Onestein (<https://www.onestein.eu>)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

import base64

from odoo import models


class AccountInvoice(models.Model):
_inherit = 'account.invoice'

def action_invoice_sent(self):
action = super().action_invoice_sent()
if self.company_id.include_ubl_attachment_in_invoice_email:
action['context']['attach_ubl_xml_file'] = True
return action

def _generate_email_ubl_attachment(self):
self.ensure_one()
attachments = self.env['ir.attachment']
if self.type not in ('out_invoice', 'out_refund'):
return attachments
if self.state not in ('open', 'paid'):
return attachments
version = self.get_ubl_version()
ubl_filename = self.get_ubl_filename(version=version)
xml_string = self.generate_ubl_xml_string(version=version)
return self.env['ir.attachment'].with_context({}).create({
'name': ubl_filename,
'res_model': str(self._name),
'res_id': self.id,
'datas': base64.b64encode(xml_string),
'datas_fname': ubl_filename,
'type': 'binary',
})
36 changes: 36 additions & 0 deletions account_invoice_ubl_email_attachment/models/mail_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Copyright 2019 Onestein (<https://www.onestein.eu>)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import api, models


class MailTemplate(models.Model):
_inherit = 'mail.template'

@api.multi
def generate_email(self, res_ids, fields=None):
res = super(MailTemplate, self).generate_email(res_ids, fields)
if not self.env.context.get('attach_ubl_xml_file'):
return res
for res_id, template in self.get_email_template(res_ids).items():
invoice = self.env['account.invoice'].browse(res_id)
version = invoice.get_ubl_version()
ubl_filename = invoice.get_ubl_filename(version=version)
ubl_attachments = self.env['ir.attachment'].search([
('res_model', '=', 'account.invoice'),
('res_id', '=', res_id),
('datas_fname', '=', ubl_filename)
])
if not ubl_attachments:
ubl_attachments = invoice._generate_email_ubl_attachment()
if len(ubl_attachments) == 1 and template.report_name:
report_name = self._render_template(
template.report_name, template.model, res_id)
ext = '.xml'
if not report_name.endswith(ext):
report_name += ext
attachments = [(report_name, ubl_attachments.datas)]
else:
attachments = [(a.name, a.datas) for a in ubl_attachments]
res[res_id]['attachments'] += attachments
return res
14 changes: 14 additions & 0 deletions account_invoice_ubl_email_attachment/models/res_company.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright 2019 Onestein (<https://www.onestein.eu>)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models


class ResCompany(models.Model):
_inherit = 'res.company'

include_ubl_attachment_in_invoice_email = fields.Boolean(
string='Include UBL XML in Invoice Email',
help="If active, the UBL Invoice XML file will be included "
"in the attachments when sending the invoice by email."
)
13 changes: 13 additions & 0 deletions account_invoice_ubl_email_attachment/models/res_config_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2019 Onestein (<https://www.onestein.eu>)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models


class ResConfigSettings(models.TransientModel):
_inherit = 'res.config.settings'

include_ubl_attachment_in_invoice_email = fields.Boolean(
related='company_id.include_ubl_attachment_in_invoice_email',
readonly=False
)
3 changes: 3 additions & 0 deletions account_invoice_ubl_email_attachment/readme/CONFIGURE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- Go to menu *Invoicing > Configuration > Settings > Invoicing*, under *Electronic Invoices*.
- Check the value of *Include UBL XML in Invoice Email*, set to `True` if you want to include
the UBL XML in the attachments when sending the invoice by email.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Andrea Stirpe <a.stirpe@onestein.nl>
5 changes: 5 additions & 0 deletions account_invoice_ubl_email_attachment/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
With module `Account Invoice UBL`, when sending an invoice by mail, only the PDF file is attached to the email and the UBL (XML) file is embedded inside the PDF.

Some accounting software cannot read the embedded XML from a PDF, so the import is only possible by manually generating the XML file.

With this module, when sending an invoice by mail, also the UBL file is automatically included, so that 2 attachments (PDF and XML) are present in the invoice mail.
1 change: 1 addition & 0 deletions account_invoice_ubl_email_attachment/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
In the invoice form click on button `Send & Print`.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading