Skip to content

Commit

Permalink
[ADD][REF] shipment_advice
Browse files Browse the repository at this point in the history
- modified shipment_advice, so it has validate_when_fully_done method that sets shipment to done if its moves are in "done" state, updated tests.
  • Loading branch information
vnikolayev1 committed Jun 10, 2024
1 parent 6c247ac commit 5057166
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 3 deletions.
21 changes: 19 additions & 2 deletions shipment_advice/models/shipment_advice.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,10 +432,27 @@ 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._action_done()
return True

def _action_done(self):
self.ensure_one()
self.write({"departure_date": fields.Datetime.now(), "state": "done"})

def _is_fully_done(self):
self.ensure_one()
for move in self.planned_move_ids:
if move.state not in ["cancel", "done"]:
return False
return True

def validate_when_fully_done(self):
"""set the shipment advice to done if all the planned_move_ids
are done or cancel"""
for shipment in self:
if shipment._is_fully_done():
shipment._action_done()

def action_cancel(self):
for shipment in self:
if shipment.state not in ("confirmed", "in_progress"):
Expand Down
2 changes: 1 addition & 1 deletion shipment_advice/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def _plan_records_in_shipment(self, shipment_advice, records, user=None):
return wiz

def _load_records_in_shipment(self, shipment_advice, records, user=None):
"""Load pickings, move lines or package levels in the givent shipment."""
"""Load pickings, move lines or package levels in the given shipment."""
wiz_model = self.env["wizard.load.shipment"].with_context(
active_model=records._name,
active_ids=records.ids,
Expand Down
48 changes: 48 additions & 0 deletions shipment_advice/tests/test_shipment_advice.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,3 +246,51 @@ def test_shipment_advice_draft(self):
def test_shipment_name(self):
self.assertTrue("OUT" in self.shipment_advice_out.name)
self.assertTrue("IN" in self.shipment_advice_in.name)

def test_shipment_advice_recieve_partial_move_backorder(self):
picking = self.move_product_in1.picking_id
# Plan a move
self._plan_records_in_shipment(self.shipment_advice_in, self.move_product_in1)
self._in_progress_shipment_advice(self.shipment_advice_in)
# Partially receive the move and create a backorder
for ml in self.move_product_in1.move_line_ids:
ml.qty_done = ml.product_uom_qty - 2
wizard = (
self.env["stock.backorder.confirmation"]
.with_context(button_validate_picking_ids=picking.ids)
.create({"pick_ids": [(6, 0, picking.ids)]})
)
wizard.process()
# New move created should not be included in the processing shipment
backorder_picking = self.env["stock.picking"].search(
[("backorder_id", "=", picking.id)]
)
self.assertFalse(backorder_picking.move_lines.shipment_advice_id)

def test_validate_shipment_advice_when_fully_done(self):
picking = self._prepare_picking_with_two_packages()
line1, line2 = picking.move_line_ids
# Load first package in shipment advice 2
pl1 = line1.package_level_id
self._in_progress_shipment_advice(self.shipment_advice_out)
self.assertEqual(self.shipment_advice_out.state, "in_progress")
self._load_records_in_shipment(self.shipment_advice_out, pl1)
pl2 = line2.package_level_id
# Load second package into shipment advice
self._load_records_in_shipment(self.shipment_advice_out, pl2)
# Assign planned move_ids that are assigned to test function
self.shipment_advice_out.planned_move_ids = line2.move_id + line1.move_id
self.assertEqual(line1.move_id.state, "assigned")
self.assertEqual(line2.move_id.state, "assigned")
self.assertEqual(self.shipment_advice_out.state, "in_progress")
# Validating if moves in "incorrect" states do not trigger _action_done()
self.shipment_advice_out.validate_when_fully_done()
self.assertEqual(self.shipment_advice_out.state, "in_progress")
# Validating if moves in one "incorrect" state do not trigger _action_done()
line1.move_id.state = "done"
self.shipment_advice_out.validate_when_fully_done()
self.assertEqual(self.shipment_advice_out.state, "in_progress")
line2.move_id.state = "done"
self.shipment_advice_out.validate_when_fully_done()
self.assertEqual(self.shipment_advice_out.state, "done")
self.assertEqual(picking.state, "done")

0 comments on commit 5057166

Please sign in to comment.