-
-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] shipment_advice: Auto close incoming advice
If a move is done or cancelled the related incoming shipment advice will be set to done if all planned moves are done or cancelled Co-authored-by: vnikolayev1 <[email protected]>
- Loading branch information
1 parent
80f612f
commit cdfcf6d
Showing
9 changed files
with
132 additions
and
3 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
# Copyright 2021 Camptocamp SA | ||
# Copyright 2024 Michael Tietz (MT Software) <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) | ||
|
||
from odoo import fields, models | ||
|
@@ -23,3 +24,11 @@ class ResCompany(models.Model): | |
"deliveries will be shipped by several trucks." | ||
), | ||
) | ||
shipment_advice_auto_close_incoming = fields.Boolean( | ||
string="Shipment Advice: Auto Close Incoming Advices", | ||
help=( | ||
"This flag indicates if an incoming shipment advice " | ||
"will be automatically set to done " | ||
"if all related moves are done or cancelled" | ||
), | ||
) |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
# Copyright 2021 Camptocamp SA | ||
# Copyright 2024 Michael Tietz (MT Software) <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) | ||
|
||
from odoo import fields, models | ||
|
@@ -10,3 +11,6 @@ class ResConfigSettings(models.TransientModel): | |
shipment_advice_outgoing_backorder_policy = fields.Selection( | ||
related="company_id.shipment_advice_outgoing_backorder_policy", readonly=False | ||
) | ||
shipment_advice_auto_close_incoming = fields.Boolean( | ||
related="company_id.shipment_advice_auto_close_incoming", readonly=False | ||
) |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
# Copyright 2021 Camptocamp SA | ||
# Copyright 2024 Michael Tietz (MT Software) <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) | ||
|
||
from odoo import _, api, fields, models | ||
|
@@ -381,6 +382,8 @@ def _lock_records(self, records): | |
|
||
def action_done(self): | ||
wiz_model = self.env["stock.backorder.confirmation"] | ||
shipment_advice_ids_to_validate = [] | ||
self = self.with_context(shipment_advice_ignore_auto_close=True) | ||
for shipment in self: | ||
if shipment.state != "in_progress": | ||
raise UserError( | ||
|
@@ -432,10 +435,36 @@ def action_done(self): | |
lambda m: m.state not in ("cancel", "done") and not m.quantity_done | ||
) | ||
moves_to_unplan.shipment_advice_id = False | ||
shipment.departure_date = fields.Datetime.now() | ||
shipment.state = "done" | ||
shipment_advice_ids_to_validate.append(shipment.id) | ||
if shipment_advice_ids_to_validate: | ||
self.browse(shipment_advice_ids_to_validate)._action_done() | ||
return True | ||
|
||
def _action_done(self): | ||
self.write({"departure_date": fields.Datetime.now(), "state": "done"}) | ||
|
||
def _is_fully_done(self): | ||
self.ensure_one() | ||
if any(move.state not in ["cancel", "done"] for move in self.planned_move_ids): | ||
return False | ||
return True | ||
|
||
def auto_close_incoming_shipment_advices(self): | ||
"""Set incoming shipment advices to done when they all moves done or cancelled""" | ||
if self.env.context.get("shipment_advice_ignore_auto_close"): | ||
return | ||
shipment_ids_to_close = [] | ||
for shipment_advice in self: | ||
if ( | ||
shipment_advice.shipment_type != "incoming" | ||
or not shipment_advice.company_id.shipment_advice_auto_close_incoming | ||
or not shipment_advice._is_fully_done() | ||
): | ||
continue | ||
shipment_ids_to_close.append(shipment_advice.id) | ||
if shipment_ids_to_close: | ||
self.browse(shipment_ids_to_close)._action_done() | ||
|
||
def action_cancel(self): | ||
for shipment in self: | ||
if shipment.state not in ("confirmed", "in_progress"): | ||
|
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
# Copyright 2021 Camptocamp SA | ||
# Copyright 2024 Michael Tietz (MT Software) <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) | ||
|
||
from odoo import fields, models | ||
|
@@ -23,3 +24,13 @@ def _prepare_merge_moves_distinct_fields(self): | |
# Avoid having stock move assign to different shipment merged together | ||
res.append("shipment_advice_id") | ||
return res | ||
|
||
def _action_done(self, cancel_backorder=False): | ||
res = super()._action_done(cancel_backorder=cancel_backorder) | ||
res.shipment_advice_id.auto_close_incoming_shipment_advices() | ||
return res | ||
|
||
def _action_cancel(self): | ||
res = super()._action_cancel() | ||
self.shipment_advice_id.auto_close_incoming_shipment_advices() | ||
return res |
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 |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
* Simone Orsi <[email protected]> | ||
* `Trobz <https://trobz.com>`_: | ||
* Dung Tran <[email protected]> | ||
* Michael Tietz (MT Software) <[email protected]> | ||
|
||
Design | ||
~~~~~~ | ||
|
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
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,46 @@ | ||
# Copyright 2024 Michael Tietz (MT Software) <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) | ||
|
||
from .common import Common | ||
|
||
|
||
class TestShipmentAdviceAutoClose(Common): | ||
@classmethod | ||
def setUpClass(cls): | ||
super().setUpClass() | ||
cls.shipment_advice_in.company_id.shipment_advice_auto_close_incoming = True | ||
cls.picking1 = cls.move_product_in1.picking_id | ||
group = cls.env["procurement.group"].create({}) | ||
cls.move_product_in21 = cls._create_move( | ||
cls.picking_type_in, cls.product_in, 5, group | ||
) | ||
cls.picking2 = cls.move_product_in21.picking_id | ||
cls.pickings = cls.picking1 | cls.picking2 | ||
cls._plan_records_in_shipment(cls.shipment_advice_in, cls.pickings) | ||
cls._in_progress_shipment_advice(cls.shipment_advice_in) | ||
|
||
def test_auto_close_incoming_on_done(self): | ||
self._validate_picking(self.picking1) | ||
self.assertEqual(self.shipment_advice_in.state, "in_progress") | ||
self._validate_picking(self.picking2) | ||
self.assertEqual(self.shipment_advice_in.state, "done") | ||
|
||
def test_auto_close_incoming_on_cancel(self): | ||
self._validate_picking(self.picking1) | ||
self.assertEqual(self.shipment_advice_in.state, "in_progress") | ||
self.picking2.action_cancel() | ||
self.assertEqual(self.shipment_advice_in.state, "done") | ||
|
||
def test_no_auto_close_on_outgoing(self): | ||
picking = self.move_product_out1.picking_id | ||
self._plan_records_in_shipment(self.shipment_advice_out, picking) | ||
self._in_progress_shipment_advice(self.shipment_advice_out) | ||
self._validate_picking(picking) | ||
self.assertEqual(picking.state, "done") | ||
self.assertEqual(self.shipment_advice_out.state, "in_progress") | ||
|
||
def test_no_auto_close_context(self): | ||
pickings = self.pickings.with_context(shipment_advice_ignore_auto_close=True) | ||
for picking in pickings: | ||
self._validate_picking(picking) | ||
self.assertEqual(self.shipment_advice_in.state, "in_progress") |
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<!-- Copyright 2021 Camptocamp SA | ||
Copyright 2024 Michael Tietz (MT Software) <[email protected]> | ||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). --> | ||
<odoo> | ||
<record id="res_config_settings_view_form" model="ir.ui.view"> | ||
|
@@ -27,6 +28,19 @@ | |
<field name="shipment_advice_outgoing_backorder_policy" /> | ||
</div> | ||
</div> | ||
<div class="col-12 col-lg-6 o_setting_box"> | ||
<div class="o_setting_left_pane"> | ||
<field name="shipment_advice_auto_close_incoming" /> | ||
</div> | ||
<div class="o_setting_right_pane"> | ||
<label for="shipment_advice_auto_close_incoming" /> | ||
<div class="text-muted"> | ||
This flag indicates if an incoming shipment advice | ||
will be automatically set to done | ||
if all related moves are done or cancelled | ||
</div> | ||
</div> | ||
</div> | ||
</xpath> | ||
</field> | ||
</record> | ||
|