Skip to content
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
98 changes: 98 additions & 0 deletions base_ubl_parse/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
.. image:: https://odoo-community.org/readme-banner-image
:target: https://odoo-community.org/get-involved?utm_source=readme
:alt: Odoo Community Association

==============
Base UBL Parse
==============

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:b3e1572cfa48ad7f6a25037935b7de6bb22b6fb2e56cd0bf26eaed7525b6e701
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |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/license-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/19.0/base_ubl_parse
:alt: OCA/edi
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/edi-19-0/edi-19-0-base_ubl_parse
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/edi&target_branch=19.0
:alt: Try me on Runboat

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

This module contains methods to parse UBL files. This module doesn't do
anything useful by itself, but it can be used by other modules to
process UBL data. Examples:

- *sale_order_import_ubl* that imports UBL sale orders.
- *account_invoice_import_ubl* that imports UBL invoices,

**Table of contents**

.. contents::
:local:

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 to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/edi/issues/new?body=module:%20base_ubl_parse%0Aversion:%2019.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
* Onestein
* Camptocamp

Contributors
------------

- Alexis de Lattre <alexis.delattre@akretion.com>
- Andrea Stirpe <a.stirpe@onestein.nl>
- Jacques-Etienne Baudoux <je@bcim.be>
- Phuc (Tran Thanh) <phuc@trobz.com>
- Simone Orsi <simone.orsi@camptocamp.com>

Other credits
-------------

The development of this module has been financially supported by:

- Camptocamp

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/19.0/base_ubl_parse>`_ 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 base_ubl_parse/__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
14 changes: 14 additions & 0 deletions base_ubl_parse/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# © 2016-2017 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
"name": "Base UBL Parse",
"version": "19.0.1.0.0",
"category": "Hidden",
"license": "AGPL-3",
"summary": "Base module to parse UBL files (Universal Business Language)",
"author": "Akretion,Onestein,Camptocamp,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/edi",
"depends": ["base_ubl"],
"installable": True,
}
27 changes: 27 additions & 0 deletions base_ubl_parse/i18n/base_ubl_parse.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * base_ubl_parse
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 18.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: base_ubl_parse
#: model:ir.model,name:base_ubl_parse.model_base_ubl
msgid "Common methods to generate and parse UBL XML files"
msgstr ""

#. module: base_ubl_parse
#. odoo-python
#: code:addons/base_ubl_parse/models/ubl.py:0
msgid ""
"The UBL XML file does not contain the version for validating the content "
"according to the schema."
msgstr ""
32 changes: 32 additions & 0 deletions base_ubl_parse/i18n/it.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * base_ubl_parse
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 18.0\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: 2025-06-17 06:27+0000\n"
"Last-Translator: mymage <stefano.consolaro@mymage.it>\n"
"Language-Team: none\n"
"Language: it\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"X-Generator: Weblate 5.10.4\n"

#. module: base_ubl_parse
#: model:ir.model,name:base_ubl_parse.model_base_ubl
msgid "Common methods to generate and parse UBL XML files"
msgstr "Metodi comuni per generare ed elaborare file UBL e XML"

#. module: base_ubl_parse
#. odoo-python
#: code:addons/base_ubl_parse/models/ubl.py:0
msgid ""
"The UBL XML file does not contain the version for validating the content "
"according to the schema."
msgstr ""
"Il file UBL XML non contiene la versione per validare il contenuto in "
"accordo allo schema."
3 changes: 3 additions & 0 deletions base_ubl_parse/models/__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 ubl
167 changes: 167 additions & 0 deletions base_ubl_parse/models/ubl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
# © 2016-2017 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
# Copyright 2019 Onestein (<https://www.onestein.eu>)
# Copyright 2020 Jacques-Etienne Baudoux (BCIM) <je@bcim.be>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

import logging

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

logger = logging.getLogger(__name__)


class BaseUbl(models.AbstractModel):
_inherit = "base.ubl"

# ==================== METHODS TO PARSE UBL files

@api.model
def _ubl_get_version(self, xml_root, root_name, ns):
version_xpath = xml_root.xpath(f"/{root_name}/cbc:UBLVersionID", namespaces=ns)
if not version_xpath:
raise UserError(
self.env._(
"The UBL XML file does not contain the version "
"for validating the content according to the schema."
)
)
return version_xpath[0].text.strip()

@api.model
def ubl_parse_customer_party(self, party_node, ns):
ref_xpath = party_node.xpath("cbc:SupplierAssignedAccountID", namespaces=ns)
party_node = party_node.xpath("cac:Party", namespaces=ns)[0]
partner_dict = self.ubl_parse_party(party_node, ns)
partner_dict["ref"] = ref_xpath and ref_xpath[0].text or False
return partner_dict

@api.model
def ubl_parse_supplier_party(self, party_node, ns):
ref_xpath = party_node.xpath("cbc:CustomerAssignedAccountID", namespaces=ns)
party_node = party_node.xpath("cac:Party", namespaces=ns)[0]
partner_dict = self.ubl_parse_party(party_node, ns)
partner_dict["ref"] = ref_xpath and ref_xpath[0].text or False
return partner_dict

@api.model
def ubl_parse_party(self, party_node, ns):
partner_name_xpath = party_node.xpath("cac:PartyName/cbc:Name", namespaces=ns)
vat_xpath = party_node.xpath("cac:PartyTaxScheme/cbc:CompanyID", namespaces=ns)
website_xpath = party_node.xpath("cbc:WebsiteURI", namespaces=ns)
contact_name_xpath = party_node.xpath("cac:Contact/cbc:Name", namespaces=ns)
contact_email_xpath = party_node.xpath(
"cac:Contact/cbc:ElectronicMail", namespaces=ns
)
contact_phone_xpath = party_node.xpath(
"cac:Contact/cbc:Telephone", namespaces=ns
)
partner_dict = {
"vat": vat_xpath and vat_xpath[0].text or False,
"name": partner_name_xpath and partner_name_xpath[0].text or False,
"website": website_xpath and website_xpath[0].text or False,
"contact": contact_name_xpath and contact_name_xpath[0].text or False,
"email": contact_email_xpath and contact_email_xpath[0].text or False,
"phone": contact_phone_xpath and contact_phone_xpath[0].text or False,
}
id_nodes = party_node.xpath("cac:PartyIdentification/cbc:ID", namespaces=ns)
id_numbers = []
for id_node in id_nodes:
id_numbers.append(
{"value": id_node.text, "schemeID": id_node.attrib.get("schemeID")}
)
partner_dict["id_number"] = id_numbers
address_xpath = party_node.xpath("cac:PostalAddress", namespaces=ns)
if address_xpath:
address_dict = self.ubl_parse_address(address_xpath[0], ns)
partner_dict.update(address_dict)
return partner_dict

@api.model
def ubl_parse_address(self, address_node, ns):
country_code_xpath = address_node.xpath(
"cac:Country/cbc:IdentificationCode", namespaces=ns
)
country_code = country_code_xpath and country_code_xpath[0].text or False
state_code_xpath = address_node.xpath("cbc:CountrySubentityCode", namespaces=ns)
state_code = state_code_xpath and state_code_xpath[0].text or False
street_xpath = address_node.xpath("cbc:StreetName", namespaces=ns)
street2_xpath = address_node.xpath("cbc:AdditionalStreetName", namespaces=ns)
street_number_xpath = address_node.xpath("cbc:BuildingNumber", namespaces=ns)
city_xpath = address_node.xpath("cbc:CityName", namespaces=ns)
zip_xpath = address_node.xpath("cbc:PostalZone", namespaces=ns)
zip_code = (
zip_xpath
and zip_xpath[0].text
and zip_xpath[0].text.replace(" ", "")
or False
)
address_dict = {
"street": street_xpath and street_xpath[0].text or False,
"street_number": street_number_xpath
and street_number_xpath[0].text
or False,
"street2": street2_xpath and street2_xpath[0].text or False,
"city": city_xpath and city_xpath[0].text or False,
"zip": zip_code,
"state_code": state_code,
"country_code": country_code,
}
return address_dict

@api.model
def ubl_parse_delivery(self, delivery_node, ns):
party_xpath = delivery_node.xpath("cac:DeliveryParty", namespaces=ns)
if party_xpath:
partner_dict = self.ubl_parse_party(party_xpath[0], ns)
else:
partner_dict = {}
postal_xpath = delivery_node.xpath(
"cac:DeliveryParty/cac:PostalAddress", namespaces=ns
)
if not postal_xpath:
delivery_address_xpath = delivery_node.xpath(
"cac:DeliveryLocation/cac:Address", namespaces=ns
)
if not delivery_address_xpath:
delivery_address_xpath = delivery_node.xpath(
"cac:DeliveryAddress", namespaces=ns
)
if delivery_address_xpath:
partner_dict.update(
self.ubl_parse_address(delivery_address_xpath[0], ns)
)
return partner_dict

@api.model
def ubl_parse_delivery_details(self, delivery_node, ns):
delivery_dict = {}
latest_date = delivery_node.xpath("cbc:LatestDeliveryDate", namespaces=ns)
latest_time = delivery_node.xpath("cbc:LatestDeliveryTime", namespaces=ns)
if latest_date:
latest_delivery = latest_date[0].text
if latest_time:
latest_delivery += " " + latest_time[0].text[:-3]
delivery_dict["commitment_date"] = latest_delivery
return delivery_dict

def ubl_parse_incoterm(self, delivery_term_node, ns):
incoterm_xpath = delivery_term_node.xpath("cbc:ID", namespaces=ns)
if incoterm_xpath:
incoterm_dict = {"code": incoterm_xpath[0].text}
return incoterm_dict
return {}

def ubl_parse_product(self, line_node, ns):
barcode_xpath = line_node.xpath(
"cac:Item/cac:StandardItemIdentification/cbc:ID[@schemeID='GTIN']",
namespaces=ns,
)
code_xpath = line_node.xpath(
"cac:Item/cac:SellersItemIdentification/cbc:ID", namespaces=ns
)
product_dict = {
"barcode": barcode_xpath and barcode_xpath[0].text or False,
"code": code_xpath and code_xpath[0].text or False,
}
return product_dict
3 changes: 3 additions & 0 deletions base_ubl_parse/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
5 changes: 5 additions & 0 deletions base_ubl_parse/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- Alexis de Lattre \<<alexis.delattre@akretion.com>\>
- Andrea Stirpe \<<a.stirpe@onestein.nl>\>
- Jacques-Etienne Baudoux \<<je@bcim.be>\>
- Phuc (Tran Thanh) \<<phuc@trobz.com>\>
- Simone Orsi \<<simone.orsi@camptocamp.com>\>
3 changes: 3 additions & 0 deletions base_ubl_parse/readme/CREDITS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
The development of this module has been financially supported by:

- Camptocamp
7 changes: 7 additions & 0 deletions base_ubl_parse/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
This module contains methods to parse UBL files. This
module doesn't do anything useful by itself,
but it can be used by other modules to process UBL data.
Examples:

- *sale_order_import_ubl* that imports UBL sale orders.
- *account_invoice_import_ubl* that imports UBL invoices,
Binary file added base_ubl_parse/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading