Skip to content

Commit

Permalink
Merge PR #1023 into 14.0
Browse files Browse the repository at this point in the history
Signed-off-by simahawk
  • Loading branch information
OCA-git-bot committed Nov 14, 2024
2 parents 94addaf + d4dd854 commit 5e459c0
Show file tree
Hide file tree
Showing 27 changed files with 1,637 additions and 0 deletions.
122 changes: 122 additions & 0 deletions edi_sale_oca/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
=========
EDI Sales
=========

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:2b4f89b88e7d4e87c5a1249801ac1225c3c3e33b7c21ecd3f3eeb66e9e38f2da
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png
:target: https://odoo-community.org/page/development-status
:alt: Alpha
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fedi-lightgray.png?logo=github
:target: https://github.com/OCA/edi/tree/14.0/edi_sale_oca
:alt: OCA/edi
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/edi-14-0/edi-14-0-edi_sale_oca
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/edi&target_branch=14.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

Inbound
~~~~~~~
Receive sale orders from EDI channels.

Control sale order confirmation
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

You can decide if the order should be confirmed by exchange type.

On your exchange type, go to advanced settings and add the following::

[...]
components:
process:
usage: input.process.sale.order
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?

.. IMPORTANT::
This is an alpha version, the data model and design can change at any time without warning.
Only for development or testing purpose, do not use in production.
`More details on development status <https://odoo-community.org/page/development-status>`_

**Table of contents**

.. contents::
:local:

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/edi/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/edi/issues/new?body=module:%20edi_sale_oca%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
~~~~~~~

* Camptocamp

Contributors
~~~~~~~~~~~~

* Simone Orsi <simone.orsi@camptocamp.com>
* Duong (Tran Quoc) <duongtq@trobz.com>
* Thien (Vo Hong) <thienvh@trobz.com>

Other credits
~~~~~~~~~~~~~

The migration of this module from 14.0 to 16.0 was financially supported by Camptocamp.

Maintainers
~~~~~~~~~~~

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

.. |maintainer-simahawk| image:: https://github.com/simahawk.png?size=40px
:target: https://github.com/simahawk
:alt: simahawk

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-simahawk|

This module is part of the `OCA/edi <https://github.com/OCA/edi/tree/14.0/edi_sale_oca>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
3 changes: 3 additions & 0 deletions edi_sale_oca/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import components
from . import models
from . import wizard
27 changes: 27 additions & 0 deletions edi_sale_oca/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# 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)",
"maintainers": ["simahawk"],
"website": "https://github.com/OCA/edi",
"depends": [
"edi_oca",
"edi_record_metadata_oca",
"sale_order_import",
],
"data": [
"data/job_function.xml",
"views/res_partner.xml",
"views/sale_order.xml",
"views/edi_exchange_record.xml",
"templates/exchange_chatter_msg.xml",
],
}
1 change: 1 addition & 0 deletions edi_sale_oca/components/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import process
79 changes: 79 additions & 0 deletions edi_sale_oca/components/process.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Copyright 2021 Camptocamp SA
# @author: Simone Orsi <simone.orsi@camptocamp.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).


from odoo import _
from odoo.exceptions import UserError

from odoo.addons.component.core import Component


class EDIExchangeSOInput(Component):
"""Process sale orders."""

_name = "edi.input.sale.order.process"
_inherit = "edi.component.input.mixin"
_usage = "input.process.sale.order"

def process(self):
wiz = self._setup_wizard()
res = wiz.import_order_button()
# TODO: log debug
if wiz.state == "update" and wiz.sale_id:
order = wiz.sale_id
msg = self.msg_order_existing_error
self._handle_existing_order(order, msg)
raise UserError(msg)
else:
order = self._handle_create_order(res["res_id"])
return self.msg_order_created % order.name

@property
def msg_order_existing_error(self):
return _("Sales order has already been imported before")

@property
def msg_order_created(self):
return _("Sales order %s created")

def _setup_wizard(self):
"""Init a `sale.order.import` instance for current record."""
# Set the right EDI origin on both order and lines
edi_defaults = {"origin_exchange_record_id": self.exchange_record.id}
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.order_file = self.exchange_record._get_file_content(binary=False)
wiz.order_filename = self.exchange_record.exchange_filename
wiz.order_file_change()
return wiz

def _handle_create_order(self, order_id):
order = self.env["sale.order"].browse(order_id)
self.exchange_record._set_related_record(order)
return order

def _handle_existing_order(self, order, message):
prev_record = self._get_previous_record(order)
self.exchange_record.message_post_with_view(
"edi_sale_oca.message_already_imported",
values={
"order": order,
"prev_record": prev_record,
"message": message,
"level": "info",
},
subtype_id=self.env.ref("mail.mt_note").id,
)

def _get_previous_record(self, order):
return self.env["edi.exchange.record"].search(
[("model", "=", "sale.order"), ("res_id", "=", order.id)], limit=1
)
7 changes: 7 additions & 0 deletions edi_sale_oca/data/job_function.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<odoo noupdate="1">
<record id="job_fun_auto_handle" model="queue.job.function">
<field name="model_id" ref="sale.model_sale_order" />
<field name="method">_edi_auto_handle_generate</field>
<field name="channel_id" ref="edi_oca.channel_edi_exchange" />
</record>
</odoo>
Loading

0 comments on commit 5e459c0

Please sign in to comment.