Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[15.0] FWD port of multiple PRs #814

Closed
wants to merge 70 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
69d4d04
edi: fix consumer mixin test
simahawk Aug 19, 2022
b6507c3
edi: improve consumer mixin w/ origin
simahawk Aug 19, 2022
3298408
edi: add test for create child/ack
simahawk Aug 19, 2022
00f45ad
edi: add 'ack for' on type
simahawk Aug 19, 2022
65df162
edi: improve exc type search
simahawk Aug 19, 2022
6004b64
edi: fix ack record compute
simahawk Aug 22, 2022
b691e9c
edi: fix exchange ordering
simahawk Aug 22, 2022
7be31c4
edi: fix record and type copy on fields
simahawk Aug 25, 2022
d3f229f
edi: fix error msg typo
simahawk Aug 27, 2022
b4041e1
edi: add exc.type.set_settings method
simahawk Aug 27, 2022
6ad8b26
edi: improve chatter msg w/ type detail
simahawk Aug 27, 2022
d5dea74
edi_exchange_template: improve time utils on render ctx
simahawk Aug 25, 2022
009e74b
edi: fix _cron_check_output_exchange_sync
simahawk Aug 28, 2022
d772bc5
edi: fix backward compat usage of _has_exchange_record_domain
simahawk Sep 5, 2022
f948c6a
edi: allow search consumers by exc type
simahawk Sep 2, 2022
5e532c6
edi: fix action_view_edi_records
simahawk Sep 2, 2022
939997f
edi: improve consumer record count perf
simahawk Sep 2, 2022
ce22980
edi: fix record missing indexes
simahawk Sep 2, 2022
f46dcd8
edi: imp backend check input/output
simahawk Sep 2, 2022
ed0d586
edi: improve cron names
simahawk Sep 2, 2022
3efaa1e
edi: exchange type add TODO
simahawk Sep 5, 2022
3987fb5
edi: add test for exc.record.action_retry
simahawk Sep 2, 2022
491d19b
edi: fix exc.record._compute_retryable
simahawk Sep 2, 2022
9847e98
edi: add quick exec option by type
simahawk Sep 2, 2022
fc2d172
edi_storage: adapt _check_output_exchange_sync override
simahawk Sep 6, 2022
af9c347
edi: drop ack record auto create
simahawk Sep 16, 2022
94cc74b
edi: fix _get_component ctx propagation
simahawk Oct 5, 2022
e48264b
edi: add 'as_bytes' option to _get_file_content
simahawk Oct 3, 2022
5f76400
edi_oca: avoid backend mismatch
florentx May 16, 2023
a345ab2
edi_oca: avoid ghost exchange records
florentx May 16, 2023
f3dd0cc
edi_oca: log warning for deleted records
florentx May 17, 2023
1fe8c90
edi_oca: assertion was not executed
florentx May 17, 2023
97b820e
edi: unify action complete notification
simahawk May 17, 2023
d7fd2b2
edi: trigger generic event on action complete
simahawk May 17, 2023
7b692a7
edi: trigger generic event on related record
simahawk May 18, 2023
d9fba11
edi: mark every session w/ 'edi_framework' ctx key
simahawk May 18, 2023
ebe0754
edi: exc.record._set_related_record use sudo
simahawk May 19, 2023
6fd0452
edi_exchange_template: partial fix for ctx propagation
simahawk May 19, 2023
64472f8
edi: speed up exchange record views
simahawk May 22, 2023
2ca168f
edi: add 'active' field to exchange type
simahawk May 24, 2023
6b2315f
edi: improve backend view filter inactive
simahawk May 24, 2023
c6e3e9e
edi: fix related record missing broken views
simahawk May 29, 2023
208e736
edi: add disable flag to consumer
simahawk May 26, 2023
d01de92
edi: allow enable/disable exc type by partner
simahawk May 29, 2023
6ace1a7
edi: refactor model rules w/ specific model
simahawk Jul 4, 2023
75bc1b9
edi: unify menu item labels
simahawk Jul 4, 2023
defccec
edi: allow form btn actions customization
simahawk Jul 4, 2023
5932943
edi: refactor model rules backward compat
simahawk Aug 9, 2023
20c52d8
edi_oca: bump 15.0.1.6.0
etobella Sep 15, 2023
e645ba9
edi_oca: fix consumer mixin exchange record count
petrus-v Jun 23, 2023
7e35558
edi_oca: avoid duplicate field name
petrus-v Aug 31, 2023
de3c606
edi_webservice: add generic send component
simahawk Aug 26, 2022
20f300e
edi_webservice: allow to send bytes
simahawk Oct 3, 2022
d98201e
edi_exchange_template_oca: add nswrapper test
simahawk Aug 9, 2022
1f4e304
edi_exchange_template_oca: fix xml_purge_nswrapper
simahawk Jul 28, 2022
b27f23a
edi_exchange_template_oca: update ownership
simahawk Aug 9, 2022
5bbfd1d
edi_exchange_template: add prettify option
simahawk Dec 1, 2022
bacaf6f
edi_exchange_template: add first_of helper
simahawk Sep 14, 2022
410e6f2
edi_exchange_template: drop useless logger
simahawk Dec 2, 2022
b3f35d5
Add edi_exchange_template_party_data
simahawk Dec 2, 2022
e42b719
edi_exchange_template: fix _get_render_values
simahawk Dec 6, 2022
00e4c91
edi_exchange_template_party_data: fix _get_render_values call
simahawk Dec 6, 2022
f093def
[FIX] edi_enpoint_oca: is not in 15, some error happened here...
etobella Sep 15, 2023
30f7dcd
[IMP] edi_storage_oca: Delete processed files if you want it
etobella Feb 7, 2023
fc727fb
[FIX] edi_webservice_oca: Adapt to 15.0
etobella Sep 15, 2023
f189b16
[MIG] edi_exchange_template_party_data: Migrate to 15.0
etobella Sep 15, 2023
522da7f
Add edi_party_data_oca
simahawk Sep 7, 2022
93be20c
edi_party_data: use display_name by default
simahawk Dec 5, 2022
7b1aeeb
[MIG] edi_party_oca: Migrate to 15.0
etobella Sep 15, 2023
d13d6f6
oca-port: blacklist PR(s) for edi_oca
etobella Sep 22, 2023
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
28 changes: 28 additions & 0 deletions .oca/oca-port/blacklist/edi_oca.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"pull_requests": {
"OCA/639": "Nothing to port from PR #OCA/639",
"OCA/651": "Nothing to port from PR #OCA/651",
"OCA/652": "Nothing to port from PR #OCA/652",
"OCA/653": "Nothing to port from PR #OCA/653",
"OCA/645": "Nothing to port from PR #OCA/645",
"OCA/648": "Nothing to port from PR #OCA/648",
"OCA/662": "Nothing to port from PR #OCA/662",
"OCA/666": "Nothing to port from PR #OCA/666",
"OCA/672": "Nothing to port from PR #OCA/672",
"OCA/694": "Nothing to port from PR #OCA/694",
"OCA/696": "Nothing to port from PR #OCA/696",
"OCA/697": "Nothing to port from PR #OCA/697",
"OCA/698": "Nothing to port from PR #OCA/698",
"OCA/721": "Nothing to port from PR #OCA/721",
"OCA/762": "Nothing to port from PR #OCA/762",
"OCA/764": "Nothing to port from PR #OCA/764",
"OCA/763": "Nothing to port from PR #OCA/763",
"OCA/765": "Nothing to port from PR #OCA/765",
"OCA/767": "Nothing to port from PR #OCA/767",
"OCA/774": "Nothing to port from PR #OCA/774",
"OCA/778": "Nothing to port from PR #OCA/778",
"OCA/797": "Nothing to port from PR #OCA/797",
"OCA/790": "Nothing to port from PR #OCA/790",
"OCA/808": "Nothing to port from PR #OCA/808"
}
}
37 changes: 0 additions & 37 deletions edi_endpoint_oca/models/edi_backend.py

This file was deleted.

6 changes: 3 additions & 3 deletions edi_exchange_template_oca/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Copyright 2020 ACSONE
# @author: Simone Orsi <[email protected]>
# Copyright 2022 Camptocamp SA
# @author Simone Orsi <[email protected]>
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

{
"name": "EDI Exchange Template",
"summary": """Allows definition of exchanges via templates.""",
"version": "15.0.1.0.1",
"development_status": "Beta",
"license": "LGPL-3",
"author": "ACSONE,Odoo Community Association (OCA)",
"author": "ACSONE,Camptocamp,Odoo Community Association (OCA)",
"maintainers": ["simahawk"],
"website": "https://github.com/OCA/edi",
"depends": ["edi_oca", "component"],
Expand Down
6 changes: 6 additions & 0 deletions edi_exchange_template_oca/models/edi_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ def _exchange_generate(self, exchange_record, **kw):
# Template take precedence over component lookup
tmpl = self._get_output_template(exchange_record)
if tmpl:
# FIXME: env_ctx is not propagated here because we bypass components completly.
# It would be better to move this machinery inside a `generate` component.
exchange_record = exchange_record.with_context(
edi_framework_action="generate"
)
tmpl = tmpl.with_context(edi_framework_action="generate")
return tmpl.exchange_generate(exchange_record, **kw)
return super()._exchange_generate(exchange_record, **kw)

Expand Down
42 changes: 38 additions & 4 deletions edi_exchange_template_oca/models/edi_exchange_template_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,19 @@
_logger = logging.getLogger(__name__)


def date_to_datetime(dt):
"""Convert date to datetime."""
if isinstance(dt, datetime.date):
return datetime.datetime.combine(dt, datetime.datetime.min.time())
return dt

Check warning on line 20 in edi_exchange_template_oca/models/edi_exchange_template_mixin.py

View check run for this annotation

Codecov / codecov/patch

edi_exchange_template_oca/models/edi_exchange_template_mixin.py#L19-L20

Added lines #L19 - L20 were not covered by tests


def to_utc(dt):
"""Convert date or datetime to UTC."""
# Gracefully convert to datetime if needed 1st
return date_to_datetime(dt).astimezone(pytz.UTC)

Check warning on line 26 in edi_exchange_template_oca/models/edi_exchange_template_mixin.py

View check run for this annotation

Codecov / codecov/patch

edi_exchange_template_oca/models/edi_exchange_template_mixin.py#L26

Added line #L26 was not covered by tests


class EDIExchangeTemplateMixin(models.AbstractModel):
"""Define a common ground for EDI exchange templates."""

Expand Down Expand Up @@ -77,22 +90,43 @@

@staticmethod
def _date_to_string(dt, utc=True):
if not dt:
return ""

Check warning on line 94 in edi_exchange_template_oca/models/edi_exchange_template_mixin.py

View check run for this annotation

Codecov / codecov/patch

edi_exchange_template_oca/models/edi_exchange_template_mixin.py#L94

Added line #L94 was not covered by tests
if utc:
dt = dt.astimezone(pytz.UTC)
dt = to_utc(dt)

Check warning on line 96 in edi_exchange_template_oca/models/edi_exchange_template_mixin.py

View check run for this annotation

Codecov / codecov/patch

edi_exchange_template_oca/models/edi_exchange_template_mixin.py#L96

Added line #L96 was not covered by tests
return fields.Date.to_string(dt)

@staticmethod
def _datetime_to_string(dt, utc=True):
if not dt:
return ""

Check warning on line 102 in edi_exchange_template_oca/models/edi_exchange_template_mixin.py

View check run for this annotation

Codecov / codecov/patch

edi_exchange_template_oca/models/edi_exchange_template_mixin.py#L102

Added line #L102 was not covered by tests
if utc:
dt = to_utc(dt)
return fields.Datetime.to_string(dt)

Check warning on line 105 in edi_exchange_template_oca/models/edi_exchange_template_mixin.py

View check run for this annotation

Codecov / codecov/patch

edi_exchange_template_oca/models/edi_exchange_template_mixin.py#L104-L105

Added lines #L104 - L105 were not covered by tests

def _get_code_snippet_eval_context(self):
"""Prepare the context used when evaluating python code

:returns: dict -- evaluation context given to safe_eval
"""
ctx = {
"uid": self.env.uid,
"user": self.env.user,
"DotDict": DotDict,
}
ctx.update(self._time_utils())
return ctx

def _time_utils(self):
return {
"datetime": safe_eval.datetime,
"dateutil": safe_eval.dateutil,
"time": safe_eval.time,
"uid": self.env.uid,
"user": self.env.user,
"DotDict": DotDict,
"utc_now": self._utc_now,
"date_to_string": self._date_to_string,
"datetime_to_string": self._datetime_to_string,
"time_to_string": lambda dt: dt.strftime("%H:%M:%S") if dt else "",
"first_of": fields.first,
}

def _evaluate_code_snippet(self, **render_values):
Expand Down
17 changes: 10 additions & 7 deletions edi_exchange_template_oca/models/edi_exchange_template_output.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
# Copyright 2020 ACSONE SA
# @author Simone Orsi <[email protected]>
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
import logging
import lxml.etree as etree

from odoo import fields, models

from ..utils import xml_purge_nswrapper

_logger = logging.getLogger(__name__)


class EDIExchangeOutputTemplate(models.Model):
"""Define an output template to generate outgoing records' content."""
Expand Down Expand Up @@ -49,6 +47,7 @@ class EDIExchangeOutputTemplate(models.Model):
readonly=False,
)
template_key = fields.Char(related="template_id.xml_id", string="Template key")
prettify = fields.Boolean(help="Prettify output. Works for XML output only.")

def _default_code_snippet_docs(self):
return (
Expand Down Expand Up @@ -94,14 +93,13 @@ def _get_render_values(self, exchange_record, **kw):
"record": exchange_record.record,
"backend": exchange_record.backend_id,
"template": self,
"utc_now": self._utc_now,
"date_to_string": self._date_to_string,
"render_edi_template": self._render_template,
"get_info_provider": self._get_info_provider,
"info": {},
}
values.update(self._evaluate_code_snippet(**values))
values.update(kw)
values.update(self._time_utils())
values.update(self._evaluate_code_snippet(**values))
return values

def _render_template(self, exchange_record, code, **kw):
Expand All @@ -117,9 +115,14 @@ def _post_process_output(self, output):
"""Post process generated output."""
if self.output_type == "xml":
# TODO: lookup for components to handle this dynamically
return xml_purge_nswrapper(output)
output = xml_purge_nswrapper(output)
if self.prettify:
output = self._prettify_xml(output)
return output

def _prettify_xml(self, xml_string):
return etree.tostring(etree.fromstring(xml_string), pretty_print=True)

def _get_info_provider(self, exchange_record, work_ctx=None, usage=None, **kw):
"""Retrieve component providing info to render a template.

Expand Down
1 change: 1 addition & 0 deletions edi_exchange_template_oca/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from . import test_edi_backend_output
from . import test_nswrapper
10 changes: 10 additions & 0 deletions edi_exchange_template_oca/tests/test_edi_backend_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,16 @@ def test_generate_file(self):
self.assertEqual(doc.getchildren()[1].text, "2")
self.assertEqual(doc.getchildren()[1].attrib, {"bit": "custom_var"})

def test_prettify(self):
self.tmpl_out2.template_id.arch = (
'<t t-name="edi_exchange.test_output2"><root><a>1</a></root></t>'
)
result = self.tmpl_out2.exchange_generate(self.record2)
self.assertEqual(result, b"<root><a>1</a></root>")
self.tmpl_out2.prettify = True
result = self.tmpl_out2.exchange_generate(self.record2)
self.assertEqual(result, b"<root>\n <a>1</a>\n</root>\n")

def test_generate_file_report(self):
output = self.backend.exchange_generate(self.record3)
self.assertTrue(output)
Expand Down
58 changes: 58 additions & 0 deletions edi_exchange_template_oca/tests/test_nswrapper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Copyright 2022 Camptocamp SA
# @author Simone Orsi <[email protected]>
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
from odoo.tests.common import SavepointCase
from odoo.tools import pycompat

from ..utils import xml_purge_nswrapper

ORDER_RESP_WRAPPER_TMPL = """
<OrderResponse
xmlns="urn:oasis:names:specification:ubl:schema:xsd:OrderResponse-2"
xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"
xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"
>
<cbc:UBLVersionID>2.2</cbc:UBLVersionID>
{}
</OrderResponse>
"""

XML1 = """
<nswrapper xmlns:foo="http://www.unece.org/cefact/Foo">
<foo:LovelyNamespacedElement />
</nswrapper>
"""

XML2 = """
<nswrapper
xmlns="urn:oasis:names:specification:ubl:schema:xsd:OrderResponse-2"
xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"
xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"
>
<cac:Party>
<cbc:EndpointID>7302347231111</cbc:EndpointID>
<cac:PartyIdentification>
<cbc:ID>7300070011115</cbc:ID>
</cac:PartyIdentification>
<cac:PartyName>
<cbc:Name>Moderna Produkter AB</cbc:Name>
</cac:PartyName>
</cac:Party>
</nswrapper>
"""


class TestNSWrapper(SavepointCase):
maxDiff = None

def test_purge1(self):
res = xml_purge_nswrapper(XML1)
self.assertNotIn("nswrapper", pycompat.to_text(res))

def test_purge2(self):
res = xml_purge_nswrapper(XML2)
self.assertNotIn("nswrapper", pycompat.to_text(res))

def test_purge3(self):
res = xml_purge_nswrapper(ORDER_RESP_WRAPPER_TMPL.format(XML2))
self.assertNotIn("nswrapper", pycompat.to_text(res))
10 changes: 8 additions & 2 deletions edi_exchange_template_oca/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Copyright 2020 ACSONE SA/NV
# Copyright 2022 Camptocamp SA
# @author Simone Orsi <[email protected]>
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

from lxml import etree

from odoo.tools import pycompat
Expand Down Expand Up @@ -25,8 +30,9 @@ def xml_purge_nswrapper(xml_content):
if not (xml_content and xml_content.strip()):
return xml_content
root = etree.XML(xml_content)
# deeper elements come after, keep the root element at the end (if any)
for nswrapper in reversed(root.xpath("//nswrapper")):
# Deeper elements come after, keep the root element at the end (if any).
# Use `name()` because the real element could be namespaced on render.
for nswrapper in reversed(root.xpath("//*[name() = 'nswrapper']")):
parent = nswrapper.getparent()
if parent is None:
# fmt:off
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
<field name="code" />
<field name="output_type" />
<field name="generator" />
<field
name="prettify"
attrs="{'invisible': [('generator', '!=', 'qweb')]}"
/>
<field
name="template_id"
attrs="{'required': [('generator', '=', 'qweb')], 'invisible': [('generator', '!=', 'qweb')]}"
Expand Down
1 change: 1 addition & 0 deletions edi_exchange_template_party_data/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
wait for da bot
1 change: 1 addition & 0 deletions edi_exchange_template_party_data/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
15 changes: 15 additions & 0 deletions edi_exchange_template_party_data/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2022 Camptocamp SA
# @author Simone Orsi <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
{
"name": "EDI Exchange Template - Party data",
"summary": """Glue module betweeb edi_exchange_template and edi_party_data""",
"version": "15.0.1.0.0",
"development_status": "Alpha",
"license": "AGPL-3",
"author": "Camptocamp,Odoo Community Association (OCA)",
"maintainers": ["simahawk"],
"website": "https://github.com/OCA/edi",
"depends": ["edi_exchange_template_oca", "edi_party_data_oca"],
"auto_install": True,
}
1 change: 1 addition & 0 deletions edi_exchange_template_party_data/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import edi_exchange_template_output
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2022 Camptocamp SA
# @author Simone Orsi <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

from odoo import _, exceptions, models

from odoo.addons.edi_party_data_oca.utils import get_party_data_component


class EDIExchangeOutputTemplate(models.Model):
"""Define an output template to generate outgoing records' content."""

_inherit = "edi.exchange.template.output"

def _get_render_values(self, exchange_record, **kw):
kw["get_party_data"] = self._get_party_data
return super()._get_render_values(exchange_record, **kw)

Check warning on line 17 in edi_exchange_template_party_data/models/edi_exchange_template_output.py

View check run for this annotation

Codecov / codecov/patch

edi_exchange_template_party_data/models/edi_exchange_template_output.py#L16-L17

Added lines #L16 - L17 were not covered by tests

def _get_party_data(self, exchange_record, partner, raise_if_not_found=True):
"""Shortcut to lookup an info provider for parties."""
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"))

Check warning on line 23 in edi_exchange_template_party_data/models/edi_exchange_template_output.py

View check run for this annotation

Codecov / codecov/patch

edi_exchange_template_party_data/models/edi_exchange_template_output.py#L23

Added line #L23 was not covered by tests
return provider.get_party() if provider else None
1 change: 1 addition & 0 deletions edi_exchange_template_party_data/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Simone Orsi <[email protected]>
4 changes: 4 additions & 0 deletions edi_exchange_template_party_data/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
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.
1 change: 1 addition & 0 deletions edi_exchange_template_party_data/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_output_tmpl
Loading
Loading