Skip to content
Open
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
7 changes: 7 additions & 0 deletions edi_exchange_template_party_data/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ Glue module betweeb edi_exchange_template and edi_party_data.
Exposes a get_party_data function to the rendering context of the
template. This way you can retrieve party data on the fly.

**Deprecated**: `edi_party_data_oca` (and this glue module) are superseded
by `edi_party_helper_oca`, which has no dependency on the `component`
framework. Use its `edi.party.helper` model (or the `EDIParty` class
directly) instead of the `get_party_data` render context shortcut. A
deprecation notice is logged on server startup while this module is
installed. It is also no longer auto-installed.

.. 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.
Expand Down
1 change: 1 addition & 0 deletions edi_exchange_template_party_data/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from . import models
from .hooks import post_load_hook
2 changes: 1 addition & 1 deletion edi_exchange_template_party_data/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
"maintainers": ["simahawk"],
"website": "https://github.com/OCA/edi-framework",
"depends": ["edi_exchange_template_oca", "edi_party_data_oca"],
"auto_install": True,
"post_load_hook": "post_load_hook",
}
13 changes: 13 additions & 0 deletions edi_exchange_template_party_data/hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import logging

_logger = logging.getLogger(__name__)


def post_load_hook():
_logger.info(
Comment thread
simahawk marked this conversation as resolved.
"`edi_exchange_template_party_data` is deprecated and will be removed. "
"`edi_party_data_oca` (and this glue module) are superseded by "
"`edi_party_helper_oca`: use its `edi.party.helper` model (or the "
"`EDIParty` class directly) instead of the `get_party_data` render "
"context shortcut."
)
7 changes: 7 additions & 0 deletions edi_exchange_template_party_data/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,10 @@ Glue module betweeb edi_exchange_template and edi_party_data.

Exposes a get_party_data function to the rendering context of the
template. This way you can retrieve party data on the fly.

**Deprecated**: `edi_party_data_oca` (and this glue module) are superseded
by `edi_party_helper_oca`, which has no dependency on the `component`
framework. Use its `edi.party.helper` model (or the `EDIParty` class
directly) instead of the `get_party_data` render context shortcut. A
deprecation notice is logged on server startup while this module is
installed. It is also no longer auto-installed.
11 changes: 6 additions & 5 deletions edi_party_data_oca/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,12 @@ of an exchange.
This module provides default component and a mixin to be used for
registering new components for specific backends.

It's based on partner_identification so that the party information will
include allowed ID numbers for a given exchange.

You can configure which ID number categories are allowed on the exchange
type.
**Deprecated**: the actual party data lookup logic has moved to
`edi_party_helper_oca`, which has no dependency on the `component`
framework. This module now only wraps it in a component for backward
compatibility and will be removed once its usages are ported over. A
deprecation notice is logged on server startup while this module is
installed.

.. IMPORTANT::
This is an alpha version, the data model and design can change at any time without warning.
Expand Down
2 changes: 1 addition & 1 deletion edi_party_data_oca/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from . import components
from . import models
from .hooks import post_load_hook
6 changes: 2 additions & 4 deletions edi_party_data_oca/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
"website": "https://github.com/OCA/edi-framework",
"author": "Camptocamp, Odoo Community Association (OCA)",
"maintainers": ["simahawk"],
"depends": ["edi_component_oca", "partner_identification"],
"data": [
"views/edi_exchange_type_views.xml",
],
"depends": ["edi_component_oca", "edi_party_helper_oca"],
"post_load_hook": "post_load_hook",
}
73 changes: 20 additions & 53 deletions edi_party_data_oca/components/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@
# @author: Simone Orsi <simahawk@gmail.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo.tools import DotDict

from odoo.addons.component.core import AbstractComponent


class EDIExchangePartyDataMixin(AbstractComponent):
"""Abstract component mixin provide partner data for exchanges."""
"""Abstract component mixin provide partner data for exchanges.

.. deprecated::
Business logic lives in the `edi_party_helper_oca` module, which has
no component dependency: `EDIParty` (plain dataclass) or the
`edi.party.helper` abstract model. This component only wraps it for
backward compatibility and will be dropped once its usages are
ported over.
"""

_name = "edi.party.data.mixin"
_inherit = "edi.component.mixin"
Expand All @@ -25,59 +31,20 @@ def _get_partner(self):
# based on current partner (eg: pick the parent).
return self.work.partner

def _get_party(self):
return self.env["edi.party.helper"].get_party(
self.exchange_record,
self.partner,
name_field=getattr(self.work, "party_data_name_field", "name"),
lang_code=getattr(self.work, "lang", False),
)

def get_party(self):
"""Return party information.

Requires a res.partner to be passed via work context.

:return: odoo.tools.DotDict
:return: `EDIParty` (behaves like a read-only dict too, for
backward compatibility with the old ``DotDict``-based return)
"""
return self._party_from_partner()

def _party_from_partner(self, **kw):
# NB: for UBL this should probably replace
# `base.ubl._ubl_get_party_identification` which does nothing today.
party = DotDict(
name=self._get_name(),
identifiers=self._get_identifiers(),
endpoint=self._get_endpoint(),
lang=self._get_lang(),
partner=self.partner,
)
party.update(kw)
return party

def _get_name(self):
name_field = getattr(self.work, "party_data_name_field", "name")
return self.partner[name_field]

def _get_endpoint(self):
return {}

def _get_identifiers(self):
identifiers = self.partner.id_numbers.filtered(
lambda x: self._filter_id_number(x)
)
return [self._get_indentity(x) for x in identifiers]

def _filter_id_number(self, id_number):
if self.allowed_id_categories:
return id_number.category_id in self.allowed_id_categories
return True

def _get_indentity(self, id_number):
return DotDict(
attrs={
"schemeID": id_number.category_id.code,
},
value=id_number.name,
)

def _get_lang(self):
lang_code = getattr(self.work, "lang", False) or self.partner.lang
if not lang_code:
return False
lang = self.env["res.lang"]._get_data(code=lang_code)
if not lang:
return False
return {"name": lang.name, "code": lang.code, "short": lang.code.split("_")[0]}
return self._get_party()
13 changes: 13 additions & 0 deletions edi_party_data_oca/hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import logging

_logger = logging.getLogger(__name__)


def post_load_hook():
_logger.info(
Comment thread
simahawk marked this conversation as resolved.
"`edi_party_data_oca` is deprecated and will be removed. Its "
"`edi.party.data.mixin` component is superseded by "
"`edi_party_helper_oca`: use its `edi.party.helper` model (or the "
"`EDIParty` class directly) instead, they don't require any "
"component lookup."
)
5 changes: 1 addition & 4 deletions edi_party_data_oca/readme/CONFIGURE.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
## ID numbers selection

On the exchange type form, find the field "ID categories" and set the
categories allowed for that exchange type.

If not set, *all the IDs* of the partner will be exposed.
See `edi_party_helper_oca`'s configuration.

## Name field

Expand Down
11 changes: 6 additions & 5 deletions edi_party_data_oca/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ of an exchange.
This module provides default component and a mixin to be used for
registering new components for specific backends.

It's based on partner_identification so that the party information will
include allowed ID numbers for a given exchange.

You can configure which ID number categories are allowed on the exchange
type.
**Deprecated**: the actual party data lookup logic has moved to
`edi_party_helper_oca`, which has no dependency on the `component`
framework. This module now only wraps it in a component for backward
compatibility and will be removed once its usages are ported over. A
deprecation notice is logged on server startup while this module is
installed.
3 changes: 3 additions & 0 deletions edi_party_data_oca/readme/USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ An handy util method is to retrive the component:
component = get_party_data_component(exchange_record, partner)

data = component.get_party()

**Deprecated**: prefer `edi_party_helper_oca`'s `edi.party.helper` model or
its `EDIParty` class directly, they don't require any component lookup.
84 changes: 84 additions & 0 deletions edi_party_data_oca/tests/common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# Copyright 2022 Camptocamp SA
# @author: Simone Orsi <simahawk@gmail.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo.addons.edi_component_oca.tests.common import EDIBackendCommonComponentTestCase


class PartyDataCommonTestCase(EDIBackendCommonComponentTestCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.backend = cls.env.ref("edi_core_oca.demo_edi_backend")
cls.cat_model = cls.env["res.partner.id_category"]
cls.all_cat = cls.cat_model.browse()
for i in range(1, 4):
rec = cls.cat_model.create({"code": f"cat{i}", "name": f"Cat {i}"})
cls.all_cat += rec
setattr(cls, f"category{i}", rec)

parent = cls.env["res.partner"].create(
{
"name": "ACME inc",
"is_company": True,
}
)

for i in range(1, 4):
rec = cls.env["res.partner"].create(
{
"name": f"Test Partner {i}",
"parent_id": parent.id,
"id_numbers": [
(
0,
0,
{
"name": f"{cat.code}-p{i}",
"category_id": cat.id,
},
)
for cat in cls.all_cat[i - 1 :]
],
}
)
setattr(cls, f"partner{i}", rec)

# No need for special file name gen
cls.exc_type = cls._create_exchange_type(
name="ID output test",
code="id_out_test",
direction="output",
)
cls.exc_record = cls.backend.create_record("id_out_test", {})

def _expected_lang(self, partner):
if not partner.lang:
return False
lang = self.env["res.lang"]._get_data(code=partner.lang)
if not lang:
return False
return {"name": lang.name, "code": lang.code, "short": lang.code.split("_")[0]}

def _make_expected_data(
self, partner, number, allowed_codes=None, name_field="name", **kw
):
data = {
"name": partner[name_field],
"identifiers": [
{"attrs": {"schemeID": "cat1"}, "value": f"cat1-p{number}"},
{"attrs": {"schemeID": "cat2"}, "value": f"cat2-p{number}"},
{"attrs": {"schemeID": "cat3"}, "value": f"cat3-p{number}"},
],
"endpoint": {},
"lang": self._expected_lang(partner),
"partner": partner,
}
data.update(kw)
if allowed_codes:
data["identifiers"] = [
x
for x in data["identifiers"]
if x["attrs"]["schemeID"] in allowed_codes
]
return data
Loading
Loading