-
-
Notifications
You must be signed in to change notification settings - Fork 128
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 processed the related incoming shipment advice will be set to done if all planned moves are done or canceled
- Loading branch information
1 parent
a595054
commit 4858531
Showing
9 changed files
with
134 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 | ||
|
@@ -29,3 +30,11 @@ class ResCompany(models.Model): | |
"shipment advice validation through a queued jobs. Each picking will be " | ||
"validated in a separate job.", | ||
) | ||
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 canceled" | ||
), | ||
) |
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 | ||
|
@@ -13,3 +14,6 @@ class ResConfigSettings(models.TransientModel): | |
shipment_advice_run_in_queue_job = fields.Boolean( | ||
related="company_id.shipment_advice_run_in_queue_job", 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 | ||
|
@@ -313,6 +314,7 @@ def _lock_records(self, records): | |
|
||
def action_done(self): | ||
self._check_action_done_allowed() | ||
self = self.with_context(shipment_advice_ignore_auto_close=True) | ||
for shipment in self: | ||
shipment._action_done() | ||
return True | ||
|
@@ -416,8 +418,12 @@ def _postprocess_action_done(self): | |
} | ||
) | ||
return | ||
if not self.departure_date: | ||
self.departure_date = fields.Datetime.now() | ||
self._close_shipments() | ||
|
||
def _close_shipments(self): | ||
for shipment in self: | ||
if not shipment.departure_date: | ||
shipment.departure_date = fields.Datetime.now() | ||
self.write({"state": "done", "error_message": False}) | ||
|
||
@api.model | ||
|
@@ -428,6 +434,25 @@ def _get_error_message(self, error, related_object): | |
error=str(error), | ||
) | ||
|
||
def auto_close_incoming_shipment_advices(self): | ||
"""Set incoming shipment advice to done when all planned moves are processed""" | ||
if self.env.context.get("shipment_advice_ignore_auto_close"): | ||
return | ||
shipment_ids_to_close = [] | ||
for shipment in self: | ||
if ( | ||
shipment.shipment_type != "incoming" | ||
or not shipment.company_id.shipment_advice_auto_close_incoming | ||
or any( | ||
move.state not in ("cancel", "done") | ||
for move in shipment.planned_move_ids | ||
) | ||
): | ||
continue | ||
shipment_ids_to_close.append(shipment.id) | ||
if shipment_ids_to_close: | ||
self.browse(shipment_ids_to_close)._close_shipments() | ||
|
||
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 | ||
|
@@ -24,3 +25,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.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.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"> | ||
|
@@ -44,6 +45,23 @@ | |
</div> | ||
</div> | ||
</div> | ||
<div | ||
class="col-12 col-lg-6 o_setting_box" | ||
id="shipment_advice_auto_close_incoming" | ||
title="shipment_advice_auto_close_incoming" | ||
> | ||
<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 canceled | ||
</div> | ||
</div> | ||
</div> | ||
</xpath> | ||
</field> | ||
</record> | ||
|