Skip to content
Permalink
Browse files

[ADD] account_invoice_import_xml: allow import of XMLs as Vendor Bills

  • Loading branch information...
Laurent Smet authored and william-andre committed Apr 18, 2018
1 parent edd659f commit 343c3f270a9c3b6a39e1b3c00209c9335d6fdf62
Showing with 49,790 additions and 9 deletions.
  1. +7 −3 addons/account/models/account_invoice_import_wizard.py
  2. +1 −0 addons/account/models/res_config_settings.py
  3. +0 −5 addons/account/views/account_invoice_import_wizard_view.xml
  4. +1 −1 addons/account/views/account_journal_dashboard_view.xml
  5. +11 −0 addons/account/views/res_config_settings_views.xml
  6. +3 −0 addons/account_invoice_import_xml/__init__.py
  7. +12 −0 addons/account_invoice_import_xml/__manifest__.py
  8. +3 −0 addons/account_invoice_import_xml/models/__init__.py
  9. +58 −0 addons/account_invoice_import_xml/models/import_invoice_xml_wizard.py
  10. +2 −0 addons/l10n_be/__init__.py
  11. +1 −0 addons/l10n_be/__manifest__.py
  12. +1 −0 addons/l10n_be/models/__init__.py
  13. +9 −0 addons/l10n_be/models/account_config_settings.py
  14. +23 −0 addons/l10n_be/views/res_config_settings_views.xml
  15. +4 −0 addons/l10n_be_edi/__init__.py
  16. +20 −0 addons/l10n_be_edi/__manifest__.py
  17. +204 −0 addons/l10n_be_edi/data/ubl_invoice_templates.xml
  18. +731 −0 addons/l10n_be_edi/data/xsd/2.1/common/CCTS_CCT_SchemaModule-2.1.xsd
  19. +39,799 −0 addons/l10n_be_edi/data/xsd/2.1/common/UBL-CommonAggregateComponents-2.1.xsd
  20. +5,389 −0 addons/l10n_be_edi/data/xsd/2.1/common/UBL-CommonBasicComponents-2.1.xsd
  21. +223 −0 addons/l10n_be_edi/data/xsd/2.1/common/UBL-CommonExtensionComponents-2.1.xsd
  22. +101 −0 addons/l10n_be_edi/data/xsd/2.1/common/UBL-CommonSignatureComponents-2.1.xsd
  23. +63 −0 addons/l10n_be_edi/data/xsd/2.1/common/UBL-CoreComponentParameters-2.1.xsd
  24. +89 −0 addons/l10n_be_edi/data/xsd/2.1/common/UBL-ExtensionContentDataType-2.1.xsd
  25. +69 −0 addons/l10n_be_edi/data/xsd/2.1/common/UBL-QualifiedDataTypes-2.1.xsd
  26. +138 −0 addons/l10n_be_edi/data/xsd/2.1/common/UBL-SignatureAggregateComponents-2.1.xsd
  27. +78 −0 addons/l10n_be_edi/data/xsd/2.1/common/UBL-SignatureBasicComponents-2.1.xsd
  28. +553 −0 addons/l10n_be_edi/data/xsd/2.1/common/UBL-UnqualifiedDataTypes-2.1.xsd
  29. +476 −0 addons/l10n_be_edi/data/xsd/2.1/common/UBL-XAdESv132-2.1.xsd
  30. +25 −0 addons/l10n_be_edi/data/xsd/2.1/common/UBL-XAdESv141-2.1.xsd
  31. +330 −0 addons/l10n_be_edi/data/xsd/2.1/common/UBL-xmldsig-core-schema-2.1.xsd
  32. +1,002 −0 addons/l10n_be_edi/data/xsd/2.1/maindoc/UBL-Invoice-2.1.xsd
  33. +6 −0 addons/l10n_be_edi/models/__init__.py
  34. +92 −0 addons/l10n_be_edi/models/account_invoice.py
  35. +176 −0 addons/l10n_be_edi/models/import_invoice_xml_wizard.py
  36. +17 −0 addons/l10n_be_edi/models/ir_actions_report.py
  37. +23 −0 addons/l10n_be_edi/models/mail_compose_message.py
  38. +3 −0 addons/l10n_be_edi/tests/__init__.py
  39. +47 −0 addons/l10n_be_edi/tests/test_ubl.py
@@ -15,13 +15,17 @@ def _get_default_journal_id(self):

@api.multi
def _create_invoice_from_file(self, attachment):
self = self.with_context(default_journal_id= self.journal_id.id)
self = self.with_context(default_journal_id=self.journal_id.id)
invoice_form = Form(self.env['account.invoice'], view='account.invoice_supplier_form')
invoice = invoice_form.save()
attachment.write({'res_model': 'account.invoice', 'res_id': invoice.id})
invoice.message_post(attachment_ids=[attachment.id])
return invoice

@api.multi
def _create_invoice(self, attachment):
return self._create_invoice_from_file(attachment)

@api.multi
def create_invoices(self):
''' Create the invoices from files.
@@ -32,10 +36,10 @@ def create_invoices(self):

invoices = self.env['account.invoice']
for attachment in self.attachment_ids:
invoices += self._create_invoice_from_file(attachment)
invoices += self._create_invoice(attachment)

action_vals = {
'name': _('Invoices'),
'name': _('Generated Documents'),
'domain': [('id', 'in', invoices.ids)],
'view_type': 'form',
'res_model': 'account.invoice',
@@ -75,6 +75,7 @@ class ResConfigSettings(models.TransientModel):
module_product_margin = fields.Boolean(string="Allow Product Margin")
module_l10n_eu_service = fields.Boolean(string="EU Digital Goods VAT")
module_account_taxcloud = fields.Boolean(string="Account TaxCloud")
module_account_invoice_import_xml = fields.Boolean(string='Import XML Bills')
module_account_invoice_extract = fields.Boolean(string="Bill Digitalization")
module_snailmail_account = fields.Boolean(string="Snailmail")
tax_exigibility = fields.Boolean(string='Cash Basis', related='company_id.tax_exigibility', readonly=False)
@@ -6,11 +6,6 @@
<field name="model">account.invoice.import.wizard</field>
<field name="arch" type="xml">
<form>
<group>
<group>
<field name="journal_id" context="{'default_type': 'purchase'}"/>
</group>
</group>
<group>
<field name="attachment_ids" widget="many2many_binary" colspan="2"
string="Upload Files" nolabel="1"/>
@@ -281,7 +281,7 @@
<button type="object" name="action_create_new" class="btn btn-primary">
<span>New Bill</span>
</button>
<button type="action" name="%(account_invoice_import_wizard_action)d" class="btn btn-primary">
<button type="action" name="%(account_invoice_import_wizard_action)d" class="btn btn-primary" context="{'default_journal_id': id}">
<span>Import Bills</span>
</button>
</t>
@@ -398,6 +398,17 @@
</div>
</div>
</div>
<div class="col-xs-12 col-md-6 o_setting_box">
<div class="o_setting_left_pane">
<field name="module_account_invoice_import_xml" widget="upgrade_boolean"/>
</div>
<div class="o_setting_right_pane">
<label for="module_account_invoice_import_xml"/>
<div class="text-muted">
Allows to import vendor bills in XML format.
</div>
</div>
</div>
</div>
<h2>Vendor Payments</h2>
<div class="row mt16 o_settings_container">
@@ -0,0 +1,3 @@
# -*- encoding: utf-8 -*-

from . import models
@@ -0,0 +1,12 @@
# -*- coding: utf-8 -*-
{
'name': 'Import Vendor Bills From XML',
'version': '1.0',
'category': 'Accounting',
'depends': ['account', 'documents'],
'data': [
],
'installable': True,
'application': False,
'auto_install': False,
}
@@ -0,0 +1,3 @@
# -*- encoding: utf-8 -*-

from . import import_invoice_xml_wizard
@@ -0,0 +1,58 @@
# -*- coding: utf-8 -*-

from odoo import api, fields, models, _
from odoo.exceptions import UserError

from lxml import etree
import base64


class ImportInvoiceXmlWizard(models.TransientModel):
_inherit = 'account.invoice.import.wizard'

@api.model
def _get_xml_decoders(self):
''' List of usable decoders to extract invoice from attachments.
:return: a list of triplet (xml_type, check_func, decode_func)
* xml_type: The format name, e.g 'UBL 2.1'
* check_func: A function taking an etree as parameter and returning a dict:
* flag: The etree is part of this format.
* error: Error message.
* decode_func: A function taking an etree as parameter and returning an invoice record.
'''
# TO BE OVERWRITTEN
return []

@api.multi
def _create_invoice_from_xml(self, attachment):
decoders = self._get_xml_decoders()

# Convert attachment -> etree
content = base64.b64decode(attachment.datas)
try:
tree = etree.fromstring(content)
except Exception:
raise UserError(_('The xml file is badly formatted : {}').format(attachment.datas_fname))

for xml_type, check_func, decode_func in decoders:
check_res = check_func(tree)

if check_res.get('flag') and not check_res.get('error'):
invoice = decode_func(tree)
if invoice:
attachment.write({
'res_model': 'account.invoice',
'res_id': invoice.id,
})
break

if invoice:
return invoice
raise UserError(_('No decoder was found for the xml file: {}. The file is badly formatted, not supported or the decoder is not installed').format(attachment.datas_fname))

@api.multi
def _create_invoice(self, attachment):
if 'xml' in attachment.mimetype:
return self._create_invoice_from_xml(attachment)
return super(ImportInvoiceXmlWizard, self)._create_invoice(attachment)
@@ -1,6 +1,8 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from . import models

from odoo import api, SUPERUSER_ID

from . import models
@@ -54,6 +54,7 @@
'data/account_reconcile_model_template.xml',
'data/account_chart_template_configure_data.xml',
'data/menuitem_data.xml',
'views/res_config_settings_views.xml',
],
'demo': [
'demo/l10n_be_demo.xml',
@@ -2,3 +2,4 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from . import account_chart_template
from . import account_config_settings
@@ -0,0 +1,9 @@
# -*- coding: utf-8 -*-

from odoo import fields, models, _


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

module_l10n_be_edi = fields.Boolean(string='E-Invoicing (Belgium)')
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="res_config_settings_view_form_inherit_l10n_be" model="ir.ui.view">
<field name="name">res.config.settings.form.inherit.l10n.be</field>
<field name="model">res.config.settings</field>
<field name="inherit_id" ref="account.res_config_settings_view_form"/>
<field name="arch" type="xml">
<xpath expr="//div[@id='invoicing_settings']" position="inside">
<div class="col-xs-12 col-md-6 o_setting_box">
<div class="o_setting_left_pane">
<field name="module_l10n_be_edi"/>
</div>
<div class="o_setting_right_pane">
<label for="module_l10n_be_edi"/>
<div class="text-muted">
Generate invoices in XML format
</div>
</div>
</div>
</xpath>
</field>
</record>
</odoo>
@@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from . import models
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
{
'name': 'Belgium - E-Invoicing (UBL 2.0, e-fff)',
'version': '0.1',
'category': 'Hidden',
'summary': 'E-Invoicing, Universal Business Language (UBL 2.0), e-fff protocol',
'description': """
Universal Business Language (UBL <http://ubl.xml.org/>`_) is a library of standard electronic XML business documents such as
invoices. The UBL standard became the `ISO/IEC 19845
<http://www.iso.org/iso/catalogue_detail.htm?csnumber=66370>`_ standard in January 2016
(cf the `official announce <http://www.prweb.com/releases/2016/01/prweb13186919.htm>`_).
Belgian e-invoicing uses the UBL 2.0 using the e-fff protocol.
""",
'depends': ['account', 'l10n_be', 'account_invoice_import_xml'],
'data': [
'data/ubl_invoice_templates.xml',
],
'installable': True,
'auto_install': False,
}
Oops, something went wrong.

0 comments on commit 343c3f2

Please sign in to comment.
You can’t perform that action at this time.