Skip to content

Commit

Permalink
[IMP] base_wamas_ubl group wamas lines
Browse files Browse the repository at this point in the history
  • Loading branch information
santostelmo committed Feb 17, 2025
1 parent 22693bc commit e7dfd92
Show file tree
Hide file tree
Showing 6 changed files with 165 additions and 34 deletions.
11 changes: 4 additions & 7 deletions base_wamas_ubl/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@
Base WAMAS UBL
==============

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:f97ed074cb58c152474c9fa18dfea888a7c80aeb70fdf5a516ed2a84becdb1bc
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png
:target: https://odoo-community.org/page/development-status
Expand All @@ -23,10 +20,10 @@ Base WAMAS UBL
:target: https://translation.odoo-community.org/projects/edi-16-0/edi-16-0-base_wamas_ubl
: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=16.0
:target: https://runboat.odoo-community.org/webui/builds.html?repo=OCA/edi&target_branch=16.0
:alt: Try me on Runboat

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

This module contains methods to parse between WAMAS file and UBL file.

Expand All @@ -45,7 +42,7 @@ 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
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:%20base_wamas_ubl%0Aversion:%2016.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.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<DespatchAdvice xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" xmlns="urn:oasis:names:specification:ubl:schema:xsd:DespatchAdvice-2">
<cbc:UBLVersionID>2.2</cbc:UBLVersionID>
<cbc:ID>130377</cbc:ID>
<cbc:IssueDate>2023-05-01</cbc:IssueDate>
<cac:OrderReference>
<cbc:ID/>
</cac:OrderReference>
<cac:DespatchSupplierParty>
<cbc:CustomerAssignedAccountID>1040</cbc:CustomerAssignedAccountID>
<cac:Party>
<cac:PartyName>
<cbc:Name/>
</cac:PartyName>
<cac:PostalAddress>
<cbc:StreetName/>
<cbc:CityName/>
<cbc:PostalZone/>
<cac:Country>
<cbc:IdentificationCode/>
</cac:Country>
</cac:PostalAddress>
<cac:Contact>
<cbc:Telephone/>
<cbc:Telefax/>
<cbc:ElectronicMail/>
</cac:Contact>
</cac:Party>
</cac:DespatchSupplierParty>
<cac:DeliveryCustomerParty>
<cac:Party>
<cac:PartyName>
<cbc:Name/>
</cac:PartyName>
<cac:PostalAddress>
<cbc:StreetName/>
<cbc:CityName/>
<cbc:PostalZone/>
<cbc:CountrySubentity/>
<cac:Country>
<cbc:IdentificationCode/>
</cac:Country>
</cac:PostalAddress>
<cac:PartyTaxScheme>
<cbc:CompanyID/>
<cac:TaxScheme>
<cbc:ID/>
<cbc:TaxTypeCode/>
</cac:TaxScheme>
</cac:PartyTaxScheme>
<cac:Contact>
<cbc:Name/>
<cbc:Telephone/>
<cbc:Telefax/>
<cbc:ElectronicMail/>
</cac:Contact>
</cac:Party>
</cac:DeliveryCustomerParty>
<cac:Shipment>
<cbc:ID/>
<cac:Delivery>
<cac:EstimatedDeliveryPeriod>
<cbc:EndDate>2023-05-01</cbc:EndDate>
<cbc:EndTime>04:43:39</cbc:EndTime>
</cac:EstimatedDeliveryPeriod>
</cac:Delivery>
</cac:Shipment>
<cac:DespatchLine>
<cbc:ID>20</cbc:ID>
<cbc:DeliveredQuantity unitCode="BOUT" unitCodeListAgencyName="WAMAS">3072.0</cbc:DeliveredQuantity>
<cac:OrderLineReference>
<cbc:LineID/>
</cac:OrderLineReference>
<cac:Item>
<cac:BuyersItemIdentification>
<cbc:ID>1151</cbc:ID>
</cac:BuyersItemIdentification>
</cac:Item>
</cac:DespatchLine><cac:DespatchLine>
<cbc:ID>40</cbc:ID>
<cbc:DeliveredQuantity unitCode="BOUT" unitCodeListAgencyName="WAMAS">3840.0</cbc:DeliveredQuantity>
<cac:OrderLineReference>
<cbc:LineID/>
</cac:OrderLineReference>
<cac:Item>
<cac:BuyersItemIdentification>
<cbc:ID>1160</cbc:ID>
</cac:BuyersItemIdentification>
</cac:Item>
</cac:DespatchLine>
</DespatchAdvice>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
WAMAS ODOO 00000120230501065723WEAKQ0051000196241 HOST 20230501060217 19700101010000202305010609112023050106433920230501060221 0001040
WAMAS ODOO 00000220230501065723WEAPQ0050000196241 000130377 HOST 00002045415 0001151 00000DISPONIBLE 000001536000000000010000 BOUT 19700101 12 eCAM 018090 N
WAMAS ODOO 00000320230501065723WEAPQ0050000196241 000130377 HOST 00002045415 0001151 00000DISPONIBLE 000001536000000000010000 BOUT 19700101 12 eCAM 018090 N
WAMAS ODOO 00000420230501065723WEAPQ0050000196241 000130377 HOST 00004045415 0001160 00000DISPONIBLE 000003840000000000000000 BOUT 19700101 12 eCAM 018090 N
5 changes: 5 additions & 0 deletions base_wamas_ubl/lib/wamas/tests/test_wamas2ubl.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ def test_convert_wamas2ubl_reception_combined(self):
lst_expected_output = "WAMAS2UBL-SAMPLE_COMB_WEAKQ_WEAPQ-DESPATCH_ADVICE.xml"
self._convert_wamas2ubl(input_file, lst_expected_output)

def test_convert_wamas2ubl_reception_groupby(self):
input_file = "WAMAS2UBL-SAMPLE_GROUPBY_WEAKQ_WEAPQ.wamas"
lst_expected_output = "WAMAS2UBL-SAMPLE_GROUPBY_WEAKQ_WEAPQ-DESPATCH_ADVICE.xml"
self._convert_wamas2ubl(input_file, lst_expected_output)

Check warning on line 50 in base_wamas_ubl/lib/wamas/tests/test_wamas2ubl.py

View check run for this annotation

Codecov / codecov/patch

base_wamas_ubl/lib/wamas/tests/test_wamas2ubl.py#L48-L50

Added lines #L48 - L50 were not covered by tests

def test_convert_wamas2ubl_return(self):
input_file = "WAMAS2UBL-SAMPLE_KRETKQ_KRETPQ.wamas"
lst_expected_output = "WAMAS2UBL-SAMPLE_KRETKQ_KRETPQ-DESPATCH_ADVICE.xml"
Expand Down
43 changes: 41 additions & 2 deletions base_wamas_ubl/lib/wamas/wamas2ubl.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ def get_line(
transfer_key1_name,
transfer_key2_name=False,
package_key_name=False,
group_by_key=False,
group_by_key_values=(),
):
"""Process a list of dict as lines of the transfers
Expand All @@ -60,9 +62,31 @@ def get_line(
transfer_key1_name: the key in the dict that serves to identify the
parent in transfers
transfer_key2_name: the key in the dict that serves to identify a sub-transfer
group_by_key: the key in the dict that serves to group the lines
group_by_key_values: the values to sum when grouping by group_by_key
package_key_name: the key in the dict that serves to identify the
related package
"""

def _add_line_to_transfer(

Check warning on line 71 in base_wamas_ubl/lib/wamas/wamas2ubl.py

View check run for this annotation

Codecov / codecov/patch

base_wamas_ubl/lib/wamas/wamas2ubl.py#L71

Added line #L71 was not covered by tests
line, transfer, group_by_key=False, group_by_key_values=()
):
if not group_by_key:
transfer.setdefault("lines", []).append(line)
return

Check warning on line 76 in base_wamas_ubl/lib/wamas/wamas2ubl.py

View check run for this annotation

Codecov / codecov/patch

base_wamas_ubl/lib/wamas/wamas2ubl.py#L75-L76

Added lines #L75 - L76 were not covered by tests

for transfer_line in transfer.get("lines", []):
if group_by_key and line.get(group_by_key) == transfer_line.get(
group_by_key
):
# Sum values grouped by group_by_key
for group_by_key_value in group_by_key_values:
transfer_line[group_by_key_value] += line.get(

Check warning on line 84 in base_wamas_ubl/lib/wamas/wamas2ubl.py

View check run for this annotation

Codecov / codecov/patch

base_wamas_ubl/lib/wamas/wamas2ubl.py#L84

Added line #L84 was not covered by tests
group_by_key_value
)
return
transfer.setdefault("lines", []).append(line)

Check warning on line 88 in base_wamas_ubl/lib/wamas/wamas2ubl.py

View check run for this annotation

Codecov / codecov/patch

base_wamas_ubl/lib/wamas/wamas2ubl.py#L87-L88

Added lines #L87 - L88 were not covered by tests

transfers = {}
if telegram_type not in self.data:
raise ValueError("Missing telegram: %s" % telegram_type)
Expand All @@ -83,7 +107,14 @@ def get_line(
if key not in transfers:
# Copy parent transfer data
transfers[key] = OrderedDict(self.transfers[line[transfer_key1_name]])
transfers[key].setdefault("lines", []).append(line)
# Sum values grouped by group_by_key
_add_line_to_transfer(

Check warning on line 111 in base_wamas_ubl/lib/wamas/wamas2ubl.py

View check run for this annotation

Codecov / codecov/patch

base_wamas_ubl/lib/wamas/wamas2ubl.py#L111

Added line #L111 was not covered by tests
line,
transfers[key],
group_by_key,
group_by_key_values,
)

if not package_key_name:
continue
package_id = line[package_key_name]
Expand Down Expand Up @@ -138,7 +169,15 @@ def dict2ubl(msg_type, data, extra_data=False):

if msg_type == "ReceptionResponse":
extractor.get_head("WEAKQ", "IvWevk_WevId_WevNr")
extractor.get_line("WEAPQ", "IvWevp_WevId_WevNr", "IvWevp_WEAP_WeaId_WeaNr")
extractor.get_line(

Check warning on line 172 in base_wamas_ubl/lib/wamas/wamas2ubl.py

View check run for this annotation

Codecov / codecov/patch

base_wamas_ubl/lib/wamas/wamas2ubl.py#L172

Added line #L172 was not covered by tests
"WEAPQ",
"IvWevp_WevId_WevNr",
transfer_key2_name="IvWevp_WEAP_WeaId_WeaNr",
# Group by key article
group_by_key="IvWevp_MId_AId_ArtNr",
# Sum quanties and weights grouped
group_by_key_values=("IvWevp_LiefMngs_Mng", "IvWevp_LiefMngs_Gew"),
)
elif msg_type == "ReturnResponse":
extractor.get_head("KRETKQ", "IvKretk_KretId_KretNr")
extractor.get_line("KRETPQ", "IvKretp_KretId_KretNr")
Expand Down
46 changes: 21 additions & 25 deletions base_wamas_ubl/static/description/index.html
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils: https://docutils.sourceforge.io/" />
<meta name="generator" content="Docutils: http://docutils.sourceforge.net/" />
<title>Base WAMAS UBL</title>
<style type="text/css">

/*
:Author: David Goodger (goodger@python.org)
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
:Id: $Id: html4css1.css 7952 2016-07-26 18:15:59Z milde $
:Copyright: This stylesheet has been placed in the public domain.
Default cascading style sheet for the HTML output of Docutils.
Despite the name, some widely supported CSS2 features are used.
See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
See http://docutils.sf.net/docs/howto/html-stylesheets.html for how to
customize this style sheet.
*/

Expand Down Expand Up @@ -275,7 +275,7 @@
margin-left: 2em ;
margin-right: 2em }

pre.code .ln { color: gray; } /* line numbers */
pre.code .ln { color: grey; } /* line numbers */
pre.code, code { background-color: #eeeeee }
pre.code .comment, code .comment { color: #5C6576 }
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
Expand All @@ -301,7 +301,7 @@
span.pre {
white-space: pre }

span.problematic, pre.problematic {
span.problematic {
color: red }

span.section-subtitle {
Expand Down Expand Up @@ -366,10 +366,8 @@ <h1 class="title">Base WAMAS UBL</h1>
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:f97ed074cb58c152474c9fa18dfea888a7c80aeb70fdf5a516ed2a84becdb1bc
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Alpha" src="https://img.shields.io/badge/maturity-Alpha-red.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/edi/tree/16.0/base_wamas_ubl"><img alt="OCA/edi" src="https://img.shields.io/badge/github-OCA%2Fedi-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/edi-16-0/edi-16-0-base_wamas_ubl"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/edi&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Alpha" src="https://img.shields.io/badge/maturity-Alpha-red.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/edi/tree/16.0/base_wamas_ubl"><img alt="OCA/edi" src="https://img.shields.io/badge/github-OCA%2Fedi-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/edi-16-0/edi-16-0-base_wamas_ubl"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runboat.odoo-community.org/webui/builds.html?repo=OCA/edi&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module contains methods to parse between WAMAS file and UBL file.</p>
<div class="admonition important">
<p class="first admonition-title">Important</p>
Expand All @@ -380,51 +378,49 @@ <h1 class="title">Base WAMAS UBL</h1>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
<li><a class="reference internal" href="#bug-tracker" id="toc-entry-1">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="toc-entry-2">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="toc-entry-3">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="toc-entry-4">Contributors</a></li>
<li><a class="reference internal" href="#other-credits" id="toc-entry-5">Other credits</a></li>
<li><a class="reference internal" href="#maintainers" id="toc-entry-6">Maintainers</a></li>
<li><a class="reference internal" href="#bug-tracker" id="id1">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="id2">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="id3">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="id4">Contributors</a></li>
<li><a class="reference internal" href="#other-credits" id="id5">Other credits</a></li>
<li><a class="reference internal" href="#maintainers" id="id6">Maintainers</a></li>
</ul>
</li>
</ul>
</div>
<div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#toc-entry-1">Bug Tracker</a></h1>
<h1><a class="toc-backref" href="#id1">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/edi/issues">GitHub Issues</a>.
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
If you spotted it first, help us smashing it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/edi/issues/new?body=module:%20base_wamas_ubl%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
<h1><a class="toc-backref" href="#toc-entry-2">Credits</a></h1>
<h1><a class="toc-backref" href="#id2">Credits</a></h1>
<div class="section" id="authors">
<h2><a class="toc-backref" href="#toc-entry-3">Authors</a></h2>
<h2><a class="toc-backref" href="#id3">Authors</a></h2>
<ul class="simple">
<li>Camptocamp</li>
<li>BCIM</li>
</ul>
</div>
<div class="section" id="contributors">
<h2><a class="toc-backref" href="#toc-entry-4">Contributors</a></h2>
<h2><a class="toc-backref" href="#id4">Contributors</a></h2>
<ul class="simple">
<li>Jacques-Etienne Baudoux &lt;<a class="reference external" href="mailto:je&#64;bcim.be">je&#64;bcim.be</a>&gt;</li>
<li>Tuan Tran &lt;<a class="reference external" href="mailto:anhtuan&#64;trobz.com">anhtuan&#64;trobz.com</a>&gt;</li>
<li>Telmo Santos &lt;<a class="reference external" href="mailto:telmo.santos&#64;camptocamp.com">telmo.santos&#64;camptocamp.com</a>&gt;</li>
</ul>
</div>
<div class="section" id="other-credits">
<h2><a class="toc-backref" href="#toc-entry-5">Other credits</a></h2>
<h2><a class="toc-backref" href="#id5">Other credits</a></h2>
<p>The creation of this module was financially supported by Camptocamp.</p>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
<h2><a class="toc-backref" href="#id6">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
</a>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<p>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.</p>
Expand Down

0 comments on commit e7dfd92

Please sign in to comment.