Skip to content

Commit

Permalink
[IMP] edi_sale_oca: Refactor code for passing all configurations via …
Browse files Browse the repository at this point in the history
…env_ctx

The configurations here are values for the wizard and whatever we need
  • Loading branch information
duongtq authored and OCA-git-bot committed Nov 15, 2023
1 parent 31e6794 commit 5d3eec8
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 30 deletions.
16 changes: 11 additions & 5 deletions edi_sale_oca/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ EDI Sales
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:a15a65af9b9ffa6808d4901942982eb8467aa13f7c1ac65c07f8751ccbceeff7
!! source digest: sha256:fb52928e31a51155acf8913e3bded99f8f488dc78beadcf8d6e35bb1f29b1bae
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png
Expand Down Expand Up @@ -43,10 +43,16 @@ On your exchange type, go to advanced settings and add the following::
components:
process:
usage: input.process.sale.order
[...]
sale_order:
default_confirm_order: true

env_ctx:
# Values for the wizard
default_confirm_order: true
default_price_source: order
# Custom keys, whatever you need
random_one: true

Note that `env_ctx` will propagate all keys to the whole env so you can use it
for any kind of context related configuration. In the case of the sale order import wizard
here we are just passing defaults as we could do in odoo standard.

TODO: shall we add an exchange type example as demo?

Expand Down
21 changes: 8 additions & 13 deletions edi_sale_oca/components/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,6 @@ 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:
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,13 +44,17 @@ def msg_generic_error(self):

def _setup_wizard(self):
"""Init a `sale.order.import` instance for current record."""
ctx = self.settings.get("wiz_ctx", {})
# Set the right EDI origin on both order and lines
edi_defaults = {"origin_exchange_record_id": self.exchange_record.id}
ctx["sale_order_import__default_vals"] = dict(
order=edi_defaults, lines=edi_defaults
addtional_ctx = dict(
sale_order_import__default_vals=dict(order=edi_defaults, lines=edi_defaults)
)
wiz = (
self.env["sale.order.import"]
.with_context(**addtional_ctx)
.sudo()
.create({})
)
wiz = self.env["sale.order.import"].with_context(**ctx).sudo().create({})
wiz.order_file = self.exchange_record._get_file_content(binary=False)
wiz.order_filename = self.exchange_record.exchange_filename
wiz.order_file_change()
Expand Down
12 changes: 9 additions & 3 deletions edi_sale_oca/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,15 @@ On your exchange type, go to advanced settings and add the following::
components:
process:
usage: input.process.sale.order
[...]
sale_order:
default_confirm_order: true
env_ctx:
# Values for the wizard
default_confirm_order: true
default_price_source: order
# Custom keys, whatever you need
random_one: true

Note that `env_ctx` will propagate all keys to the whole env so you can use it
for any kind of context related configuration. In the case of the sale order import wizard
here we are just passing defaults as we could do in odoo standard.

TODO: shall we add an exchange type example as demo?
14 changes: 10 additions & 4 deletions edi_sale_oca/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ <h1 class="title">EDI Sales</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:a15a65af9b9ffa6808d4901942982eb8467aa13f7c1ac65c07f8751ccbceeff7
!! source digest: sha256:fb52928e31a51155acf8913e3bded99f8f488dc78beadcf8d6e35bb1f29b1bae
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Alpha" src="https://img.shields.io/badge/maturity-Alpha-red.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/edi-framework/tree/16.0/edi_sale_oca"><img alt="OCA/edi-framework" src="https://img.shields.io/badge/github-OCA%2Fedi--framework-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/edi-framework-16-0/edi-framework-16-0-edi_sale_oca"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runboat.odoo-community.org/builds?repo=OCA/edi-framework&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<div class="section" id="inbound">
Expand All @@ -383,10 +383,16 @@ <h1>Control sale order confirmation</h1>
components:
process:
usage: input.process.sale.order
[...]
sale_order:
default_confirm_order: true
env_ctx:
# Values for the wizard
default_confirm_order: true
default_price_source: order
# Custom keys, whatever you need
random_one: true
</pre>
<p>Note that <cite>env_ctx</cite> will propagate all keys to the whole env so you can use it
for any kind of context related configuration. In the case of the sale order import wizard
here we are just passing defaults as we could do in odoo standard.</p>
<p>TODO: shall we add an exchange type example as demo?</p>
<div class="admonition important">
<p class="first admonition-title">Important</p>
Expand Down
9 changes: 4 additions & 5 deletions edi_sale_oca/tests/test_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,10 @@ def setUpClass(cls):
components:
process:
usage: input.process.sale.order
sale_order_import:
wiz_ctx:
random_key: custom
default_price_source: 'pricelist'
default_import_type: 'xml'
env_ctx:
default_price_source: 'pricelist'
default_import_type: 'xml'
random_key: custom
"""
),
)
Expand Down

0 comments on commit 5d3eec8

Please sign in to comment.