Skip to content

Commit

Permalink
[MIG] stock_picking_return_lot: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
peluko00 committed Oct 18, 2024
1 parent 83dba5c commit 0099571
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 23 deletions.
4 changes: 4 additions & 0 deletions stock_picking_return_lot/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ Contributors

- Souheil Bejaoui <souheil.bejaoui@acsone.eu>

- `APSL-Nagarro <https://apsl.tech>`__:

- Antoni Marroig <amarroig@apsl.net>

Maintainers
-----------

Expand Down
2 changes: 1 addition & 1 deletion stock_picking_return_lot/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{
"name": "Stock Picking Return Lot",
"summary": "Propagate SN/lots from origin picking to return picking.",
"version": "16.0.1.1.0",
"version": "17.0.1.0.0",
"license": "AGPL-3",
"author": "Camptocamp, ACSONE SA/NV, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/stock-logistics-workflow",
Expand Down
2 changes: 2 additions & 0 deletions stock_picking_return_lot/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@
- Foresti Francesco \<<francesco.foresti@ooops404.com>\>
- [ACSONE SA/NV](https://www.acsone.eu):
- Souheil Bejaoui \<<souheil.bejaoui@acsone.eu>\>
- [APSL-Nagarro](https://apsl.tech):
- Antoni Marroig \<<amarroig@apsl.net>\>
4 changes: 4 additions & 0 deletions stock_picking_return_lot/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,10 @@ <h2><a class="toc-backref" href="#toc-entry-4">Contributors</a></h2>
<li>Souheil Bejaoui &lt;<a class="reference external" href="mailto:souheil.bejaoui&#64;acsone.eu">souheil.bejaoui&#64;acsone.eu</a>&gt;</li>
</ul>
</li>
<li><a class="reference external" href="https://apsl.tech">APSL-Nagarro</a>:<ul>
<li>Antoni Marroig &lt;<a class="reference external" href="mailto:amarroig&#64;apsl.net">amarroig&#64;apsl.net</a>&gt;</li>
</ul>
</li>
</ul>
</div>
<div class="section" id="maintainers">
Expand Down
10 changes: 2 additions & 8 deletions stock_picking_return_lot/tests/test_stock_picking_return_lot.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ def setUpClass(cls):
}
)
cls.picking.action_confirm()
cls.picking.action_assign()
cls.picking.action_set_quantities_to_reservation()
cls.picking.move_ids.picked = True
cls.picking._action_done()

@classmethod
Expand Down Expand Up @@ -101,14 +100,12 @@ def _create_picking(self, product=None):
def _create_validate_picking(self):
picking = self._create_picking()
picking.action_confirm()
picking.action_assign()
picking.action_set_quantities_to_reservation()
picking.move_ids.picked = True
picking._action_done()
return picking

def test_partial_return(self):
wiz = self.create_return_wiz(self.picking)
wiz._onchange_picking_id()
self.assertEqual(len(wiz.product_return_moves), 2)
return_line_1 = wiz.product_return_moves.filtered(
lambda m, lot=self.lot_1: m.lot_id == lot
Expand All @@ -134,7 +131,6 @@ def test_partial_return(self):
def test_full_return_after_partial_return(self):
self.test_partial_return()
wiz = self.create_return_wiz(self.picking)
wiz._onchange_picking_id()
self.assertEqual(len(wiz.product_return_moves), 2)

return_line_1 = wiz.product_return_moves.filtered(
Expand Down Expand Up @@ -166,7 +162,6 @@ def test_multiple_move_same_product_different_lot(self):
)
picking = self._create_validate_picking()
wiz = self.create_return_wiz(picking)
wiz._onchange_picking_id()
self.assertEqual(len(wiz.product_return_moves), 2)
return_line_1 = wiz.product_return_moves.filtered(
lambda m, lot=self.lot_1: m.lot_id == lot
Expand Down Expand Up @@ -194,7 +189,6 @@ def test_multiple_move_same_product_same_lot(self):
)
picking = self._create_validate_picking()
wiz = self.create_return_wiz(picking)
wiz._onchange_picking_id()
self.assertEqual(len(wiz.product_return_moves), 2)
return_lines = wiz.product_return_moves.filtered(
lambda m, lot=self.lot_1: m.lot_id == lot
Expand Down
26 changes: 13 additions & 13 deletions stock_picking_return_lot/wizards/stock_return_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,47 +11,47 @@
class ReturnPicking(models.TransientModel):
_inherit = "stock.return.picking"

def _get_qty_done_by_product_lot(self):
def _get_qty_by_product_lot(self):
res = defaultdict(float)
for group in self.env["stock.move.line"].read_group(
[
("picking_id", "=", self.picking_id.id),
("state", "=", "done"),
("move_id.scrapped", "=", False),
],
["qty_done:sum"],
["quantity:sum"],
["move_id", "lot_id"],
lazy=False,
):
lot_id = group.get("lot_id")[0] if group.get("lot_id") else False
move_id = group.get("move_id")[0]
qty_done = group.get("qty_done")
res[(move_id, lot_id)] += qty_done
quantity = group.get("quantity")
res[(move_id, lot_id)] += quantity
return res

@api.onchange("picking_id")
def _onchange_picking_id(self):
res = super()._onchange_picking_id()
@api.depends("picking_id")
def _compute_moves_locations(self):
res = super()._compute_moves_locations()
product_return_moves = [(5,)]
line_fields = [f for f in self.env["stock.return.picking.line"]._fields.keys()]
product_return_moves_data_tmpl = self.env[
"stock.return.picking.line"
].default_get(line_fields)
qty_done_by_product_lot = self._get_qty_done_by_product_lot()
for (move_id, lot_id), qty_done in qty_done_by_product_lot.items():
qty_by_product_lot = self._get_qty_by_product_lot()
for (move_id, lot_id), quantity in qty_by_product_lot.items():
product_return_moves_data = dict(product_return_moves_data_tmpl)
product_return_moves_data.update(
self._prepare_stock_return_picking_line_vals(move_id, lot_id, qty_done)
self._prepare_stock_return_picking_line_vals(move_id, lot_id, quantity)
)
product_return_moves.append((0, 0, product_return_moves_data))
if self.picking_id:
self.product_return_moves = product_return_moves
return res

@api.model
def _prepare_stock_return_picking_line_vals(self, move_id, lot_id, qty_done):
def _prepare_stock_return_picking_line_vals(self, move_id, lot_id, quantity):
move = self.env["stock.move"].browse(move_id)
quantity = qty_done
quantity = quantity
for dest_move in move.move_dest_ids:
if (
not dest_move.origin_returned_move_id
Expand All @@ -65,7 +65,7 @@ def _prepare_stock_return_picking_line_vals(self, move_id, lot_id, qty_done):
or not lot_id
):
if dest_move.state in ("partially_available", "assigned"):
quantity -= sum(dest_move.move_line_ids.mapped("reserved_qty"))
quantity -= sum(dest_move.move_line_ids.mapped("quantity"))
elif dest_move.state == "done":
quantity -= dest_move.product_qty

Check warning on line 70 in stock_picking_return_lot/wizards/stock_return_picking.py

View check run for this annotation

Codecov / codecov/patch

stock_picking_return_lot/wizards/stock_return_picking.py#L70

Added line #L70 was not covered by tests
quantity = float_round(
Expand Down
2 changes: 1 addition & 1 deletion stock_picking_return_lot/wizards/stock_return_picking.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<field
name="lot_id"
groups="stock.group_production_lot"
attrs="{'invisible': [('lots_visible', '=', False)]}"
invisible="not lots_visible"
/>
</xpath>
</field>
Expand Down

0 comments on commit 0099571

Please sign in to comment.