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

[14.0][FIX] shipment_advice: do not copy shipment advice id on moves #123

Open
wants to merge 2 commits into
base: 14.0
Choose a base branch
from
Open
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
7 changes: 7 additions & 0 deletions shipment_advice/models/stock_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class StockMove(models.Model):
ondelete="set null",
string="Planned shipment",
index=True,
copy=False,
)

def _plan_in_shipment(self, shipment_advice):
Expand All @@ -23,3 +24,9 @@ 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 _prepare_move_split_vals(self, qty):
vals = super()._prepare_move_split_vals(qty)
if self.env.context.get("shipment_advice__propagate_on_split"):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TDu @jbaudoux Why this key of context ?

Shouldn't it be possible to use the stock rule that has created the move and a property on it to do the same ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just as Information, we discussed this topic some weeks ago and there was no scenario where the id should not be copied. All of the cases in shopfloor as example would need the value.
So i think we should close this one.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that this PR is not used on customer projects, I would say it can be closed.
Although I think the copy=False makes some sense.

vals.update(shipment_advice_id=self.shipment_advice_id.id)
return vals
1 change: 1 addition & 0 deletions shipment_advice/models/stock_move_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class StockMoveLine(models.Model):
ondelete="set null",
string="Shipment advice",
index=True,
copy=False,
)

def button_load_in_shipment(self):
Expand Down
34 changes: 34 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,37 @@ 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_receive_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_move_split_propagation(self):
"""Check the use of conext key to propagate the shipment id on move split."""
move = self.move_product_in1
self._plan_records_in_shipment(self.shipment_advice_in, move)
self.assertTrue(move.shipment_advice_id)
# Without the context key the shipment advice id is not copied
vals = move._prepare_move_split_vals(1)
self.assertTrue("shipemnt_advice_id" not in vals.keys())
# But it is with the context key
vals = move.with_context(
shipment_advice__propagate_on_split=True
)._prepare_move_split_vals(1)
self.assertTrue("shipment_advice_id" in vals.keys())
Loading