Skip to content

Commit

Permalink
[MIG] account_invoice_factur-x: Migration to 12.0
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuajan committed Jan 23, 2019
1 parent a411840 commit 8fc9d9d
Show file tree
Hide file tree
Showing 22 changed files with 610 additions and 112 deletions.
67 changes: 49 additions & 18 deletions account_invoice_factur-x/README.rst
Original file line number Diff line number Diff line change
@@ -1,17 +1,41 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3

========================
Account Invoice Factur-X
========================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! 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_factur-x
: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_factur-x
: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 this module, the PDF customer invoices and refunds generated by the Qweb reporting engine of Odoo will comply with the `Factur-X <http://fnfe-mpe.org/factur-x/>`_ standard at *EN 16931* level. The Factur-X standard is the new e-invoicing standard for France and Germany released in Beta version in July 2017. In Germany, it is also known as the `ZUGFeRD 2.0 <http://www.ferd-net.de/aktuelles/meldungen/verabschiedung-zugferd-2.0_profil-en16931.html/>`_ standard. This standard is based on `CII <http://tfig.unece.org/contents/cross-industry-invoice-cii.htm>`_ (Cross-Industry Invoice) for electronic invoicing. The great idea of the ZUGFeRD/Factur-X standard is to embed an XML file inside the PDF invoice to carry structured information about the invoice. So, with a ZUGFeRD/Factur-X PDF invoice:

* no need to change your habbits and those of your customers: you can still send your PDF invoices by email as usual.
* customers equiped with a modern accouting software will be able to import the invoice automatically as supplier invoice by taking advantage of the embedded XML file,
* customers with an ancient accounting software will just open the PDF file with their PDF reader and manually encode the document as supplier invoice in their accounting software.

**Table of contents**

.. contents::
:local:

Installation
============

Expand All @@ -35,10 +59,6 @@ Usage

On the form view of a customer invoice/refund, just click on the *Print* button as usual to get the Factur-X-compliant PDF file.

.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/226/10.0

Known issues / Roadmap
======================

Expand All @@ -49,30 +69,41 @@ Known issues / Roadmap
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.
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_factur-x%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
~~~~~~~

* Akretion

Contributors
------------
~~~~~~~~~~~~

* Firstname Lastname <email.address@example.org> (optional company website url)
* Alexis de Lattre <alexis.delattre@akretion.com>
* Shine IT <contact@openerp.cn>

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

Maintainer
----------
This module is maintained by the OCA.

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

This module is maintained by the OCA.

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.

To contribute to this module, please visit https://odoo-community.org.
This module is part of the `OCA/edi <https://github.com/OCA/edi/tree/12.0/account_invoice_factur-x>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 0 additions & 2 deletions account_invoice_factur-x/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
# -*- coding: utf-8 -*-

from . import models
from .post_install import set_xml_format_in_pdf_invoice_to_facturx
12 changes: 6 additions & 6 deletions account_invoice_factur-x/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
# -*- coding: utf-8 -*-
# © 2016-2018 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
'name': 'Account Invoice Factur-X',
'version': '10.0.1.0.0',
'version': '12.0.1.0.0',
'category': 'Accounting & Finance',
'license': 'AGPL-3',
'summary': 'Generate Factur-X/ZUGFeRD customer invoices',
'author': 'Akretion,Odoo Community Association (OCA)',
'author': 'Akretion, Odoo Community Association (OCA)',
'website': 'http://www.akretion.com',
'depends': [
'account_e-invoice_generate',
'account_payment_partner',
'base_zugferd',
'base_vat',
],
'account_facturx',
],
'external_dependencies': {'python': ['facturx']},
'data': [
'views/res_partner.xml',
'views/account_config_settings.xml',
'views/res_config_settings.xml',
'views/report_invoice.xml',
],
],
'post_init_hook': 'set_xml_format_in_pdf_invoice_to_facturx',
'installable': True,
}
4 changes: 1 addition & 3 deletions account_invoice_factur-x/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-

from . import company
from . import account_config_settings
from . import res_config_settings
from . import account_invoice
from . import report
9 changes: 5 additions & 4 deletions account_invoice_factur-x/models/account_invoice.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# -*- coding: utf-8 -*-
# © 2016-2017 Akretion (http://www.akretion.com)
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import models, fields, api, _
from odoo.exceptions import UserError
from odoo.tools import float_compare, float_is_zero, float_round
from odoo.tools import float_compare, float_is_zero, float_round, pycompat
from lxml import etree
import logging
logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -161,7 +160,7 @@ def _cii_add_party_identification(
if id_dict:
party_identification = etree.SubElement(
parent_node, ns['ram'] + 'SpecifiedLegalOrganization')
for scheme_name, party_id_text in id_dict.iteritems():
for scheme_name, party_id_text in id_dict.items():
party_identification_id = etree.SubElement(
party_identification, ns['ram'] + 'ID',
schemeID=scheme_name)
Expand Down Expand Up @@ -521,7 +520,8 @@ def _cii_add_invoice_line_block(
line_doc = etree.SubElement(
line_item, ns['ram'] + 'AssociatedDocumentLineDocument')
etree.SubElement(
line_doc, ns['ram'] + 'LineID').text = unicode(line_number)
line_doc, ns['ram'] + 'LineID').text = pycompat.to_text(
line_number)

# TODO: move in dedicated method ?
trade_product = etree.SubElement(
Expand Down Expand Up @@ -738,6 +738,7 @@ def generate_facturx_xml(self):
logger.debug(
'Factur-X XML file generated for invoice ID %d', self.id)
logger.debug(xml_string)
xml_string = pycompat.to_text(xml_string)
return (xml_string, level)

@api.multi
Expand Down
9 changes: 4 additions & 5 deletions account_invoice_factur-x/models/company.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
# © 2017 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import fields, models, tools
import base64


class ResCompany(models.Model):
Expand All @@ -24,11 +24,11 @@ class ResCompany(models.Model):
('381', 'Type 381 with positive amounts'),
], string='Factur-X Refund Type', default='381')
facturx_logo = fields.Binary(
compute='compute_facturx_logo', string='Factur-X Logo',
compute='_compute_facturx_logo', string='Factur-X Logo',
help='Logo to include in the visible part of Factur-X invoices',
readonly=True)

def compute_facturx_logo(self):
def _compute_facturx_logo(self):
level2logo = {
'minimum': 'factur-x-minimum.png',
'basicwl': 'factur-x-basicwl.png',
Expand All @@ -46,6 +46,5 @@ def compute_facturx_logo(self):
f = tools.file_open(fname_path, 'rb')
f_binary = f.read()
if f_binary:
facturx_logo = f_binary.encode('base64')

facturx_logo = base64.b64encode(f_binary)
company.facturx_logo = facturx_logo
49 changes: 19 additions & 30 deletions account_invoice_factur-x/models/report.py
Original file line number Diff line number Diff line change
@@ -1,42 +1,31 @@
# -*- coding: utf-8 -*-
# © 2016-2018 Akretion (http://www.akretion.com)
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import models, api
from odoo.addons.account_facturx.models.ir_actions_report\
import IrActionsReport as OriginIrActionsReport
import logging

logger = logging.getLogger(__name__)


class Report(models.Model):
_inherit = 'report'
class IrActionsReport(models.Model):
_inherit = 'ir.actions.report'

@api.model
def get_pdf(self, docids, report_name, html=None, data=None):
"""We go through that method when the PDF is generated for the 1st
time and also when it is read from the attachment.
This method is specific to QWeb"""
pdf_content = super(Report, self).get_pdf(
docids, report_name, html=html, data=data)
invoice_reports = [
'account.report_invoice',
'account.account_invoice_report_duplicate_main']
if report_name in invoice_reports and len(docids) == 1:
invoice = self.env['account.invoice'].browse(docids[0])
if (
invoice.type in ('out_invoice', 'out_refund') and
invoice.company_id.xml_format_in_pdf_invoice ==
'factur-x'):
@api.multi
def _post_pdf(self, save_in_attachment, pdf_content=None, res_ids=None):
# OVERRIDE
if self.model == 'account.invoice' and res_ids and len(res_ids) == 1:
invoice = self.env['account.invoice'].browse(res_ids)
if invoice.type in ('out_invoice', 'out_refund') and\
invoice.company_id.xml_format_in_pdf_invoice == 'factur-x':
pdf_content = super(
OriginIrActionsReport, self)._post_pdf(
save_in_attachment, pdf_content=pdf_content,
res_ids=res_ids)
pdf_content = invoice.regular_pdf_invoice_to_facturx_invoice(
pdf_content=pdf_content)
return pdf_content

# TODO : the PDF saved as attachment is NOT the good one...
# but the PDF opened from the attachment is OK !
# because we don't inherit the right method.
# get_pdf() calls _run_wkhtmltopdf() which generate
# AND SAVE AS ATTACHMENT the report. So we need a hook inside _run_wkhtmltopdf
# but there is no hook for the moment
# The problem is the same in the module
# OCA/reporting-engines/report_qweb_signer
pdf_content)
return pdf_content
return super(IrActionsReport, self)._post_pdf(
save_in_attachment, pdf_content=pdf_content, res_ids=res_ids)
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# -*- coding: utf-8 -*-
# © 2017 Akretion - Alexis de Lattre <alexis.delattre@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import fields, models


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

facturx_level = fields.Selection(related='company_id.facturx_level')
facturx_level = fields.Selection(related='company_id.facturx_level',
readonly=False)
facturx_refund_type = fields.Selection(
related='company_id.facturx_refund_type')
related='company_id.facturx_refund_type', readonly=False)
1 change: 0 additions & 1 deletion account_invoice_factur-x/post_install.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# © 2018 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

Expand Down
5 changes: 5 additions & 0 deletions account_invoice_factur-x/readme/CONFIGURE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
In the menu *Accounting > Configuration > Settings*, check these options:

* *XML Format embedded in PDF invoice*: if you want to generate Factur-X invoices, this option must be set to *Factur-X (CII)*
* the *Factur-X Level*: unless you have a good reason, you should keep the default value *EN 16931 (Comfort)*
* *Factur-X Refund Type*: choose the type of the XML invoice for customer refunds.
3 changes: 3 additions & 0 deletions account_invoice_factur-x/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* Firstname Lastname <email.address@example.org> (optional company website url)
* Alexis de Lattre <alexis.delattre@akretion.com>
* Shine IT <contact@openerp.cn>
5 changes: 5 additions & 0 deletions account_invoice_factur-x/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
With this module, the PDF customer invoices and refunds generated by the Qweb reporting engine of Odoo will comply with the `Factur-X <http://fnfe-mpe.org/factur-x/>`_ standard at *EN 16931* level. The Factur-X standard is the new e-invoicing standard for France and Germany released in Beta version in July 2017. In Germany, it is also known as the `ZUGFeRD 2.0 <http://www.ferd-net.de/aktuelles/meldungen/verabschiedung-zugferd-2.0_profil-en16931.html/>`_ standard. This standard is based on `CII <http://tfig.unece.org/contents/cross-industry-invoice-cii.htm>`_ (Cross-Industry Invoice) for electronic invoicing. The great idea of the ZUGFeRD/Factur-X standard is to embed an XML file inside the PDF invoice to carry structured information about the invoice. So, with a ZUGFeRD/Factur-X PDF invoice:

* no need to change your habbits and those of your customers: you can still send your PDF invoices by email as usual.
* customers equiped with a modern accouting software will be able to import the invoice automatically as supplier invoice by taking advantage of the embedded XML file,
* customers with an ancient accounting software will just open the PDF file with their PDF reader and manually encode the document as supplier invoice in their accounting software.
5 changes: 5 additions & 0 deletions account_invoice_factur-x/readme/INSTALL.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
This module requires the Python library *factur-x* with **version >= 0.3** developped by Akretion. Note that the factur-x library depends on PyPDF2 for the low-level PDF manipulation. To install it, run:

.. code::
sudo pip install factur-x
3 changes: 3 additions & 0 deletions account_invoice_factur-x/readme/ROADMAP.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* for Odoo v11, use the new hooks in the report code to embed the XML file inside the PDF file just after its generation and before it is saved as attachment.

* develop glue modules (or use hasattr() ?) to add to the XML file pieces of information that is carried out by fields defined in other modules such as sale or stock (customer order reference, incoterms, delivery address, etc...).
1 change: 1 addition & 0 deletions account_invoice_factur-x/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
On the form view of a customer invoice/refund, just click on the *Print* button as usual to get the Factur-X-compliant PDF file.
Loading

0 comments on commit 8fc9d9d

Please sign in to comment.