-
-
Notifications
You must be signed in to change notification settings - Fork 311
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] edi_sale_oca: use edi.configuration #1067
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import listeners |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Copyright 2024 Camptocamp SA | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo.addons.component.core import Component | ||
|
||
|
||
class EDIConfigSOListener(Component): | ||
_name = "edi.listener.config.sale.order" | ||
_inherit = "base.event.listener" | ||
_apply_on = ["sale.order"] | ||
|
||
def on_record_create(self, record, fields=None): | ||
trigger = "on_record_create" | ||
return self._exec_conf(record, trigger) | ||
|
||
def on_record_write(self, record, fields=None): | ||
trigger = "on_record_write" | ||
return self._exec_conf(record, trigger) | ||
|
||
def on_edi_sale_order_state_change(self, record, state=None): | ||
trigger = "on_edi_sale_order_state_change" | ||
return self._exec_conf(record, trigger) | ||
|
||
def _exec_conf(self, record, trigger, conf_field="edi_sale_conf_ids"): | ||
confs = record.partner_id[conf_field].edi_get_conf(trigger) | ||
for conf in confs: | ||
conf.edi_exec_snippet_do(record) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<odoo> | ||
<!-- Generic state change --> | ||
<record | ||
id="edi_conf_trigger_sale_order_state_change" | ||
model="edi.configuration.trigger" | ||
> | ||
<field name="name">On SO state change</field> | ||
<field name="code">on_edi_sale_order_state_change</field> | ||
<field name="description">Trigger when a sale order state changes</field> | ||
<field name="model_id" ref="sale.model_sale_order" /> | ||
</record> | ||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<odoo> | ||
<record id="demo_edi_configuration_confirmed" model="edi.configuration"> | ||
<field name="name">Demo 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_out" /> | ||
<field name="backend_id" ref="demo_edi_backend" /> | ||
<field name="model_id" ref="sale.model_sale_order" /> | ||
<field name="trigger_id" ref="edi_conf_trigger_sale_order_state_change" /> | ||
<field name="snippet_do"> | ||
# STATES | ||
# ('draft', 'Quotation'), | ||
# ('sent', 'Quotation Sent'), | ||
# ('sale', 'Sales Order'), | ||
# ('done', 'Locked'), | ||
# ('cancel', 'Cancelled'), | ||
if record.state == 'sale': | ||
record._edi_send_via_edi(conf.type_id) | ||
</field> | ||
</record> | ||
<record id="demo_edi_configuration_done" model="edi.configuration"> | ||
<field name="name">Demo Sale OrderResponse - order done</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_out" /> | ||
<field name="backend_id" ref="demo_edi_backend" /> | ||
<field name="model_id" ref="sale.model_sale_order" /> | ||
<field name="trigger_id" ref="edi_conf_trigger_sale_order_state_change" /> | ||
<field name="snippet_do"> | ||
if record.state == 'done': | ||
record._edi_send_via_edi(conf.type_id) | ||
</field> | ||
</record> | ||
|
||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,24 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<odoo> | ||
<!-- TODO: add demo and tests for fake input/output exchanges. --> | ||
<!-- <record id="demo_edi_exc_type_order_in" model="edi.exchange.type"> | ||
|
||
<record id="demo_edi_exc_type_order_out" model="edi.exchange.type"> | ||
<field name="backend_type_id" ref="demo_edi_backend_type_sale" /> | ||
<field name="backend_id" ref="demo_edi_backend" /> | ||
<field name="name">Demo Sale Order Response</field> | ||
<field name="code">demo_SaleOrder_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> | ||
</record> | ||
|
||
<record id="demo_edi_exc_type_order_in" model="edi.exchange.type"> | ||
<field name="backend_type_id" ref="demo_edi_backend_type_sale" /> | ||
<field name="backend_id" ref="demo_edi_backend" /> | ||
<field name="ack_type_id" ref="demo_edi_exc_type_order_response_out" /> | ||
<!-- <field name="ack_type_id" ref="demo_edi_exc_type_order_out" /> --> | ||
<field name="name">Demo Sale Order</field> | ||
<field name="code">demo_SaleOrder_in</field> | ||
<field name="direction">input</field> | ||
<field name="exchange_file_ext">xml</field> | ||
<field name="advanced_settings_edit"> | ||
components: | ||
process: | ||
usage: input.process.sale.order | ||
env_ctx: | ||
default_price_source: 'pricelist' | ||
default_import_type: 'xml' | ||
random_key: custom | ||
</field> | ||
</record> --> | ||
</record> | ||
|
||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
from . import sale_order | ||
from . import res_partner |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Copyright 2024 Camptocamp SA | ||
# @author: Simone Orsi <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
|
||
from odoo import fields, models | ||
|
||
|
||
class ResPartner(models.Model): | ||
_inherit = "res.partner" | ||
|
||
edi_sale_conf_ids = fields.Many2many( | ||
string="EDI sale configuration", | ||
comodel_name="edi.configuration", | ||
relation="res_partner_edi_sale_configuration_rel", | ||
column1="partner_id", | ||
column2="conf_id", | ||
domain=[("model_name", "=", "sale.order")], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
from . import test_order | ||
from . import test_generate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
# Copyright 2024 Camptocamp SA | ||
# @author: Simone Orsi <[email protected]> | ||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). | ||
|
||
|
||
from odoo.addons.component.tests.common import SavepointComponentRegistryCase | ||
from odoo.addons.edi_oca.tests.common import EDIBackendTestMixin | ||
from odoo.addons.edi_oca.tests.fake_components import ( | ||
FakeOutputGenerator, | ||
FakeOutputSender, | ||
) | ||
|
||
|
||
class Generator(FakeOutputGenerator): | ||
_backend_type = "sale_demo" | ||
_exchange_type = "demo_SaleOrder_out" | ||
|
||
|
||
class Sender(FakeOutputSender): | ||
_backend_type = "sale_demo" | ||
_exchange_type = "demo_SaleOrder_out" | ||
|
||
|
||
class TestProcessComponent(SavepointComponentRegistryCase, EDIBackendTestMixin): | ||
@classmethod | ||
def setUpClass(cls): | ||
super().setUpClass() | ||
cls._setup_env() | ||
cls.backend = cls._get_backend() | ||
cls.exc_type = cls.env.ref("edi_sale_oca.demo_edi_exc_type_order_out") | ||
cls.edi_conf_confirmed = cls.env.ref( | ||
"edi_sale_oca.demo_edi_configuration_confirmed" | ||
) | ||
cls.edi_conf_done = cls.env.ref("edi_sale_oca.demo_edi_configuration_done") | ||
cls.partner = cls.env.ref("base.res_partner_2").copy({"name": "John Doe"}) | ||
cls._load_module_components(cls, "edi_oca") | ||
cls._load_module_components(cls, "edi_sale_oca") | ||
cls._build_components( | ||
cls, | ||
Generator, | ||
Sender, | ||
) | ||
|
||
def setUp(self): | ||
super().setUp() | ||
Generator.reset_faked() | ||
Sender.reset_faked() | ||
|
||
@classmethod | ||
def _get_backend(cls): | ||
return cls.env.ref("edi_sale_oca.demo_edi_backend") | ||
|
||
def test_lookup(self): | ||
# Just ensuring test setup is done properly | ||
record = self.backend.create_record(self.exc_type.code, {}) | ||
comp = self.backend._get_component(record, "generate") | ||
self.assertEqual(comp._name, Generator._name) | ||
comp = self.backend._get_component(record, "send") | ||
self.assertEqual(comp._name, Sender._name) | ||
|
||
def test_new_order_no_conf_no_output(self): | ||
order = self.env["sale.order"].create( | ||
{ | ||
"partner_id": self.partner.id, | ||
} | ||
) | ||
order.action_confirm() | ||
self.assertFalse(order.exchange_record_ids) | ||
|
||
def test_new_order_1conf_output(self): | ||
self.partner.edi_sale_conf_ids = self.edi_conf_confirmed | ||
order = self.env["sale.order"].create( | ||
{ | ||
"partner_id": self.partner.id, | ||
} | ||
) | ||
self.assertFalse(order.exchange_record_ids) | ||
order.with_context(fake_output="ORDER CONFIRM").action_confirm() | ||
self.assertEqual(len(order.exchange_record_ids), 1) | ||
record = order.exchange_record_ids[0] | ||
self.assertEqual(record._get_file_content(), "ORDER CONFIRM") | ||
self.assertEqual(record.type_id, self.exc_type) | ||
# When done, nothing changes | ||
order.action_done() | ||
self.assertEqual(len(order.exchange_record_ids), 1) | ||
record = order.exchange_record_ids[0] | ||
self.assertEqual(record.type_id, self.exc_type) | ||
|
||
def test_new_order_2conf_output(self): | ||
self.partner.edi_sale_conf_ids = self.edi_conf_confirmed | self.edi_conf_done | ||
order = self.env["sale.order"].create( | ||
{ | ||
"partner_id": self.partner.id, | ||
} | ||
) | ||
self.assertFalse(order.exchange_record_ids) | ||
order.with_context(fake_output="ORDER CONFIRM").action_confirm() | ||
self.assertEqual(len(order.exchange_record_ids), 1) | ||
record = order.exchange_record_ids[0] | ||
self.assertEqual(record._get_file_content(), "ORDER CONFIRM") | ||
self.assertEqual(record.type_id, self.exc_type) | ||
# When done, nothing changes | ||
order.with_context(fake_output="ORDER DONE").action_done() | ||
record1, record2 = order.exchange_record_ids | ||
self.assertEqual(record1.type_id, self.exc_type) | ||
self.assertEqual(record1._get_file_content(), "ORDER CONFIRM") | ||
self.assertEqual(record2.type_id, self.exc_type) | ||
self.assertEqual(record2._get_file_content(), "ORDER DONE") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be useful to add help text explaining which variables are available to use in the snippet (like Odoo does by default for server actions or crons)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
variables come from edi_oca. I'll check there.