-
-
Notifications
You must be signed in to change notification settings - Fork 310
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[UPD] edi_purchase_oca: Update for edi configuration
- Loading branch information
1 parent
d8f5dba
commit 6f64596
Showing
12 changed files
with
161 additions
and
19 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
from . import models | ||
from . import components |
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 listener_purchase_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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Copyright 2024 Camptocamp SA | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo.addons.component.core import Component | ||
|
||
|
||
class EDIConfigPurchaseListener(Component): | ||
_name = "edi.listener.config.purchase.order" | ||
_inherit = "base.event.listener" | ||
_apply_on = ["purchase.order"] | ||
|
||
def on_button_confirm_purchase_order(self, record): | ||
trigger = "on_button_confirm_purchase_order" | ||
confs = record.partner_id.edi_purchase_conf_ids.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
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,3 @@ | ||
from . import purchase_order | ||
from . import res_partner | ||
from . import edi_configuration |
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 | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import fields, models | ||
|
||
|
||
class EdiConfiguration(models.Model): | ||
_inherit = "edi.configuration" | ||
|
||
trigger = fields.Selection( | ||
selection_add=[ | ||
("on_button_confirm_purchase_order", "On Button Confirm Purchase Order"), | ||
("send_via_email_rfq", "Send via Email RFQ"), | ||
], | ||
ondelete={ | ||
"on_button_confirm_purchase_order": "set default", | ||
"send_via_email_rfq": "set default", | ||
}, | ||
) |
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 test_edi_configuration |
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,91 @@ | ||
# Copyright 2024 CamptoCamp SA | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
import mock | ||
|
||
from odoo.exceptions import UserError | ||
|
||
from odoo.addons.edi_oca.tests.common import EDIBackendCommonComponentRegistryTestCase | ||
|
||
|
||
class TestsPurchaseEDIConfiguration(EDIBackendCommonComponentRegistryTestCase): | ||
@classmethod | ||
def setUpClass(cls): | ||
super().setUpClass() | ||
cls._load_module_components(cls, "edi_purchase_oca") | ||
cls.edi_configuration = cls.env["edi.configuration"] | ||
cls.purchase_order = cls.env["purchase.order"] | ||
cls.product = cls.env["product.product"].create( | ||
{ | ||
"name": "Product 1", | ||
"default_code": "1234567", | ||
} | ||
) | ||
|
||
def setUp(self): | ||
super().setUp() | ||
self.confirm_conf = self.env.ref( | ||
"edi_purchase_oca.edi_conf_button_confirm_purchase_order" | ||
) | ||
self.partner.write({"edi_purchase_conf_ids": [(4, self.confirm_conf.id)]}) | ||
|
||
def test_edi_configuration_snippet_before_do(self): | ||
order = self.purchase_order.create( | ||
{ | ||
"partner_id": self.partner.id, | ||
"order_line": [ | ||
( | ||
0, | ||
0, | ||
{ | ||
"product_id": self.product.id, | ||
"product_qty": 10, | ||
"price_unit": 100.0, | ||
}, | ||
) | ||
], | ||
} | ||
) | ||
self.assertTrue(order) | ||
self.assertEqual(order.state, "draft") | ||
|
||
# Replace snippet_before_do for test | ||
self.confirm_conf.snippet_before_do = "record.button_cancel()" | ||
order.button_confirm() | ||
# After purchase order is confirmed | ||
# it will be automatically canceled due to edi_configuration execution. | ||
self.assertEqual(order.state, "cancel") | ||
|
||
def test_edi_configuration_snippet_do(self): | ||
self.confirm_conf.write( | ||
{ | ||
"backend_id": self.backend.id, | ||
"type_id": self.exchange_type_out.id, | ||
"snippet_do": "record._edi_send_via_edi(conf.type_id)", | ||
} | ||
) | ||
with mock.patch.object( | ||
type(self.backend), "exchange_generate", return_value=True | ||
): | ||
|
||
with self.assertRaises(UserError) as err: | ||
order = self.purchase_order.create( | ||
{ | ||
"partner_id": self.partner.id, | ||
"order_line": [ | ||
( | ||
0, | ||
0, | ||
{ | ||
"product_id": self.product.id, | ||
"product_qty": 10, | ||
"price_unit": 100.0, | ||
}, | ||
) | ||
], | ||
} | ||
) | ||
order.button_confirm() | ||
self.assertRegex( | ||
err.exception.args[0], r"Record ID=\d+ has no file to send!" | ||
) |
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