Skip to content
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

[16.0][MIG] edi_sale_oca: Migration to 16.0 #31

Merged
merged 19 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 121 additions & 0 deletions edi_sale_oca/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
=========
EDI Sales
=========

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:fb52928e31a51155acf8913e3bded99f8f488dc78beadcf8d6e35bb1f29b1bae
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |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--framework-lightgray.png?logo=github
:target: https://github.com/OCA/edi-framework/tree/16.0/edi_sale_oca
:alt: OCA/edi-framework
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/edi-framework-16-0/edi-framework-16-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-framework&target_branch=16.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-framework/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-framework/issues/new?body=module:%20edi_sale_oca%0Aversion:%2016.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 <[email protected]>
* Duong (Tran Quoc) <[email protected]>

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-framework <https://github.com/OCA/edi-framework/tree/16.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": "16.0.1.0.0",
"development_status": "Alpha",
"license": "AGPL-3",
"author": "Camptocamp,Odoo Community Association (OCA)",
"maintainers": ["simahawk"],
"website": "https://github.com/OCA/edi-framework",
"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
84 changes: 84 additions & 0 deletions edi_sale_oca/components/process.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# Copyright 2021 Camptocamp SA
# @author: Simone Orsi <[email protected]>
# 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
raise UserError(self.msg_generic_error)

@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")

@property
def msg_generic_error(self):
return _("Something went wrong with the importing wizard.")

Check warning on line 43 in edi_sale_oca/components/process.py

View check run for this annotation

Codecov / codecov/patch

edi_sale_oca/components/process.py#L43

Added line #L43 was not covered by tests

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>
1 change: 1 addition & 0 deletions edi_sale_oca/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import sale_order
73 changes: 73 additions & 0 deletions edi_sale_oca/models/sale_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Copyright 2022 Camptocamp SA
# @author: Simone Orsi <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, fields, models


class SaleOrder(models.Model):
_name = "sale.order"
_inherit = [
"sale.order",
"edi.exchange.consumer.mixin",
]
# Receiver may send or not the response on create
# then for each update IF required.
# https://docs.oasis-open.org/ubl/os-UBL-2.3/UBL-2.3.html#S-ORDERING-POST-AWARD
# https://docs.peppol.eu/poacc/upgrade-3/profiles/28-ordering
# /#_response_code_on_header_level

# TBD: implementing OrdResp for all modifications
# can be complex to manage (also for the 3rd party).
# Hence, we could block further modifications w/ sale exceptions
# and ask the sender to issue a new order request.
# This approach seems suitable only for orders that do not get processed immediately.

edi_disable_auto = fields.Boolean(
states={"draft": [("readonly", False)]},
)

# edi_record_metadata api
def _edi_get_metadata_to_store(self, orig_vals):
data = super()._edi_get_metadata_to_store(orig_vals)
# collect line values
line_vals_by_edi_id = {}
for line_vals in orig_vals.get("order_line", []):
# line_vals in the form `(0, 0, vals)`
vals = line_vals[-1]
line_vals_by_edi_id[vals["edi_id"]] = vals

data.update({"orig_values": {"lines": line_vals_by_edi_id}})
return data


class SaleOrderLine(models.Model):
_name = "sale.order.line"
_inherit = [
"sale.order.line",
"edi.exchange.consumer.mixin",
"edi.id.mixin",
]

edi_disable_auto = fields.Boolean(related="order_id.edi_disable_auto")

# TODO: add test
edi_exchange_ready = fields.Boolean(compute="_compute_edi_exchange_ready")

@api.depends()
def _compute_edi_exchange_ready(self):
for rec in self:
rec.edi_exchange_ready = rec._edi_exchange_ready()

Check warning on line 60 in edi_sale_oca/models/sale_order.py

View check run for this annotation

Codecov / codecov/patch

edi_sale_oca/models/sale_order.py#L60

Added line #L60 was not covered by tests

def _edi_exchange_ready(self):
return not self._is_delivery() and not self.display_type

Check warning on line 63 in edi_sale_oca/models/sale_order.py

View check run for this annotation

Codecov / codecov/patch

edi_sale_oca/models/sale_order.py#L63

Added line #L63 was not covered by tests

@api.model_create_multi
def create(self, vals_list):
# Set default origin if not passed
for vals in vals_list:
orig_id = vals.get("origin_exchange_record_id")
if not orig_id and "order_id" in vals:
order = self.env["sale.order"].browse(vals["order_id"])
vals["origin_exchange_record_id"] = order.origin_exchange_record_id.id
return super().create(vals_list)
2 changes: 2 additions & 0 deletions edi_sale_oca/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* Simone Orsi <[email protected]>
* Duong (Tran Quoc) <[email protected]>
1 change: 1 addition & 0 deletions edi_sale_oca/readme/CREDITS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The migration of this module from 14.0 to 16.0 was financially supported by Camptocamp.
27 changes: 27 additions & 0 deletions edi_sale_oca/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
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

simahawk marked this conversation as resolved.
Show resolved Hide resolved
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?
Loading
Loading