From 94d5f9ec011c2bac174421137e271d4f50132985 Mon Sep 17 00:00:00 2001 From: Rafa Morant Date: Mon, 5 Jun 2023 18:01:27 +0200 Subject: [PATCH 1/2] [14.0][MIG] sale_order_import_edifact & base_edifact --- base_edifact/README.rst | 127 +++++ base_edifact/__init__.py | 1 + base_edifact/__manifest__.py | 29 + base_edifact/models/__init__.py | 1 + base_edifact/models/edifact.py | 211 ++++++++ base_edifact/readme/CONFIGURE.rst | 12 + base_edifact/readme/CONTRIBUTORS.rst | 2 + base_edifact/readme/DESCRIPTION.rst | 2 + base_edifact/readme/HISTORY.rst | 4 + base_edifact/readme/INSTALL.rst | 2 + base_edifact/readme/USAGE.rst | 4 + base_edifact/static/description/icon.png | Bin 0 -> 9455 bytes base_edifact/static/description/icon.svg | 79 +++ base_edifact/static/description/index.html | 466 +++++++++++++++++ base_edifact/tests/__init__.py | 1 + base_edifact/tests/test_base_edifact.py | 56 ++ requirements.txt | 1 + sale_order_import_edifact/README.rst | 154 ++++++ sale_order_import_edifact/__init__.py | 2 + sale_order_import_edifact/__manifest__.py | 31 ++ sale_order_import_edifact/demo/demo_data.xml | 81 +++ sale_order_import_edifact/models/__init__.py | 1 + .../models/business_document_import.py | 54 ++ .../readme/CONFIGURE.rst | 30 ++ .../readme/CONTRIBUTORS.rst | 2 + .../readme/DESCRIPTION.rst | 6 + sale_order_import_edifact/readme/HISTORY.rst | 15 + sale_order_import_edifact/readme/ROADMAP.rst | 5 + .../static/description/icon.png | Bin 0 -> 9455 bytes .../static/description/icon.svg | 79 +++ .../static/description/index.html | 495 ++++++++++++++++++ sale_order_import_edifact/tests/__init__.py | 1 + sale_order_import_edifact/tests/common.py | 42 ++ .../files/Retail_EDIFACT_ORDERS_sample1.txt | 26 + .../files/Retail_EDIFACT_ORDERS_sample2.txt | 29 + .../tests/test_edifact_order_import.py | 40 ++ sale_order_import_edifact/wizard/__init__.py | 1 + .../wizard/sale_order_import.py | 237 +++++++++ .../wizard/sale_order_import_view.xml | 25 + setup/base_edifact/odoo/addons/base_edifact | 1 + setup/base_edifact/setup.py | 6 + .../odoo/addons/sale_order_import_edifact | 1 + setup/sale_order_import_edifact/setup.py | 6 + 43 files changed, 2368 insertions(+) create mode 100644 base_edifact/README.rst create mode 100644 base_edifact/__init__.py create mode 100644 base_edifact/__manifest__.py create mode 100644 base_edifact/models/__init__.py create mode 100644 base_edifact/models/edifact.py create mode 100644 base_edifact/readme/CONFIGURE.rst create mode 100644 base_edifact/readme/CONTRIBUTORS.rst create mode 100644 base_edifact/readme/DESCRIPTION.rst create mode 100644 base_edifact/readme/HISTORY.rst create mode 100644 base_edifact/readme/INSTALL.rst create mode 100644 base_edifact/readme/USAGE.rst create mode 100644 base_edifact/static/description/icon.png create mode 100644 base_edifact/static/description/icon.svg create mode 100644 base_edifact/static/description/index.html create mode 100644 base_edifact/tests/__init__.py create mode 100644 base_edifact/tests/test_base_edifact.py create mode 100644 sale_order_import_edifact/README.rst create mode 100644 sale_order_import_edifact/__init__.py create mode 100644 sale_order_import_edifact/__manifest__.py create mode 100644 sale_order_import_edifact/demo/demo_data.xml create mode 100644 sale_order_import_edifact/models/__init__.py create mode 100644 sale_order_import_edifact/models/business_document_import.py create mode 100644 sale_order_import_edifact/readme/CONFIGURE.rst create mode 100644 sale_order_import_edifact/readme/CONTRIBUTORS.rst create mode 100644 sale_order_import_edifact/readme/DESCRIPTION.rst create mode 100644 sale_order_import_edifact/readme/HISTORY.rst create mode 100644 sale_order_import_edifact/readme/ROADMAP.rst create mode 100644 sale_order_import_edifact/static/description/icon.png create mode 100644 sale_order_import_edifact/static/description/icon.svg create mode 100644 sale_order_import_edifact/static/description/index.html create mode 100644 sale_order_import_edifact/tests/__init__.py create mode 100644 sale_order_import_edifact/tests/common.py create mode 100644 sale_order_import_edifact/tests/files/Retail_EDIFACT_ORDERS_sample1.txt create mode 100644 sale_order_import_edifact/tests/files/Retail_EDIFACT_ORDERS_sample2.txt create mode 100644 sale_order_import_edifact/tests/test_edifact_order_import.py create mode 100644 sale_order_import_edifact/wizard/__init__.py create mode 100644 sale_order_import_edifact/wizard/sale_order_import.py create mode 100644 sale_order_import_edifact/wizard/sale_order_import_view.xml create mode 120000 setup/base_edifact/odoo/addons/base_edifact create mode 100644 setup/base_edifact/setup.py create mode 120000 setup/sale_order_import_edifact/odoo/addons/sale_order_import_edifact create mode 100644 setup/sale_order_import_edifact/setup.py diff --git a/base_edifact/README.rst b/base_edifact/README.rst new file mode 100644 index 0000000000..001bc5773a --- /dev/null +++ b/base_edifact/README.rst @@ -0,0 +1,127 @@ +============ +Base EDIFACT +============ + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png + :target: https://odoo-community.org/page/development-status + :alt: Alpha +.. |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/14.0/base_edifact + :alt: OCA/edi +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/edi-14-0/edi-14-0-base_edifact + :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/14.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + + +This module contains methods to generate and parse EDIFACT/D96A files + +.. IMPORTANT:: + This is an alpha version, the data model and design can change at any time without warning. + Only for development or testing purpose, do not use in production. + `More details on development status `_ + +**Table of contents** + +.. contents:: + :local: + +Installation +============ + + +This module requires 'pydifact' python library. + +Configuration +============= + +Requires partner_identification_gln module to store GLN identifiers. + +Partner identification code assigned by the European Article Numbering Association. + +Use two identification categories: + +- "GLN Identificatin Number". Partner identification like invoice or delivery address. +- "GCP Identification Number". Global Company Prefix. + +If GCP codes are needed in UNB interchange header. + +If you need group partners, consider oca/partner-contact/partner_company_group module. + +Usage +===== + + +This module doesn't do anything useful by itself, but it is used by several other modules: + +* *sale_order_import_edifact* that imports EDIFACT/D96A sale orders. + +Changelog +========= + + +14.0.1.0.0 (2023-04-13) +~~~~~~~~~~~~~~~~~~~~~~~ +Strong migration from 12.0.1.0.1 because it's not working for Amazon vendor orders. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub 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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* ALBA Software +* PlanetaTIC + +Contributors +~~~~~~~~~~~~ + +* Rafa Morant (www.albasoft.com) +* Marc Poch + +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. + +.. |maintainer-rmorant| image:: https://github.com/rmorant.png?size=40px + :target: https://github.com/rmorant + :alt: rmorant + +Current `maintainer `__: + +|maintainer-rmorant| + +This module is part of the `OCA/edi `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/base_edifact/__init__.py b/base_edifact/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/base_edifact/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/base_edifact/__manifest__.py b/base_edifact/__manifest__.py new file mode 100644 index 0000000000..3f1dcf134f --- /dev/null +++ b/base_edifact/__manifest__.py @@ -0,0 +1,29 @@ +# Copyright 2023 ALBA Software S.L. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl-3.0) + +{ + "name": "Base EDIFACT", + "summary": "UN/EDIFACT/D96A utilities using pydifact parser", + "version": "14.0.1.0.0", + "development_status": "Alpha", + "category": "Tools", + "website": "https://github.com/OCA/edi", + "author": "ALBA Software, PlanetaTIC, Odoo Community Association (OCA)", + "maintainers": ["rmorant"], + "license": "AGPL-3", + "application": False, + "installable": True, + # "preloadable": True, + "external_dependencies": { + "python": ["pydifact"], + "bin": [], + }, + "depends": [ + # "edi_party_data_oca" + # for configuration + "account", + "partner_identification", + "partner_identification_gln", + ], + "data": [], +} diff --git a/base_edifact/models/__init__.py b/base_edifact/models/__init__.py new file mode 100644 index 0000000000..6216ddc789 --- /dev/null +++ b/base_edifact/models/__init__.py @@ -0,0 +1 @@ +from . import edifact diff --git a/base_edifact/models/edifact.py b/base_edifact/models/edifact.py new file mode 100644 index 0000000000..76c17b0bee --- /dev/null +++ b/base_edifact/models/edifact.py @@ -0,0 +1,211 @@ +import datetime +import logging + +from pydifact.segmentcollection import Interchange, Message +from pydifact.segments import Segment + +from odoo import _, api, exceptions, models + +from odoo.addons.edi_party_data_oca.utils import get_party_data_component + +logger = logging.getLogger(__name__) + + +# https://github.com/nerdocs/pydifact +class BasePydifact(models.AbstractModel): + _name = "base.edifact" + _description = "Generate and parse Edifact documents" + + MAP_AGENCY_CODE_2_RES_PARTNER_NAMEREF = {"9": "gln"} + CURRENCY_SYMBOLS = { + "EUR": "€", + "USD": "$", + } + PRODUCT_CODE_TYPES = {"EN": "EAN", "UP": "UPC", "SRV": "GTIN"} + + @api.model + def pydifact_import(self, names): + classes = { + "Segment": Segment, + "Message": Message, + "Interchange": Interchange, + } + return [classes.get(name, None) for name in names] + + @api.model + def pydifact_obj(self, docu): + obj = [] + interchange = self._loads_edifact(docu) + header_seg = interchange.get_header_segment() + header_dict = dict() + header_dict[header_seg.tag] = header_seg.elements + obj.append(header_dict) + for message in interchange.get_messages(): + segms = [] + msg = { + "reference_number": message.reference_number, + "type": message.type, + "version": message.version, + "identifier": message.identifier, + "HEADER_TAG": message.HEADER_TAG, + "FOOTER_TAG": message.FOOTER_TAG, + "characters": str(message.characters), + "extra_header_elements": message.extra_header_elements, + "has_una_segment": message.has_una_segment, + } + logger.info(message) + for segment in message.segments: + logger.info( + "Segment tag: {}, content: {}".format(segment.tag, segment.elements) + ) + # segms.append((segment.tag, segment.elements)) + seg = dict() + seg[segment.tag] = segment.elements + segms.append(seg) + msg["segments"] = segms + obj.append(msg) + return obj + + @api.model + def get_party_data(self, exchange_record, partner, raise_if_not_found=True): + provider = get_party_data_component(exchange_record, partner) + if not provider and raise_if_not_found: + raise exceptions.UserError(_("No info provider found for party data")) + return provider.get_party() if provider else None + + @api.model + def _loads_edifact(self, order_file): + interchange = Interchange.from_str(order_file.decode()) + return interchange + + @api.model + def _get_msg_type(self, interchange): + seg = interchange.get_segment("UNH") + # MSG_TYPE, EDIFACT_MSG_TYPE_RELEASE + return (seg[1][0], "{}{}".format(seg[1][1], seg[1][2])) + + @api.model + def map2odoo_date(self, dt): + # '102' + dtt = datetime.datetime.strptime(dt[1], "%Y%m%d") + return dtt.date() + + @api.model + def map2odoo_partner(self, seg): + """ + BY. Party to which merchandise is sold. + NAD+BY+5550534000017::9' + NAD segment: ['BY', ['5550534001649', '', '9']] + + SU. Party which manufactures or otherwise has possession of + goods,and consigns or makes them available in trade. + NAD+SU+::9' + """ + + partner_dict = {} + codes = ["BY", "SU"] + reference_code = seg[0] + if reference_code not in codes: + raise NotImplementedError(f"Code '{reference_code}' not implemented") + # + party_identification = seg[1] + party_id = party_identification[0] + agency_code = party_identification[2] + nameref = self.MAP_AGENCY_CODE_2_RES_PARTNER_NAMEREF.get(agency_code, "gln") + partner_dict[nameref] = party_id + return partner_dict + + @api.model + def map2odoo_address(self, seg): + """ + DP. Party to which goods should be delivered, if not identical with + consignee. + NAD+DP+5550534000086::9+++++++DE' + NAD segment: ['DP', ['5550534022101', '', '9'], '', '', '', '', '', '', 'ES'] + IV. Party to whom an invoice is issued. + NAD+IV+5450534005838::9++AMAZON EU SARL:NIEDERLASSUNG + DEUTSCHLAND+MARCEL-BREUER-STR. 12+MUENCHEN++80807+DE + + :returns: { + 'type': + 'partner': {'gln':''} + 'address': {...} + } + """ + if seg[0] not in ("DP", "IV"): + return False + order_type = "delivery" if seg[0] == "DP" else "invoice" + address = dict(type=order_type, partner={}, address={}) + # PARTY IDENTIFICATION DETAILS + iden = seg[1] + party_id = iden[0] + agency_code = iden[2] + nameref = self.MAP_AGENCY_CODE_2_RES_PARTNER_NAMEREF.get(agency_code, "gln") + address["partner"][nameref] = party_id + d = address["address"] + # PARTY NAME + if bool(seg[2]): + d["name"] = seg[2] + if bool(seg[3]): + d["name"] = "{}{}".format(f"{d['name']}. " if d.get("name") else "", seg[3]) + if bool(seg[4]): + # Street address and/or PO Box number in a structured address: one to three lines. + d["street"] = seg[4] + if bool(seg[5]): + d["city"] = seg[5] + if bool(seg[6]): + # Country sub-entity identification + d["state_code"] = seg[6] + if bool(seg[7]): + d["zip"] = seg[7] + if bool(seg[8]): + # Country, coded ISO 3166 + d["country_code"] = seg[8] + + return address + + @api.model + def map2odoo_currency(self, seg): + """ + ['2', 'EUR', '9'] + """ + # Identification of the name or symbol of the monetary unit involved in the transaction. + currency_coded = seg[1] + return { + "iso": currency_coded, + "symbol": self.CURRENCY_SYMBOLS.get(currency_coded, False), + } + + @api.model + def map2odoo_product(self, seg): + """ + :seg: LIN segment + ['1', '', ['8885583503464', 'EN']] + EN. International Article Numbering Association (EAN) + UP. UPC (Universal product code) + SRV. GTIN + """ + product = seg[2] + pct = product[1] + return dict(code=product[0]) if pct == "SRV" else dict(barcode=product[0]) + + @api.model + def map2odoo_qty(self, seg): + """ + 'QTY' EDI segment: [['21', '2']] + '21'. Ordered quantity + """ + return float(seg[0][1]) + + @api.model + def map2odoo_unit_price(self, seg): + """ + 'PRI' EDI segment: [['AAA', '19.75']] + Price qualifier: + * 'AAA'. Calculation net + * 'AAB'. Calculation gross + """ + pri = seg[0] + if pri[0] == "AAA": + return float(pri[1]) + return 0.0 diff --git a/base_edifact/readme/CONFIGURE.rst b/base_edifact/readme/CONFIGURE.rst new file mode 100644 index 0000000000..52e98dc493 --- /dev/null +++ b/base_edifact/readme/CONFIGURE.rst @@ -0,0 +1,12 @@ +Requires partner_identification_gln module to store GLN identifiers. + +Partner identification code assigned by the European Article Numbering Association. + +Use two identification categories: + +- "GLN Identificatin Number". Partner identification like invoice or delivery address. +- "GCP Identification Number". Global Company Prefix. + +If GCP codes are needed in UNB interchange header. + +If you need group partners, consider oca/partner-contact/partner_company_group module. diff --git a/base_edifact/readme/CONTRIBUTORS.rst b/base_edifact/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000000..4dbcae9a88 --- /dev/null +++ b/base_edifact/readme/CONTRIBUTORS.rst @@ -0,0 +1,2 @@ +* Rafa Morant (www.albasoft.com) +* Marc Poch diff --git a/base_edifact/readme/DESCRIPTION.rst b/base_edifact/readme/DESCRIPTION.rst new file mode 100644 index 0000000000..397f86d645 --- /dev/null +++ b/base_edifact/readme/DESCRIPTION.rst @@ -0,0 +1,2 @@ + +This module contains methods to generate and parse EDIFACT/D96A files diff --git a/base_edifact/readme/HISTORY.rst b/base_edifact/readme/HISTORY.rst new file mode 100644 index 0000000000..5a4112e667 --- /dev/null +++ b/base_edifact/readme/HISTORY.rst @@ -0,0 +1,4 @@ + +14.0.1.0.0 (2023-04-13) +~~~~~~~~~~~~~~~~~~~~~~~ +Strong migration from 12.0.1.0.1 because it's not working for Amazon vendor orders. diff --git a/base_edifact/readme/INSTALL.rst b/base_edifact/readme/INSTALL.rst new file mode 100644 index 0000000000..bffb87393a --- /dev/null +++ b/base_edifact/readme/INSTALL.rst @@ -0,0 +1,2 @@ + +This module requires 'pydifact' python library. diff --git a/base_edifact/readme/USAGE.rst b/base_edifact/readme/USAGE.rst new file mode 100644 index 0000000000..6b984bee24 --- /dev/null +++ b/base_edifact/readme/USAGE.rst @@ -0,0 +1,4 @@ + +This module doesn't do anything useful by itself, but it is used by several other modules: + +* *sale_order_import_edifact* that imports EDIFACT/D96A sale orders. diff --git a/base_edifact/static/description/icon.png b/base_edifact/static/description/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..3a0328b516c4980e8e44cdb63fd945757ddd132d GIT binary patch literal 9455 zcmW++2RxMjAAjx~&dlBk9S+%}OXg)AGE&Cb*&}d0jUxM@u(PQx^-s)697TX`ehR4?GS^qbkof1cslKgkU)h65qZ9Oc=ml_0temigYLJfnz{IDzUf>bGs4N!v3=Z3jMq&A#7%rM5eQ#dc?k~! zVpnB`o+K7|Al`Q_U;eD$B zfJtP*jH`siUq~{KE)`jP2|#TUEFGRryE2`i0**z#*^6~AI|YzIWy$Cu#CSLW3q=GA z6`?GZymC;dCPk~rBS%eCb`5OLr;RUZ;D`}um=H)BfVIq%7VhiMr)_#G0N#zrNH|__ zc+blN2UAB0=617@>_u;MPHN;P;N#YoE=)R#i$k_`UAA>WWCcEVMh~L_ zj--gtp&|K1#58Yz*AHCTMziU1Jzt_jG0I@qAOHsk$2}yTmVkBp_eHuY$A9)>P6o~I z%aQ?!(GqeQ-Y+b0I(m9pwgi(IIZZzsbMv+9w{PFtd_<_(LA~0H(xz{=FhLB@(1&qHA5EJw1>>=%q2f&^X>IQ{!GJ4e9U z&KlB)z(84HmNgm2hg2C0>WM{E(DdPr+EeU_N@57;PC2&DmGFW_9kP&%?X4}+xWi)( z;)z%wI5>D4a*5XwD)P--sPkoY(a~WBw;E~AW`Yue4kFa^LM3X`8x|}ZUeMnqr}>kH zG%WWW>3ml$Yez?i%)2pbKPI7?5o?hydokgQyZsNEr{a|mLdt;X2TX(#B1j35xPnPW z*bMSSOauW>o;*=kO8ojw91VX!qoOQb)zHJ!odWB}d+*K?#sY_jqPdg{Sm2HdYzdEx zOGVPhVRTGPtv0o}RfVP;Nd(|CB)I;*t&QO8h zFfekr30S!-LHmV_Su-W+rEwYXJ^;6&3|L$mMC8*bQptyOo9;>Qb9Q9`ySe3%V$A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*I literal 0 HcmV?d00001 diff --git a/base_edifact/static/description/icon.svg b/base_edifact/static/description/icon.svg new file mode 100644 index 0000000000..a7a26d0932 --- /dev/null +++ b/base_edifact/static/description/icon.svg @@ -0,0 +1,79 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + diff --git a/base_edifact/static/description/index.html b/base_edifact/static/description/index.html new file mode 100644 index 0000000000..4c92997f2b --- /dev/null +++ b/base_edifact/static/description/index.html @@ -0,0 +1,466 @@ + + + + + + +Base EDIFACT + + + +
+

Base EDIFACT

+ + +

Alpha License: AGPL-3 OCA/edi Translate me on Weblate Try me on Runbot

+

This module contains methods to generate and parse EDIFACT/D96A files

+
+

Important

+

This is an alpha version, the data model and design can change at any time without warning. +Only for development or testing purpose, do not use in production. +More details on development status

+
+

Table of contents

+ +
+

Installation

+

This module requires ‘pydifact’ python library.

+
+
+

Configuration

+

Requires partner_identification_gln module to store GLN identifiers.

+

Partner identification code assigned by the European Article Numbering Association.

+

Use two identification categories:

+
    +
  • “GLN Identificatin Number”. Partner identification like invoice or delivery address.
  • +
  • “GCP Identification Number”. Global Company Prefix.
  • +
+

If GCP codes are needed in UNB interchange header.

+

If you need group partners, consider oca/partner-contact/partner_company_group module.

+
+
+

Usage

+

This module doesn’t do anything useful by itself, but it is used by several other modules:

+
    +
  • sale_order_import_edifact that imports EDIFACT/D96A sale orders.
  • +
+
+
+

Changelog

+
+

14.0.1.0.0 (2023-04-13)

+

Strong migration from 12.0.1.0.1 because it’s not working for Amazon vendor orders.

+
+
+
+

Bug Tracker

+

Bugs are tracked on GitHub 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.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • ALBA Software
  • +
  • PlanetaTIC
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

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.

+

Current maintainer:

+

rmorant

+

This module is part of the OCA/edi project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/base_edifact/tests/__init__.py b/base_edifact/tests/__init__.py new file mode 100644 index 0000000000..25dfeb0bc2 --- /dev/null +++ b/base_edifact/tests/__init__.py @@ -0,0 +1 @@ +from . import test_base_edifact diff --git a/base_edifact/tests/test_base_edifact.py b/base_edifact/tests/test_base_edifact.py new file mode 100644 index 0000000000..11d99785fb --- /dev/null +++ b/base_edifact/tests/test_base_edifact.py @@ -0,0 +1,56 @@ +# Copyright 2023 ALBA Software S.L. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl-3.0) + + +from odoo.tests.common import TransactionCase + + +class TestBaseEdifact(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + + @classmethod + def tearDownClass(cls): + super().tearDownClass() + + def setUp(self): + super().setUp() + self.base_edifact_model = self.env["base.edifact"] + + def tearDown(self): + return super().tearDown() + + def test_map2odoo_address(self): + """Address segment + DP. Party to which goods should be delivered, if not identical with + consignee. + NAD+DP+5550534000086::9+++++++DE' + NAD segment: ['DP', ['5550534022101', '', '9'], '', '', '', '', '', '', 'ES'] + """ + seg = ["DP", ["5550534000086", "", "9"], "", "", "", "", "", "", "ES"] + address = self.base_edifact_model.map2odoo_address(seg) + self.assertEqual(address["type"], "delivery") + self.assertEqual(address["partner"], {"gln": "5550534000086"}) + self.assertEqual(address["address"]["country_code"], "ES") + + def test_map2odoo_currency(self): + seg = ("2", "EUR", "9") + currency = self.base_edifact_model.map2odoo_currency(seg) + self.assertEqual(currency["iso"], "EUR") + self.assertEqual(currency["symbol"], "€") + + def test_map2odoo_product(self): + seg = ("1", "", ["8885583503464", "EN"]) + product = self.base_edifact_model.map2odoo_product(seg) + self.assertEqual(product["barcode"], "8885583503464") + + def test_map2odoo_qty(self): + seg = (["21", "2"],) + qty = self.base_edifact_model.map2odoo_qty(seg) + self.assertEqual(qty, 2.0) + + def test_map2odoo_unit_price(self): + seg = (["AAA", "19.75"],) + unit_price = self.base_edifact_model.map2odoo_unit_price(seg) + self.assertEqual(unit_price, 19.75) diff --git a/requirements.txt b/requirements.txt index 09fb3d4f37..1d09ae6653 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,6 +5,7 @@ invoice2data ovh pdfplumber phonenumbers +pydifact pyyaml regex xmlschema diff --git a/sale_order_import_edifact/README.rst b/sale_order_import_edifact/README.rst new file mode 100644 index 0000000000..9d44702343 --- /dev/null +++ b/sale_order_import_edifact/README.rst @@ -0,0 +1,154 @@ +=========================================== +Import Business Document EDIFACT/D96A Order +=========================================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png + :target: https://odoo-community.org/page/development-status + :alt: Alpha +.. |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/14.0/sale_order_import_edifact + :alt: OCA/edi +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/edi-14-0/edi-14-0-sale_order_import_edifact + :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/14.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +UN/EDIFACT + United Nations rules for Elec­tronic Data Interchange for Administration, Commerce and Transport + +This module plugs EDIFACT/D96A ORDER in sale_order_import process. + +https://www.stedi.com/edi/edifact/D96A/messages/ORDERS + +.. IMPORTANT:: + This is an alpha version, the data model and design can change at any time without warning. + Only for development or testing purpose, do not use in production. + `More details on development status `_ + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + + +EDI Exchange Type "Advanced Settings" + +.. code-block:: yaml + + components: + process: + usage: input.process.sale.order + + sale_order_import: + price_source: order + confirm_order: false + wiz_ctx: + file_ext: 'edi' + release: 'd96a' + doc_type: 'rfq' + + +- price_source. Can be 'order' or 'pricelist' +- confirm_order. False by default +- wiz_ctx. Wizard's context + - file_ext. File extensions supported. By default: 'txt,d96a' + - release. EDIFACT format release. + - doc_type. ('rfq', "Request for Quotation") | ('order', "Order"). Default 'order' + +This module struggles with EDIFACT format, if you need X12 format you will need something like sale_order_import_x12 module. + +Regardless format, a concret document should need a concret specification nammed release. For example Amazon uses "D96A" specification. + +See + +Known issues / Roadmap +====================== + +.. Enumerate known caveats and future potential improvements. + It is mostly intended for end-users, and can also help + potential new contributors discovering new features to implement. + +* Refactor import by release + +Changelog +========= + +.. The change log. The goal of this file is to help readers + understand changes between versions. The primary audience is + end users and integrators. Purely technical changes such as + code refactoring must not be mentioned here. + + This file may contain ONE level of section titles, underlined + with the ~ (tilde) character. Other section markers are + forbidden and will likely break the structure of the README.rst + or other documents where this fragment is included. + +14.0.1.0.0 (2023-06-07) +~~~~~~~~~~~~~~~~~~~~~~~ + +* [14.0][MIG] sale_order_import_edifact & base_edifact. + (`#779 `_) + +Bug Tracker +=========== + +Bugs are tracked on `GitHub 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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* ALBA Software + +Contributors +~~~~~~~~~~~~ + +* Rafa Morant (https://www.albasoft.com) +* Marc Poch + +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. + +.. |maintainer-rmorant| image:: https://github.com/rmorant.png?size=40px + :target: https://github.com/rmorant + :alt: rmorant + +Current `maintainer `__: + +|maintainer-rmorant| + +This module is part of the `OCA/edi `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/sale_order_import_edifact/__init__.py b/sale_order_import_edifact/__init__.py new file mode 100644 index 0000000000..9b4296142f --- /dev/null +++ b/sale_order_import_edifact/__init__.py @@ -0,0 +1,2 @@ +from . import models +from . import wizard diff --git a/sale_order_import_edifact/__manifest__.py b/sale_order_import_edifact/__manifest__.py new file mode 100644 index 0000000000..eeea97e189 --- /dev/null +++ b/sale_order_import_edifact/__manifest__.py @@ -0,0 +1,31 @@ +# Copyright 2023 ALBA Software S.L. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl-3.0) + +{ + "name": "Import Business Document EDIFACT/D96A Order", + "summary": "EDIFACT/D96A Order", + "version": "14.0.1.0.0", + "development_status": "Alpha", + "category": "Sales Management", + "website": "https://github.com/OCA/edi", + "author": "ALBA Software, Odoo Community Association (OCA)", + "maintainers": ["rmorant"], + "license": "AGPL-3", + "application": False, + "installable": True, + "external_dependencies": { + "python": [], + "bin": [], + }, + "depends": [ + "sale_management", + "partner_identification", + "partner_identification_gln", + "base_edifact", + "edi_sale_order_import", + ], + "data": [ + "wizard/sale_order_import_view.xml", + ], + "demo": ["demo/demo_data.xml"], +} diff --git a/sale_order_import_edifact/demo/demo_data.xml b/sale_order_import_edifact/demo/demo_data.xml new file mode 100644 index 0000000000..0e17c7abd5 --- /dev/null +++ b/sale_order_import_edifact/demo/demo_data.xml @@ -0,0 +1,81 @@ + + + + + AMATEST EU SARL + + + 38 Avenue J.F. Kennedy + 1234 + Luxembourg + + + + AMATEST EU (TST) + + 80 Bojsdoeisn + 4321 + Gliwice + + + delivery + + + AMATEST Invoice + + Accountant + + invoice + + + + + + + 5450534000017 + + + + + 5450534008617 + + + + + 5450534008143 + + + + EDIFACT Demo 1 + + consu + edifact1 + + 9783898307529 + + + EDIFACT Demo 2 + + consu + edifac2 + + 9783898307538 + + + EDIFACT Demo 3 + + consu + edifact + + 9783898307645 + + diff --git a/sale_order_import_edifact/models/__init__.py b/sale_order_import_edifact/models/__init__.py new file mode 100644 index 0000000000..d695bc5f59 --- /dev/null +++ b/sale_order_import_edifact/models/__init__.py @@ -0,0 +1 @@ +from . import business_document_import diff --git a/sale_order_import_edifact/models/business_document_import.py b/sale_order_import_edifact/models/business_document_import.py new file mode 100644 index 0000000000..f495f4f3f0 --- /dev/null +++ b/sale_order_import_edifact/models/business_document_import.py @@ -0,0 +1,54 @@ +# Copyright 2019 PlanetaTIC - Marc Poch +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import _, api, exceptions, models + + +class BusinessDocumentImport(models.AbstractModel): + _inherit = "business.document.import" + + @api.model + def _hook_match_partner(self, partner_dict, chatter_msg, domain, order): + """ + 2 types + partner_dict = {'gln':""} + partner_dict = {'partner': {'gln':""}, 'address':{'country_code':"ES",...}} + """ + partner = partner_dict.get("partner", partner_dict) + partner_dict.get("address", False) + if not partner.get("gln"): + return super()._hook_match_partner(partner_dict, chatter_msg, domain, order) + party_id = partner["gln"] + + partner_id_category = self.env.ref( + "partner_identification_gln.partner_identification_gln_number_category" + ) + if not partner_id_category: + raise exceptions.UserError( + _( + "partner_identification_gln module should be installed with a xmlid: " + "partner_identification_gln_number_category" + ) + ) + id_number = self.env["res.partner.id_number"].search( + [("category_id", "=", int(partner_id_category)), ("name", "=", party_id)], + limit=1, + ) + if not id_number: + ctx = partner.get( + "edi_ctx", {"order_filename": _("Unknown"), "rff_va": _("Unknown")} + ) + raise exceptions.UserError( + _( + "Partner GLN Code: %s not found in order file: '%s' " + "from VAT registration number '%s'." + ) + % (party_id, ctx.get("order_filename"), ctx.get("rff_va")) + ) + + return id_number.partner_id + + # @api.model + # def post_create_or_update(self, parsed_dict, record, doc_filename=None): + # if 'origin_exchange_record_id' in record.fields_get(): + # record.origin_exchange_record_id = diff --git a/sale_order_import_edifact/readme/CONFIGURE.rst b/sale_order_import_edifact/readme/CONFIGURE.rst new file mode 100644 index 0000000000..dfd1b95a6a --- /dev/null +++ b/sale_order_import_edifact/readme/CONFIGURE.rst @@ -0,0 +1,30 @@ + +EDI Exchange Type "Advanced Settings" + +.. code-block:: yaml + + components: + process: + usage: input.process.sale.order + + sale_order_import: + price_source: order + confirm_order: false + wiz_ctx: + file_ext: 'edi' + release: 'd96a' + doc_type: 'rfq' + + +- price_source. Can be 'order' or 'pricelist' +- confirm_order. False by default +- wiz_ctx. Wizard's context + - file_ext. File extensions supported. By default: 'txt,d96a' + - release. EDIFACT format release. + - doc_type. ('rfq', "Request for Quotation") | ('order', "Order"). Default 'order' + +This module struggles with EDIFACT format, if you need X12 format you will need something like sale_order_import_x12 module. + +Regardless format, a concret document should need a concret specification nammed release. For example Amazon uses "D96A" specification. + +See diff --git a/sale_order_import_edifact/readme/CONTRIBUTORS.rst b/sale_order_import_edifact/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000000..a153b2ddd1 --- /dev/null +++ b/sale_order_import_edifact/readme/CONTRIBUTORS.rst @@ -0,0 +1,2 @@ +* Rafa Morant (https://www.albasoft.com) +* Marc Poch diff --git a/sale_order_import_edifact/readme/DESCRIPTION.rst b/sale_order_import_edifact/readme/DESCRIPTION.rst new file mode 100644 index 0000000000..0874269f06 --- /dev/null +++ b/sale_order_import_edifact/readme/DESCRIPTION.rst @@ -0,0 +1,6 @@ +UN/EDIFACT + United Nations rules for Elec­tronic Data Interchange for Administration, Commerce and Transport + +This module plugs EDIFACT/D96A ORDER in sale_order_import process. + +https://www.stedi.com/edi/edifact/D96A/messages/ORDERS diff --git a/sale_order_import_edifact/readme/HISTORY.rst b/sale_order_import_edifact/readme/HISTORY.rst new file mode 100644 index 0000000000..c57a493aa1 --- /dev/null +++ b/sale_order_import_edifact/readme/HISTORY.rst @@ -0,0 +1,15 @@ +.. The change log. The goal of this file is to help readers + understand changes between versions. The primary audience is + end users and integrators. Purely technical changes such as + code refactoring must not be mentioned here. + + This file may contain ONE level of section titles, underlined + with the ~ (tilde) character. Other section markers are + forbidden and will likely break the structure of the README.rst + or other documents where this fragment is included. + +14.0.1.0.0 (2023-06-07) +~~~~~~~~~~~~~~~~~~~~~~~ + +* [14.0][MIG] sale_order_import_edifact & base_edifact. + (`#779 `_) diff --git a/sale_order_import_edifact/readme/ROADMAP.rst b/sale_order_import_edifact/readme/ROADMAP.rst new file mode 100644 index 0000000000..e5c8273d15 --- /dev/null +++ b/sale_order_import_edifact/readme/ROADMAP.rst @@ -0,0 +1,5 @@ +.. Enumerate known caveats and future potential improvements. + It is mostly intended for end-users, and can also help + potential new contributors discovering new features to implement. + +* Refactor import by release diff --git a/sale_order_import_edifact/static/description/icon.png b/sale_order_import_edifact/static/description/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..3a0328b516c4980e8e44cdb63fd945757ddd132d GIT binary patch literal 9455 zcmW++2RxMjAAjx~&dlBk9S+%}OXg)AGE&Cb*&}d0jUxM@u(PQx^-s)697TX`ehR4?GS^qbkof1cslKgkU)h65qZ9Oc=ml_0temigYLJfnz{IDzUf>bGs4N!v3=Z3jMq&A#7%rM5eQ#dc?k~! zVpnB`o+K7|Al`Q_U;eD$B zfJtP*jH`siUq~{KE)`jP2|#TUEFGRryE2`i0**z#*^6~AI|YzIWy$Cu#CSLW3q=GA z6`?GZymC;dCPk~rBS%eCb`5OLr;RUZ;D`}um=H)BfVIq%7VhiMr)_#G0N#zrNH|__ zc+blN2UAB0=617@>_u;MPHN;P;N#YoE=)R#i$k_`UAA>WWCcEVMh~L_ zj--gtp&|K1#58Yz*AHCTMziU1Jzt_jG0I@qAOHsk$2}yTmVkBp_eHuY$A9)>P6o~I z%aQ?!(GqeQ-Y+b0I(m9pwgi(IIZZzsbMv+9w{PFtd_<_(LA~0H(xz{=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(#@w$Y_H7G22M~ApVFTRHMI_3be)Lkn#0F*V8Pq zc}`Cjy$bE;FJ6H7p=0y#R>`}-m4(0F>%@P|?7fx{=R^uFdISRnZ2W_xQhD{YuR3t< z{6yxu=4~JkeA;|(J6_nv#>Nvs&FuLA&PW^he@t(UwFFE8)|a!R{`E`K`i^ZnyE4$k z;(749Ix|oi$c3QbEJ3b~D_kQsPz~fIUKym($a_7dJ?o+40*OLl^{=&oq$<#Q(yyrp z{J-FAniyAw9tPbe&IhQ|a`DqFTVQGQ&Gq3!C2==4x{6EJwiPZ8zub-iXoUtkJiG{} zPaR&}_fn8_z~(=;5lD-aPWD3z8PZS@AaUiomF!G8I}Mf>e~0g#BelA-5#`cj;O5>N Xviia!U7SGha1wx#SCgwmn*{w2TRX*I literal 0 HcmV?d00001 diff --git a/sale_order_import_edifact/static/description/icon.svg b/sale_order_import_edifact/static/description/icon.svg new file mode 100644 index 0000000000..a7a26d0932 --- /dev/null +++ b/sale_order_import_edifact/static/description/icon.svg @@ -0,0 +1,79 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + diff --git a/sale_order_import_edifact/static/description/index.html b/sale_order_import_edifact/static/description/index.html new file mode 100644 index 0000000000..007ccd6242 --- /dev/null +++ b/sale_order_import_edifact/static/description/index.html @@ -0,0 +1,495 @@ + + + + + + +Import Business Document EDIFACT/D96A Order + + + +
+

Import Business Document EDIFACT/D96A Order

+ + +

Alpha License: AGPL-3 OCA/edi Translate me on Weblate Try me on Runbot

+
+
UN/EDIFACT
+
United Nations rules for Elec­tronic Data Interchange for Administration, Commerce and Transport
+
+

This module plugs EDIFACT/D96A ORDER in sale_order_import process.

+

https://www.stedi.com/edi/edifact/D96A/messages/ORDERS

+
+

Important

+

This is an alpha version, the data model and design can change at any time without warning. +Only for development or testing purpose, do not use in production. +More details on development status

+
+

Table of contents

+ +
+

Configuration

+

EDI Exchange Type “Advanced Settings”

+
+components:
+   process:
+      usage: input.process.sale.order
+
+sale_order_import:
+   price_source: order
+   confirm_order: false
+   wiz_ctx:
+      file_ext: 'edi'
+      release: 'd96a'
+      doc_type: 'rfq'
+
+
    +
  • price_source. Can be ‘order’ or ‘pricelist’
  • +
  • confirm_order. False by default
  • +
  • wiz_ctx. Wizard’s context +- file_ext. File extensions supported. By default: ‘txt,d96a’ +- release. EDIFACT format release. +- doc_type. (‘rfq’, “Request for Quotation”) | (‘order’, “Order”). Default ‘order’
  • +
+

This module struggles with EDIFACT format, if you need X12 format you will need something like sale_order_import_x12 module.

+

Regardless format, a concret document should need a concret specification nammed release. For example Amazon uses “D96A” specification.

+

See <https://www.stedi.com/edi/edifact>

+
+
+

Known issues / Roadmap

+ +
    +
  • Refactor import by release
  • +
+
+
+

Changelog

+ +
+

14.0.1.0.0 (2023-06-07)

+
    +
  • [14.0][MIG] sale_order_import_edifact & base_edifact. +(#779)
  • +
+
+
+
+

Bug Tracker

+

Bugs are tracked on GitHub 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.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • ALBA Software
  • +
+
+ +
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

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.

+

Current maintainer:

+

rmorant

+

This module is part of the OCA/edi project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/sale_order_import_edifact/tests/__init__.py b/sale_order_import_edifact/tests/__init__.py new file mode 100644 index 0000000000..90d50ce03d --- /dev/null +++ b/sale_order_import_edifact/tests/__init__.py @@ -0,0 +1 @@ +from . import test_edifact_order_import diff --git a/sale_order_import_edifact/tests/common.py b/sale_order_import_edifact/tests/common.py new file mode 100644 index 0000000000..5a483c5e97 --- /dev/null +++ b/sale_order_import_edifact/tests/common.py @@ -0,0 +1,42 @@ +# Copyright 2016 Akretion +# @author: Alexis de Lattre ) +# Copyright 2022 Camptocamp +# @author: Simone Orsi +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from functools import partial + +from odoo.tools import DotDict, file_open + + +def _get_file_content(filename): + path = "sale_order_import_edifact/tests/files/" + filename + with file_open(path, "rb") as fd: + return fd.read() + + +def get_test_data(env): + ref = env.ref + return { + "Retail_EDIFACT_ORDERS_sample1.txt": DotDict( + { + "_get_content": partial( + _get_file_content, "Retail_EDIFACT_ORDERS_sample1.txt" + ), + "client_order_ref": "1AA1TEST", + "date_order": "2023-06-06", + "partner": ref("sale_order_import_edifact.partner_edi_invoiceto_dm"), + "shipping_partner": ref( + "sale_order_import_edifact.partner_edi_shipto_dm" + ), + # "invoicing_partner": ref( + # "sale_order_import_edifact.partner_edi_invoiceto_dm" + # ), + # "currency": ref("base.SEK"), + # "commitment_date": "", + "products": ref("sale_order_import_edifact.product_product_edifact1_dm") + + ref("sale_order_import_edifact.product_product_edifact2_dm") + + ref("sale_order_import_edifact.product_product_edifact3_dm"), + } + ) + } diff --git a/sale_order_import_edifact/tests/files/Retail_EDIFACT_ORDERS_sample1.txt b/sale_order_import_edifact/tests/files/Retail_EDIFACT_ORDERS_sample1.txt new file mode 100644 index 0000000000..59e6923fd8 --- /dev/null +++ b/sale_order_import_edifact/tests/files/Retail_EDIFACT_ORDERS_sample1.txt @@ -0,0 +1,26 @@ +UNB+UNOA:2+5450534000000:14+8450534000000:14+221117:0134+4234++++1+EANCOM' +UNH+1+ORDERS:D:96A:UN:EAN008' +BGM+220+1AA1TEST+9' +DTM+137:20230606:102' +DTM+63:20230606:102' +DTM+64:20230606:102' +RFF+CR:ABCD5' +NAD+BY+5450534000017::9' +NAD+SU+8450534000000::9' +NAD+DP+5450534008617::9+++++++GB' +NAD+IV+5450534008143::9++AMAZON EU SARL+38 Avenue J.F. Kennedy+Luxembourg++1855+LU' +RFF+VA:LU20260743' +CUX+2:EUR:9' +LIN+1++9783898307529:EN' +QTY+21:5' +PRI+AAA:27.5' +LIN+2++9783898307538:EN' +QTY+21:1' +PRI+AAA:10.87' +LIN+3++9783898307645:EN' +QTY+21:3' +PRI+AAA:3.85' +UNS+S' +CNT+2:3' +UNT+24+1' +UNZ+1+4234' diff --git a/sale_order_import_edifact/tests/files/Retail_EDIFACT_ORDERS_sample2.txt b/sale_order_import_edifact/tests/files/Retail_EDIFACT_ORDERS_sample2.txt new file mode 100644 index 0000000000..29bdb06d69 --- /dev/null +++ b/sale_order_import_edifact/tests/files/Retail_EDIFACT_ORDERS_sample2.txt @@ -0,0 +1,29 @@ +UNB+UNOA:2+5450534000000:14+:14+221117:0134+4234++++1+EANCOM' +UNH+1+ORDERS:D:96A:UN:EAN008' +BGM+220+1AA1TEST+9' +DTM+137:20221117:102' +DTM+63:20221127:102' +DTM+64:20221124:102' +RFF+CR:ABCD5' +NAD+BY+5450534000017::9' +NAD+SU+::9' +NAD+DP+5450534000086::9+++++++DE' +NAD+IV+5450534005838::9++AMAZON EU SARL:NIEDERLASSUNG DEUTSCHLAND+MARCEL-BREUER-STR. 12+MUENCHEN++80807+DE' +RFF+VA:DE814584193' +CUX+2:EUR:9' +LIN+1' +PIA+5+567123:SA' +QTY+21:5' +PRI+AAA:27.5' +LIN+2' +PIA+5+1234567:SA' +QTY+21:1' +PRI+AAA:10.87' +LIN+3' +PIA+5+765432:SA' +QTY+21:3' +PRI+AAA:3.85' +UNS+S' +CNT+2:3' +UNT+27+1' +UNZ+1+4234' diff --git a/sale_order_import_edifact/tests/test_edifact_order_import.py b/sale_order_import_edifact/tests/test_edifact_order_import.py new file mode 100644 index 0000000000..5bf0f57016 --- /dev/null +++ b/sale_order_import_edifact/tests/test_edifact_order_import.py @@ -0,0 +1,40 @@ +# Copyright 2023 ALBA Software S.L. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl-3.0) + +import base64 + +from odoo.tests.common import TransactionCase +from odoo.tools import mute_logger + +from .common import get_test_data + + +class TestEdifactOrderImport(TransactionCase): + @mute_logger("odoo.addons.sale_order_import.wizard.sale_order_import") + def test_edifact_order_import(self): + tests = get_test_data(self.env) + for filename, expected in tests.items(): + edifact_file = expected._get_content() + wiz = self.env["sale.order.import"].create( + { + "order_file": base64.b64encode(edifact_file), + "order_filename": filename, + } + ) + action = wiz.import_order_button() + so = self.env["sale.order"].browse(action["res_id"]) + self.assertEqual(so.partner_id, expected["partner"]) + + if expected.get("client_order_ref"): + self.assertEqual(so.client_order_ref, expected["client_order_ref"]) + + if expected.get("shipping_partner"): + self.assertEqual(so.partner_shipping_id, expected["shipping_partner"]) + if expected.get("invoicing_partner"): + self.assertEqual(so.partner_invoice_id, expected["invoicing_partner"]) + + if expected.get("products"): + expected_ids = sorted(expected["products"].ids) + self.assertEqual( + sorted(so.order_line.mapped("product_id").ids), expected_ids + ) diff --git a/sale_order_import_edifact/wizard/__init__.py b/sale_order_import_edifact/wizard/__init__.py new file mode 100644 index 0000000000..e0ddf6156f --- /dev/null +++ b/sale_order_import_edifact/wizard/__init__.py @@ -0,0 +1 @@ +from . import sale_order_import diff --git a/sale_order_import_edifact/wizard/sale_order_import.py b/sale_order_import_edifact/wizard/sale_order_import.py new file mode 100644 index 0000000000..3b597525a7 --- /dev/null +++ b/sale_order_import_edifact/wizard/sale_order_import.py @@ -0,0 +1,237 @@ +import json +import logging +import os +from base64 import b64decode +from collections import defaultdict + +from odoo import _, api, fields, models +from odoo.exceptions import UserError + +logger = logging.getLogger(__name__) + + +class SaleOrderImportEdifact(models.TransientModel): + _name = "sale.order.import" + _inherit = ["sale.order.import", "base.edifact"] + + state = fields.Selection( + selection_add=[("tech", "Technical")], ondelete={"tech": "set default"} + ) + parsed_json = fields.Text() + + @property + def edifact_ok(self): + conf_ext = self.env.context.get("file_ext", "txt,d96a") + extensions = conf_ext.split(",") + ok = False + if self.order_filename: + path, ext = os.path.splitext(self.order_filename) + ok = ext and ext[1:] in extensions + if not ok and self.order_file: + ok = b64decode(self.order_file[:4]) == b"UNB" + return ok + + @api.onchange("order_file") + def order_file_change(self): + if self.edifact_ok: + self.csv_import = False + self.doc_type = self.env.context.get("doc_type", "rfq") + self.price_source = "order" + else: + res = super(SaleOrderImportEdifact, self).order_file_change() + if isinstance(res, dict): + return res + + def parse_order_button(self): + self.ensure_one() + order_file_decoded = b64decode(self.order_file) + parsed_obj = dict(edifact=None, order=None) + if self.edifact_ok: + parsed_obj["edifact"] = self.pydifact_obj(order_file_decoded) + + parsed_order = self.parse_order( + order_file_decoded, self.order_filename, self.partner_id + ) + del parsed_order["attachments"] + parsed_obj["order"] = parsed_order + self.write( + { + "parsed_json": json.dumps(parsed_obj, indent=4, default=str), + "state": "tech", + } + ) + action = self.env["ir.actions.act_window"]._for_xml_id( + "sale_order_import.sale_order_import_action" + ) + action["res_id"] = self.id + return action + + # Parser hook + def _parse_file(self, filename, filecontent, detect_doc_type=False): + "Called from parse_order()" + parsed_order = super(SaleOrderImportEdifact, self)._parse_file( + filename, filecontent, detect_doc_type + ) + if not parsed_order and self.edifact_ok: + self.env.context.get("release", "d96a") + interchange = self._loads_edifact(filecontent) + parsed_order = self.parse_edifact_sale_order(interchange) + return parsed_order + + @api.model + def parse_edifact_sale_order(self, interchange): + # https://github.com/nerdocs/pydifact/blob/master/pydifact/segmentcollection.py + header = interchange.get_header_segment() + # > UNB segment: [['UNOA', '2'], ['5450534000000', '14'], + # ['8435337000003', '14'], ['230306', '0435'], '5506'] + + msg_type, msg_type_release = self._get_msg_type(interchange) + supported = ["ORDERS"] + if msg_type not in supported: + raise UserError(_("%s document is not a Sale Order document")) + + doc_type = self.env.context.get("doc_type", "order") + + bgm = interchange.get_segment("BGM") + # Customer PO number + # BGM segment: ['220', '1LP6WZGF', '9'] + order_ref = bgm[1] + + rd = { + "doc_type": doc_type, + # Customer PO number + "order_ref": order_ref, + "edi_ctx": {"sender": header[1], "recipient": header[2]}, # header[1][0] + } + parties = self._prepare_edifact_parties(interchange) + order_dict = { + **rd, + **self._prepare_edifact_dates(interchange), + **self._prepare_edifact_currencies(interchange), + **parties, + } + lines = self._prepare_edifact_lines(interchange) + if lines: + order_dict["lines"] = lines + return order_dict + + @api.model + def _prepare_edifact_parties(self, interchange): + references = self._prepare_edifact_references(interchange) + parties = self._prepare_edifact_name_and_address(interchange) + if references.get("vat") and parties.get("invoice_to"): + # just for check vat + if parties["invoice_to"].get("partner"): + parties["invoice_to"]["partner"]["rff_va"] = references["vat"] + if parties.get("invoice_to") and parties["invoice_to"].get("partner"): + newpartner = parties["invoice_to"]["partner"].copy() + if parties.get("partner") and parties["partner"].get("gln"): + # To see if NAD_BY is different NAD_IV + newpartner["gln_by"] = parties["partner"]["gln"] + parties["partner"] = newpartner + # add context information + for pval in parties.values(): + partner_dict = pval.get("partner", pval) + partner_dict["edi_ctx"] = { + "order_filename": self.order_filename, + "rff_va": references["vat"], + } + if parties.get("company"): + parties["company"]["edi_ctx"]["vendor_code"] = references.get("vendor_code") + return parties + + @api.model + def _prepare_edifact_dates(self, interchange): + dates = defaultdict(dict) + for seg in interchange.get_segments("DTM"): + date_meaning_code = seg[0][0] + if date_meaning_code == "137": + dates["date"] = self.map2odoo_date(seg[0]) + elif date_meaning_code == "63": + # latest delivery date + # dates.setdefault("delivery_detail",{}) + dates["delivery_detail"]["validity_date"] = self.map2odoo_date(seg[0]) + elif date_meaning_code == "64": + # earliest delivery date + dates["delivery_detail"]["commitment_date"] = self.map2odoo_date(seg[0]) + + return dates + + @api.model + def _prepare_edifact_references(self, interchange): + """ + RFF segment: [['CR', 'IK142']] + """ + refs = {} + for seg in interchange.get_segments("RFF"): + reference = seg[0] + reference_code = reference[0] + if reference_code == "ADE": + # ['firstorder','backorder','advantage','nyp'] + refs["account_reference"] = reference[1] + elif reference_code == "CR": + # Customer reference Number + refs["vendor_code"] = reference[1] + elif reference_code == "PD": + # Promotion Deal Number + # Number assigned by a vendor to a special promotion activity + refs["promotion_number"] = reference[1] + elif reference_code == "VA": + # Unique number assigned by the relevant tax authority to identify a + # party for use in relation to Value Added Tax (VAT). + refs["vat"] = reference[1] + + return refs + + @api.model + def _prepare_edifact_name_and_address(self, interchange): + nads = {} + for seg in interchange.get_segments("NAD"): + reference_code = seg[0] + if reference_code == "BY": + # NAD segment: ['BY', ['5450534001649', '', '9']] + # Customer (Buyer's GLN) + nads["partner"] = self.map2odoo_partner(seg) + elif reference_code == "SU": + # Our number of Supplier's GLN + # Can be used to check that we are not importing the order + # in the wrong company by mistake + nads["company"] = self.map2odoo_partner(seg) + elif reference_code == "DP": + # Delivery Party + nads["ship_to"] = self.map2odoo_address(seg) + elif reference_code == "IV": + # Invoice Party + nads["invoice_to"] = self.map2odoo_address(seg) + return nads + + @api.model + def _prepare_edifact_currencies(self, interchange): + currencies = {} + for seg in interchange.get_segments("CUX"): + usage_code = seg[0] + if usage_code == "2": + currencies["currency"] = self.map2odoo_currency(seg) + return currencies + + @api.model + def _prepare_edifact_lines(self, interchange): + lines = [] + zipsegments = zip( + interchange.get_segments("LIN"), + interchange.get_segments("QTY"), + interchange.get_segments("PRI"), + ) + + for linseg, qtyseg, priseg in zipsegments: + lines.append( + { + "sequence": int(linseg[0]), + "product": self.map2odoo_product(linseg), + "qty": self.map2odoo_qty(qtyseg), + # price without taxes + "price_unit": self.map2odoo_unit_price(priseg), + } + ) + + return lines diff --git a/sale_order_import_edifact/wizard/sale_order_import_view.xml b/sale_order_import_edifact/wizard/sale_order_import_view.xml new file mode 100644 index 0000000000..967599d65a --- /dev/null +++ b/sale_order_import_edifact/wizard/sale_order_import_view.xml @@ -0,0 +1,25 @@ + + + + sale.order.import.form.dev + sale.order.import + + +
+ + + +
+
+
+ +
+
+
diff --git a/setup/base_edifact/odoo/addons/base_edifact b/setup/base_edifact/odoo/addons/base_edifact new file mode 120000 index 0000000000..f632f1acc6 --- /dev/null +++ b/setup/base_edifact/odoo/addons/base_edifact @@ -0,0 +1 @@ +../../../../base_edifact \ No newline at end of file diff --git a/setup/base_edifact/setup.py b/setup/base_edifact/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/base_edifact/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/setup/sale_order_import_edifact/odoo/addons/sale_order_import_edifact b/setup/sale_order_import_edifact/odoo/addons/sale_order_import_edifact new file mode 120000 index 0000000000..59ca90b132 --- /dev/null +++ b/setup/sale_order_import_edifact/odoo/addons/sale_order_import_edifact @@ -0,0 +1 @@ +../../../../sale_order_import_edifact \ No newline at end of file diff --git a/setup/sale_order_import_edifact/setup.py b/setup/sale_order_import_edifact/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/sale_order_import_edifact/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) From 80a630691dd63969c45474636c0056f195e63fc6 Mon Sep 17 00:00:00 2001 From: Rafa Morant Date: Thu, 29 Jun 2023 17:27:38 +0200 Subject: [PATCH 2/2] [FIX] base_edifact: test chore --- .../tests/files/Retail_EDIFACT_ORDERS_sample1.txt | 0 .../tests/files/Retail_EDIFACT_ORDERS_sample2.txt | 0 base_edifact/tests/test_base_edifact.py | 12 ++++++++++++ sale_order_import_edifact/tests/common.py | 2 +- 4 files changed, 13 insertions(+), 1 deletion(-) rename {sale_order_import_edifact => base_edifact}/tests/files/Retail_EDIFACT_ORDERS_sample1.txt (100%) rename {sale_order_import_edifact => base_edifact}/tests/files/Retail_EDIFACT_ORDERS_sample2.txt (100%) diff --git a/sale_order_import_edifact/tests/files/Retail_EDIFACT_ORDERS_sample1.txt b/base_edifact/tests/files/Retail_EDIFACT_ORDERS_sample1.txt similarity index 100% rename from sale_order_import_edifact/tests/files/Retail_EDIFACT_ORDERS_sample1.txt rename to base_edifact/tests/files/Retail_EDIFACT_ORDERS_sample1.txt diff --git a/sale_order_import_edifact/tests/files/Retail_EDIFACT_ORDERS_sample2.txt b/base_edifact/tests/files/Retail_EDIFACT_ORDERS_sample2.txt similarity index 100% rename from sale_order_import_edifact/tests/files/Retail_EDIFACT_ORDERS_sample2.txt rename to base_edifact/tests/files/Retail_EDIFACT_ORDERS_sample2.txt diff --git a/base_edifact/tests/test_base_edifact.py b/base_edifact/tests/test_base_edifact.py index 11d99785fb..1eb3614d6c 100644 --- a/base_edifact/tests/test_base_edifact.py +++ b/base_edifact/tests/test_base_edifact.py @@ -3,6 +3,13 @@ from odoo.tests.common import TransactionCase +from odoo.tools import file_open + + +def _get_file_content(filename): + path = "base_edifact/tests/files/" + filename + with file_open(path, "rb") as fd: + return fd.read() class TestBaseEdifact(TransactionCase): @@ -21,6 +28,11 @@ def setUp(self): def tearDown(self): return super().tearDown() + def test_pydifact_obj(self): + edifact_docu = _get_file_content("Retail_EDIFACT_ORDERS_sample1.txt") + obj = self.base_edifact_model.pydifact_obj(edifact_docu) + self.assertEqual(obj["order"]["order_ref"], "1AA1TEST") + def test_map2odoo_address(self): """Address segment DP. Party to which goods should be delivered, if not identical with diff --git a/sale_order_import_edifact/tests/common.py b/sale_order_import_edifact/tests/common.py index 5a483c5e97..13beb601c9 100644 --- a/sale_order_import_edifact/tests/common.py +++ b/sale_order_import_edifact/tests/common.py @@ -10,7 +10,7 @@ def _get_file_content(filename): - path = "sale_order_import_edifact/tests/files/" + filename + path = "base_edifact/tests/files/" + filename with file_open(path, "rb") as fd: return fd.read()