-
-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[16.0][ADD] - stock_release_channel_shipment_advice
This module is used to plan the shipment advice for released pickings in a stock release channel. As this is the base module, it provides only a simple planning mode. All released pickings are grouped together in a single advice. fix label Co-authored-by: Laurent Mignon (ACSONE) <laurent.mignon@acsone.eu> [FIX] - button_show_shipment_advice: improve domain Co-authored-by: Laurent Mignon (ACSONE) <laurent.mignon@acsone.eu> [IMP] - _compute_can_plan_shipment: improve expression Co-authored-by: Laurent Mignon (ACSONE) <laurent.mignon@acsone.eu> [IMP] - _plan_shipment: improve expression Co-authored-by: Laurent Mignon (ACSONE) <laurent.mignon@acsone.eu>
- Loading branch information
Showing
19 changed files
with
891 additions
and
1 deletion.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
...p/stock_release_channel_shipment_advice/odoo/addons/stock_release_channel_shipment_advice
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 @@ | ||
../../../../stock_release_channel_shipment_advice |
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,6 @@ | ||
import setuptools | ||
|
||
setuptools.setup( | ||
setup_requires=['setuptools-odoo'], | ||
odoo_addon=True, | ||
) |
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,86 @@ | ||
===================================== | ||
Stock Release Channel Shipment Advice | ||
===================================== | ||
|
||
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png | ||
:target: https://odoo-community.org/page/development-status | ||
:alt: Beta | ||
.. |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%2Fwms-lightgray.png?logo=github | ||
:target: https://github.com/OCA/wms/tree/16.0/stock_release_channel_shipment_advice | ||
:alt: OCA/wms | ||
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png | ||
:target: https://translation.odoo-community.org/projects/wms-16-0/wms-16-0-stock_release_channel_shipment_advice | ||
:alt: Translate me on Weblate | ||
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png | ||
:target: https://runboat.odoo-community.org/webui/builds.html?repo=OCA/wms&target_branch=16.0 | ||
:alt: Try me on Runboat | ||
|
||
|badge1| |badge2| |badge3| |badge4| |badge5| | ||
|
||
This module is used to plan the shipment advice for released pickings in a | ||
stock release channel. | ||
|
||
As this is the base module, it provides only a simple | ||
planning mode. All released pickings are grouped together in a single advice. | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Usage | ||
===== | ||
|
||
To use this module, you need to: | ||
|
||
#. Go to Inventory>Release Channels. | ||
#. Select a channel with released picking. | ||
#. Click on "Plan shipment" button. | ||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues <https://github.com/OCA/wms/issues>`_. | ||
In case of trouble, please check there if your issue has already been reported. | ||
If you spotted it first, help us smashing it by providing a detailed and welcomed | ||
`feedback <https://github.com/OCA/wms/issues/new?body=module:%20stock_release_channel_shipment_advice%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 | ||
~~~~~~~ | ||
|
||
* ACSONE SA/NV | ||
|
||
Contributors | ||
~~~~~~~~~~~~ | ||
|
||
* Souheil Bejaoui <souheil.bejaoui@acsone.eu> | ||
|
||
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. | ||
|
||
This module is part of the `OCA/wms <https://github.com/OCA/wms/tree/16.0/stock_release_channel_shipment_advice>`_ project on GitHub. | ||
|
||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
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 models |
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,18 @@ | ||
# Copyright 2023 ACSONE SA/NV | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
{ | ||
"name": "Stock Release Channel Shipment Advice", | ||
"summary": """ | ||
fixme""", | ||
"version": "16.0.1.0.0", | ||
"license": "AGPL-3", | ||
"author": "ACSONE SA/NV,Odoo Community Association (OCA)", | ||
"website": "https://github.com/OCA/wms", | ||
"depends": ["shipment_advice", "stock_release_channel"], | ||
"data": [ | ||
"views/shipment_advice.xml", | ||
"views/stock_release_channel.xml", | ||
], | ||
"demo": [], | ||
} |
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,3 @@ | ||
from . import stock_release_channel | ||
from . import shipment_advice | ||
from . import stock_picking |
15 changes: 15 additions & 0 deletions
15
stock_release_channel_shipment_advice/models/shipment_advice.py
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,15 @@ | ||
# Copyright 2023 ACSONE SA/NV | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import fields, models | ||
|
||
|
||
class ShipmentAdvice(models.Model): | ||
_inherit = "shipment.advice" | ||
|
||
release_channel_id = fields.Many2one( | ||
comodel_name="stock.release.channel", | ||
string="Release Channel", | ||
states={"draft": [("readonly", False)]}, | ||
readonly=True, | ||
) |
13 changes: 13 additions & 0 deletions
13
stock_release_channel_shipment_advice/models/stock_picking.py
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,13 @@ | ||
# Copyright 2023 ACSONE SA/NV | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import fields, models | ||
|
||
|
||
class StockPicking(models.Model): | ||
|
||
_inherit = "stock.picking" | ||
|
||
warehouse_id = fields.Many2one( | ||
comodel_name="stock.warehouse", related="location_id.warehouse_id", store=True | ||
) |
154 changes: 154 additions & 0 deletions
154
stock_release_channel_shipment_advice/models/stock_release_channel.py
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,154 @@ | ||
# Copyright 2023 ACSONE SA/NV | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import Command, _, api, fields, models | ||
from odoo.exceptions import UserError | ||
|
||
|
||
class StockReleaseChannel(models.Model): | ||
_inherit = "stock.release.channel" | ||
|
||
shipment_planning_method = fields.Selection( | ||
selection=[("none", "None"), ("simple", "Simple")], | ||
required=True, | ||
default="none", | ||
) | ||
picking_to_plan_ids = fields.Many2many( | ||
comodel_name="stock.picking", compute="_compute_picking_to_plan_ids" | ||
) | ||
can_plan_shipment = fields.Boolean(compute="_compute_can_plan_shipment") | ||
shipment_advice_ids = fields.One2many( | ||
comodel_name="shipment.advice", | ||
inverse_name="release_channel_id", | ||
string="Shipment Advices", | ||
readonly=True, | ||
) | ||
|
||
def button_show_shipment_advice(self): | ||
self.ensure_one() | ||
return { | ||
"type": "ir.actions.act_window", | ||
"name": _("Shipment Advice"), | ||
"view_mode": "calendar,tree,form", | ||
"res_model": self.shipment_advice_ids._name, | ||
"domain": [("release_channel_id", "=", self.id)], | ||
"context": self.env.context, | ||
} | ||
|
||
@api.depends("shipment_planning_method", "picking_to_plan_ids") | ||
def _compute_can_plan_shipment(self): | ||
for rec in self: | ||
rec.can_plan_shipment = ( | ||
rec.shipment_planning_method != "none" and rec.picking_to_plan_ids | ||
) | ||
|
||
@api.depends("picking_ids", "picking_ids.planned_shipment_advice_id") | ||
def _compute_picking_to_plan_ids(self): | ||
for rec in self: | ||
rec.picking_to_plan_ids = rec.picking_ids.filtered( | ||
lambda p: not p.planned_shipment_advice_id and p.state == "assigned" | ||
) | ||
|
||
def button_plan_shipment(self): | ||
self.ensure_one() | ||
if not self.can_plan_shipment: | ||
raise UserError(_("Shipment planning not allowed")) | ||
shipment_advice = self._plan_shipment() | ||
if not shipment_advice: | ||
return {} | ||
return { | ||
"type": "ir.actions.act_window", | ||
"name": _("Shipment Advice"), | ||
"view_mode": "form", | ||
"res_model": shipment_advice._name, | ||
"res_id": shipment_advice.id, | ||
"context": self.env.context, | ||
} | ||
|
||
def _get_release_channels_by_shipment_planning_method(self): | ||
res = {} | ||
for group in self.read_group( | ||
[("id", "in", self.ids)], | ||
["shipment_planning_method"], | ||
["shipment_planning_method"], | ||
): | ||
res[group.get("shipment_planning_method")] = self.search( | ||
group.get("__domain") | ||
) | ||
return res | ||
|
||
def _plan_shipment(self): | ||
shipment_advices = self.env["shipment.advice"] | ||
for ( | ||
shipment_planning_method, | ||
channels, | ||
) in self._get_release_channels_by_shipment_planning_method().items(): | ||
_shipment_planning_method_name = self._get_shipment_planning_method_name( | ||
shipment_planning_method | ||
) | ||
if not hasattr(self, _shipment_planning_method_name): | ||
raise NotImplementedError( | ||
_("There is no implementation for the planning method '%s'") | ||
% self.shipment_planning_method | ||
) | ||
shipment_advices |= getattr(channels, _shipment_planning_method_name)() | ||
return shipment_advices | ||
|
||
def _get_picking_to_plan_by_warehouse(self): | ||
self.ensure_one() | ||
warehouse_model = self.env["stock.warehouse"] | ||
picking_model = self.env["stock.picking"] | ||
res = {} | ||
for group in self.picking_to_plan_ids.read_group( | ||
[ | ||
("release_channel_id", "=", self.id), | ||
("planned_shipment_advice_id", "=", False), | ||
("state", "=", "assigned"), | ||
], | ||
["warehouse_id"], | ||
["warehouse_id"], | ||
): | ||
warehouse = warehouse_model.browse(group.get("warehouse_id")[0]) | ||
res[warehouse] = picking_model.search(group.get("__domain")) | ||
return res | ||
|
||
def _plan_shipment_simple(self): | ||
shipment_advices = self.env["shipment.advice"] | ||
shipment_advice_model = self.env["shipment.advice"] | ||
can_plan_channels = self.filtered("can_plan_shipment") | ||
if not can_plan_channels: | ||
return shipment_advice_model | ||
for ( | ||
warehouse, | ||
pickings_to_plan, | ||
) in self._get_picking_to_plan_by_warehouse().items(): | ||
shipment_advices |= shipment_advice_model.create( | ||
self._prepare_shipment_advice_simple_vals_list( | ||
warehouse, pickings_to_plan | ||
) | ||
) | ||
return shipment_advices | ||
|
||
def _prepare_shipment_advice_simple_vals_list(self, warehouse, pickings_to_plan): | ||
return [ | ||
rec._prepare_shipment_advice_simple_vals(warehouse, pickings_to_plan) | ||
for rec in self | ||
] | ||
|
||
def _prepare_shipment_advice_simple_vals(self, warehouse, pickings_to_plan): | ||
vals = self._prepare_shipment_advice_common_vals(warehouse) | ||
vals["planned_move_ids"] = [Command.set(pickings_to_plan.move_ids.ids)] | ||
return vals | ||
|
||
def _prepare_shipment_advice_common_vals(self, warehouse): | ||
self.ensure_one() | ||
return { | ||
"release_channel_id": self.id, | ||
"shipment_type": "outgoing", | ||
"warehouse_id": warehouse.id, | ||
"company_id": warehouse.company_id.id, | ||
} | ||
|
||
@api.model | ||
def _get_shipment_planning_method_name(self, shipment_planning_method): | ||
return f"_plan_shipment_{shipment_planning_method}" |
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 @@ | ||
* Souheil Bejaoui <souheil.bejaoui@acsone.eu> |
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,5 @@ | ||
This module is used to plan the shipment advice for released pickings in a | ||
stock release channel. | ||
|
||
As this is the base module, it provides only a simple | ||
planning mode. All released pickings are grouped together in a single advice. |
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,5 @@ | ||
To use this module, you need to: | ||
|
||
#. Go to Inventory>Release Channels. | ||
#. Select a channel with released picking. | ||
#. Click on "Plan shipment" button. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.