Skip to content

Commit

Permalink
edi_sale_input: add support for legacy conf
Browse files Browse the repository at this point in the history
This was supported in early un-merged version of the module.
Let's be kind w/ existing configurations ;)
  • Loading branch information
simahawk committed Dec 4, 2024
1 parent e6cc0d3 commit 1ca0481
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
30 changes: 30 additions & 0 deletions edi_sale_input_oca/components/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).


import logging

from odoo import _
from odoo.exceptions import UserError

from odoo.addons.component.core import Component

_logger = logging.getLogger(__name__)


class EDIExchangeSOInput(Component):
"""Process sale orders."""
Expand All @@ -16,6 +20,21 @@ class EDIExchangeSOInput(Component):
_inherit = "edi.component.input.mixin"
_usage = "input.process.sale.order"

def __init__(self, work_context):
super().__init__(work_context)
self.settings = {}
# Suppor legacy key `self.type_settings`
for key in ("sale_order", "sale_order_import"):
if key in self.type_settings:
_logger.warning(
"Deprecated key %s for %s. "
"Please use default field values in env_ctx",
key,
self._usage,
)
self.settings = self.type_settings.get(key, {})
break

def process(self):
wiz = self._setup_wizard()
res = wiz.import_order_button()
Expand Down Expand Up @@ -53,8 +72,19 @@ def _setup_wizard(self):
wiz.order_file = self.exchange_record._get_file_content(binary=False)
wiz.order_filename = self.exchange_record.exchange_filename
wiz.order_file_change()
wiz.price_source = self._get_default_price_source()
wiz.confirm_order = self._order_should_be_confirmed()
return wiz

# Deprecated: use default field values in env_ctx
# as these settings are supported by sale_order_import model.
def _get_default_price_source(self):
return self.settings.get("price_source", "pricelist")

# Deprecated: use default field values in env_ctx
def _order_should_be_confirmed(self):
return self.settings.get("confirm_order", False)

def _handle_create_order(self, order_id):
order = self.env["sale.order"].browse(order_id)
self.exchange_record._set_related_record(order)
Expand Down
28 changes: 28 additions & 0 deletions edi_sale_input_oca/tests/test_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

import base64
import textwrap
from unittest import mock

from odoo.tools import mute_logger

from odoo.addons.component.tests.common import SavepointComponentCase
from odoo.addons.edi_oca.tests.common import EDIBackendTestMixin

Expand Down Expand Up @@ -45,6 +48,31 @@ def test_wizard_setup(self):
self.assertEqual(wiz.price_source, "pricelist")
md_onchange.assert_called()

@mute_logger("odoo.addons.edi_sale_input_oca.components.process")
def test_wizard_setup_deprecated_settings(self):
self.exc_type.advanced_settings_edit = textwrap.dedent(
"""
components:
process:
usage: input.process.sale.order
sale_order_import:
confirm_order: true
"""
)
comp = self.backend._get_component(self.record, "process")
with mock.patch.object(
type(self.wiz_model), "order_file_change"
) as md_onchange:
wiz = comp._setup_wizard()
self.assertEqual(wiz._name, self.wiz_model._name)
self.assertEqual(
base64.b64decode(wiz.order_file), b"<fake><order></order></fake>"
)
self.assertEqual(wiz.order_filename, self.record.exchange_filename)
self.assertEqual(wiz.price_source, "pricelist")
self.assertEqual(wiz.confirm_order, True)
md_onchange.assert_called()

# In both tests here we don"t care about the specific format of the import.
# We only care that the wizard plugged with the component works as expected.
def test_existing_order(self):
Expand Down

0 comments on commit 1ca0481

Please sign in to comment.