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

[14.0][ADD] edi_sale_ubl_oca #1024

Open
wants to merge 35 commits into
base: 14.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
29f1353
Add edi_sale_ubl_oca
simahawk Aug 14, 2022
184b12a
edi_sale_ubl: improve order response data
simahawk Sep 14, 2022
a9d7838
edi_sale_ubl_oca: make exc type demo FIXME
simahawk Nov 15, 2022
c57f8ba
edi_sale_ubl_oca: depend on party data
simahawk Dec 6, 2022
7f6c355
edi_sale_ubl_oca: move data to demo
simahawk Dec 6, 2022
ceb5e45
edi_sale_ubl_oca: imp OrderResponse data
simahawk Dec 6, 2022
7280800
edi_sale_ubl_oca: fix tests
simahawk Dec 6, 2022
cf82851
edi_sale_ubl: ease data override via info
simahawk Dec 17, 2022
98c1f0a
edi_sale_ubl: fix demo data
simahawk May 19, 2023
b16b3e2
edi_sale_ubl: introduce states
simahawk May 19, 2023
8e8a245
edi_sale_ubl: improve tests common
simahawk May 19, 2023
8ead28f
edi_sale: add edi_exchange_ready
simahawk May 23, 2023
05af9d1
edi_sale_ubl: fix state mapping
simahawk May 24, 2023
aafa463
edi_sale_ubl: fix order state handling
simahawk May 26, 2023
88b25b3
edi_sale_ubl: do not use Form for tests
simahawk May 26, 2023
8566af7
edi_sale_ubl: fix state update
simahawk May 26, 2023
e3d10f0
edi_sale_ubl: improve line state test
simahawk Jun 22, 2023
f81af10
edi_sale_ubl: trigger state update on line create/write
simahawk Jun 23, 2023
8c5e644
edi_sale_ubl: fix line state compute
simahawk Jul 3, 2023
7c438fc
edi_sale_ubl: fix order state compute
simahawk Jul 3, 2023
553de98
edi_sale_ubl: adapt to type rule
simahawk Jul 6, 2023
914e6ef
edi_sale_ubl: make state readonly
simahawk Jul 6, 2023
e6e427f
edi_sale_ubl: fix line state compute
simahawk Jul 6, 2023
427759e
edi_sale_ubl: fix tests order setup
simahawk Jul 6, 2023
f793740
edi_sale_ubl: fix line state compute on order create
simahawk Jul 10, 2023
d588bcc
edi_sale_ubl: fix ordrsp tmpl
simahawk Jul 10, 2023
82c47e0
edi_sale_ubl: fix line state for qty=0
simahawk Jul 10, 2023
a4bcfa2
edi_sale_ubl: fix tests, handle increased qty
simahawk Jul 31, 2023
4e5e1a7
edi_sale: move OrderMixin from edi_sale_ubl
simahawk Aug 7, 2023
698c653
[IMP] edi_sale_ubl_oca: add more decorator on create method
May 23, 2024
817df32
test-requirements.txt: depend on edi.config
simahawk Nov 14, 2024
43bfc5a
edi_sale_ubl_oca: use edi.config
simahawk Nov 14, 2024
821a063
fixup! edi_sale_ubl_oca: use edi.config
simahawk Nov 15, 2024
f6fbc45
fixup! fixup! edi_sale_ubl_oca: use edi.config
simahawk Nov 15, 2024
ffb2719
fixup! fixup! fixup! edi_sale_ubl_oca: use edi.config
simahawk Nov 15, 2024
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
1 change: 1 addition & 0 deletions edi_sale_ubl_oca/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bot, please, take care of this!
2 changes: 2 additions & 0 deletions edi_sale_ubl_oca/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import components
from . import models
37 changes: 37 additions & 0 deletions edi_sale_ubl_oca/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Copyright 2022 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
"name": "EDI Sales",
"summary": """
Configuration and special behaviors for EDI on sales.
""",
"version": "14.0.1.0.0",
"development_status": "Alpha",
"license": "AGPL-3",
"author": "Camptocamp,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/edi",
"depends": [
"sale_order_import_ubl",
"edi_sale_oca",
"edi_ubl_oca",
"edi_xml_oca",
"edi_exchange_template_oca",
"edi_exchange_template_party_data",
"edi_state_oca",
# This could be made optional
# but the delivery part would need another source of data
"sale_stock",
],
"data": [
"data/edi_state.xml",
"templates/qweb_tmpl_party.xml",
"templates/qweb_tmpl_order_response.xml",
"views/sale_order.xml",
],
"demo": [
"demo/edi_exchange_type.xml",
"demo/edi_configuration.xml",
"demo/exc_templ_order_response.xml",
],
}
1 change: 1 addition & 0 deletions edi_sale_ubl_oca/components/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import listeners
106 changes: 106 additions & 0 deletions edi_sale_ubl_oca/components/listeners.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# Copyright 2023 Camptocamp SA
# @author: Simone Orsi <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

import logging

from odoo.addons.component.core import AbstractComponent, Component

_logger = logging.getLogger(__file__)


class EDISOEventListenerMixin(AbstractComponent):
_name = "edi.sale.order.event.listener.mixin"
_inherit = "base.event.listener"
_apply_on = ["sale.order", "sale.order.line"]

def on_record_create(self, record, fields=None):
self._on_record_operation(record, fields=fields, operation="create")

def on_record_write(self, record, fields=None):
self._on_record_operation(record, fields=fields, operation="write")

def _on_record_operation(self, record, fields=None, operation=None):
if self._skip_state_update(record, fields=fields, operation=operation):
return
order, lines = self._get_records(record)
order = order.with_context(edi_sale_skip_state_update=True)
lines = lines.with_context(edi_sale_skip_state_update=True)
self._handle_order_state(order, lines=lines)

# TODO: what to do?
# def on_record_unlink(self, record):

def _get_records(self, record):
raise NotImplementedError()

def _handle_order_state(self, order, lines=None):
state = order._edi_update_state(lines=lines)
if not state:
self._handle_order_state_no_state(order)

def _skip_state_update(self, record, fields=None, operation=None):
if record.env.context.get(
"edi_sale_skip_state_update"
) or not self._is_ubl_exchange(record):
return True
return False

def _is_ubl_exchange(self, record):
return record.origin_exchange_type_id.backend_type_id == self.env.ref(
"edi_ubl_oca.edi_backend_type_ubl"
)

def _handle_order_state_no_state(self, order):
msg = "Cannot determine EDI state for order %(order_name)s"
msg_args = dict(order_name=order.name)
exc_type = order.origin_exchange_type_id
if not exc_type.state_workflow_ids:
msg += ". No workflow configured on exc type " "%(type_name)s'"
msg_args["type_name"] = exc_type.name
_logger.error(msg, msg_args)


class EDISOEventListener(Component):
_name = "edi.sale.order.event.listener"
_inherit = "edi.sale.order.event.listener.mixin"
_apply_on = ["sale.order"]

def _get_records(self, record):
return record, record.order_line

def _skip_state_update(self, record, fields=None, operation=None):
res = super()._skip_state_update(record, fields=fields, operation=operation)
if res:
return res
fields = fields or []
# EDI state will be recomputed only at state change on write or in any case at creation
skip = operation == "write" and (
"state" not in fields or fields == ["edi_state_id"]
)
return skip


class EDISOLineEventListener(Component):
_name = "edi.sale.order.line.event.listener"
_inherit = "edi.sale.order.event.listener.mixin"
_apply_on = ["sale.order.line"]

def _get_records(self, record):
return record.order_id, record

def _skip_state_update(self, record, fields=None, operation=None):
res = super()._skip_state_update(record, fields=fields, operation=operation)
if res:
return res
if self.env.context.get("evt_from_create") == "sale.order":
# If lines are created from an SO creation straight
# bypass check and state compute because it will be done anyway at create.
return True
fields = fields or []
# EDI state will be recomputed when critical line info has changed
# TODO: tie this list w/ the fields in `s.o.l._edi_compare_orig_values`
trigger_fields = ("product_id", "product_uom_qty")
for fname in trigger_fields:
if fname in fields:
return False
70 changes: 70 additions & 0 deletions edi_sale_ubl_oca/data/edi_state.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo noupdate="1">
<!--
UBL norm has no specific state, hence we decided to use PEPPOL's definitions.
https://docs.peppol.eu/poacc/upgrade-3/codelist/UNCL4343-T76/
-->
<!-- sale.order -->
<record id="edi_sale_order_state_workflow" model="edi.state.workflow">
<field name="name">EDI sale order</field>
<field name="backend_type_id" ref="edi_ubl_oca.edi_backend_type_ubl" />
<field name="model_id" ref="sale.model_sale_order" />
</record>
<record id="edi_sale_order_state_ap" model="edi.state">
<field name="code">AP</field>
<field name="name">Accepted</field>
<field name="workflow_id" ref="edi_sale_order_state_workflow" />
<field name="is_default" eval="True" />
</record>
<record id="edi_sale_order_state_ab" model="edi.state">
<field name="code">AB</field>
<field name="name">Message acknowledgement</field>
<field name="workflow_id" ref="edi_sale_order_state_workflow" />
</record>
<record id="edi_sale_order_state_re" model="edi.state">
<field name="code">RE</field>
<field name="name">Rejected</field>
<field name="workflow_id" ref="edi_sale_order_state_workflow" />
</record>
<record id="edi_sale_order_state_ca" model="edi.state">
<field name="code">CA</field>
<field name="name">Conditionally accepted</field>
<field name="workflow_id" ref="edi_sale_order_state_workflow" />
</record>
<!-- sale.order.line
https://docs.peppol.eu/poacc/upgrade-3/codelist/UNCL1229/
-->
<record id="edi_sale_order_line_state_workflow" model="edi.state.workflow">
<field name="name">EDI sale order line</field>
<field name="backend_type_id" ref="edi_ubl_oca.edi_backend_type_ubl" />
<field name="model_id" ref="sale.model_sale_order_line" />
</record>
<record id="edi_sale_order_line_state_1" model="edi.state">
<field name="code">1</field>
<field name="name">Order line is added</field>
<field name="description">The information is to be or has been added</field>
<field name="workflow_id" ref="edi_sale_order_line_state_workflow" />
</record>
<record id="edi_sale_order_line_state_3" model="edi.state">
<field name="code">3</field>
<field name="name">Changed</field>
<field name="description">Order line is accepted with change</field>
<field name="workflow_id" ref="edi_sale_order_line_state_workflow" />
</record>
<record id="edi_sale_order_line_state_5" model="edi.state">
<field name="code">5</field>
<field name="name">Accepted without amendment</field>
<field name="workflow_id" ref="edi_sale_order_line_state_workflow" />
<field name="is_default" eval="True" />
</record>
<record id="edi_sale_order_line_state_7" model="edi.state">
<field name="code">7</field>
<field name="name"> Not accepted</field>
<field name="workflow_id" ref="edi_sale_order_line_state_workflow" />
</record>
<record id="edi_sale_order_line_state_42" model="edi.state">
<field name="code">42</field>
<field name="name">Already delivered</field>
<field name="workflow_id" ref="edi_sale_order_line_state_workflow" />
</record>
</odoo>
19 changes: 19 additions & 0 deletions edi_sale_ubl_oca/demo/edi_configuration.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<record id="demo_ubl_edi_configuration_confirmed" model="edi.configuration">
<field name="name">Demo UBL Sale OrderResponse - order confirmed</field>
<field
name="description"
>Show case how you can send out an order response automatically</field>
<field name="type_id" ref="demo_edi_exc_type_order_response_out" />
<field name="backend_id" ref="edi_ubl_oca.edi_backend_ubl_demo" />
<field name="model_id" ref="sale.model_sale_order" />
<field
name="trigger_id"
ref="edi_sale_oca.edi_conf_trigger_sale_order_state_sale"
/>
<field name="snippet_do">
record._edi_send_via_edi(conf.type_id)
</field>
</record>
</odoo>
52 changes: 52 additions & 0 deletions edi_sale_ubl_oca/demo/edi_exchange_type.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<!-- TODO: noupdate OR better create via post init hook -->
<record id="demo_edi_exc_type_order_response_out" model="edi.exchange.type">
<field name="backend_type_id" ref="edi_ubl_oca.edi_backend_type_ubl" />
<field name="backend_id" ref="edi_ubl_oca.edi_backend_ubl_demo" />
<field name="name">Demo UBL Sale Order Response</field>
<field name="code">demo_UBL_SaleOrderResponse_out</field>
<field name="direction">output</field>
<field name="exchange_filename_pattern">{record_name}-{type.code}-{dt}</field>
<field name="exchange_file_ext">xml</field>
<field
name="state_workflow_ids"
eval="[(6, 0, [
ref('edi_sale_ubl_oca.edi_sale_order_state_workflow'),
ref('edi_sale_ubl_oca.edi_sale_order_line_state_workflow')
])]"
/>
<field name="advanced_settings_edit">
components:
generate:
usage: ubl.generate.OrderResponse
validate:
usage: edi.xml
work_ctx:
schema_path: base_ubl:data/xsd-2.2/maindoc/UBL-OrderResponse-2.2.xsd
</field>
</record>

<record id="demo_edi_exc_type_order_in" model="edi.exchange.type">
<field name="backend_type_id" ref="edi_ubl_oca.edi_backend_type_ubl" />
<field name="backend_id" ref="edi_ubl_oca.edi_backend_ubl_demo" />
<field name="ack_type_id" ref="demo_edi_exc_type_order_response_out" />
<field name="name">Demo UBL Sale Order</field>
<field name="code">demo_UBL_SaleOrder_in</field>
<field name="direction">input</field>
<field name="exchange_file_ext">xml</field>
<field
name="state_workflow_ids"
eval="[(6, 0, [
ref('edi_sale_ubl_oca.edi_sale_order_state_workflow'),
ref('edi_sale_ubl_oca.edi_sale_order_line_state_workflow')
])]"
/>
<field name="advanced_settings_edit">
components:
process:
usage: input.process.sale.order
</field>
</record>

</odoo>
34 changes: 34 additions & 0 deletions edi_sale_ubl_oca/demo/exc_templ_order_response.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<record
id="demo_edi_exc_template_order_response_out"
model="edi.exchange.template.output"
>
<field name="name">UBL OrderResponse output</field>
<field name="code">ubl.generate.OrderResponse</field>
<field name="output_type">xml</field>
<field name="backend_type_id" ref="edi_ubl_oca.edi_backend_type_ubl" />
<field name="type_id" ref="demo_edi_exc_type_order_response_out" />
<field name="template_id" ref="qwb_tmpl_ubl_order_response_out" />
<field name="code_snippet">
seller = record.company_id.partner_id
buyer = record.partner_id

seller_party = get_party_data(exchange_record, seller)
buyer_party = get_party_data(exchange_record, buyer)
delivery = record.picking_ids.filtered(lambda x: x.picking_type_id.code == "outgoing")

_result = {
"seller_party": seller_party,
"buyer_party": buyer_party,
"delivery": delivery,
}

provider = get_info_provider(exchange_record, work_ctx=_result)
if provider:
_result["info"] = provider.generate_info()

result = _result
</field>
</record>
</odoo>
1 change: 1 addition & 0 deletions edi_sale_ubl_oca/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import sale_order
Loading
Loading