Skip to content

Commit

Permalink
fixup! Add stock_split_picking_kit
Browse files Browse the repository at this point in the history
  • Loading branch information
TDu committed Jan 17, 2025
1 parent 988cd51 commit 3489641
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 53 deletions.
8 changes: 7 additions & 1 deletion stock_split_picking_kit/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ Stock Split Picking Kit

This module adds a new splitting mode to the `stock_split_picking` module.

The new mode `Quantity of kits` allows to split a transfer by a specified number of kits.
The new mode `Quantity of kits` allows splitting a transfer by a specified number of kits.
A new field on the wizard also allows specifying a sort order for the stock moves before
splitting the transfer.

Multi level boms are not supported.

**Table of contents**

Expand All @@ -54,12 +58,14 @@ Authors
~~~~~~~

* Camptocamp
* BCIM
*

Contributors
~~~~~~~~~~~~

* Thierry Ducrest <[email protected]>
* Jacques-Etienne Baudoux (BCIM) <[email protected]>

Maintainers
~~~~~~~~~~~
Expand Down
2 changes: 1 addition & 1 deletion stock_split_picking_kit/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"summary": "Split a picking by a number of kits.",
"version": "14.0.1.0.0",
"category": "Inventory",
"author": "Camptocamp, " "Odoo Community Association (OCA),",
"author": "Camptocamp, BCIM, Odoo Community Association (OCA),",
"license": "AGPL-3",
"website": "https://github.com/OCA/stock-logistics-workflow",
"depends": ["stock_split_picking", "mrp"],
Expand Down
1 change: 1 addition & 0 deletions stock_split_picking_kit/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
* Thierry Ducrest <[email protected]>
* Jacques-Etienne Baudoux (BCIM) <[email protected]>
6 changes: 4 additions & 2 deletions stock_split_picking_kit/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
This module adds a new splitting mode to the `stock_split_picking` module.

The new mode `Quantity of kits` allows to split a transfer by a specified number of kits.
A new field on the wizard also allows specify a sort order for the stock moves before
The new mode `Quantity of kits` allows splitting a transfer by a specified number of kits.
A new field on the wizard also allows specifying a sort order for the stock moves before
splitting the transfer.

Multi level boms are not supported.
7 changes: 6 additions & 1 deletion stock_split_picking_kit/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,10 @@ <h1 class="title">Stock Split Picking Kit</h1>
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/stock-logistics-workflow/tree/14.0/stock_split_picking_kit"><img alt="OCA/stock-logistics-workflow" src="https://img.shields.io/badge/github-OCA%2Fstock--logistics--workflow-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/stock-logistics-workflow-14-0/stock-logistics-workflow-14-0-stock_split_picking_kit"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/stock-logistics-workflow&amp;target_branch=14.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module adds a new splitting mode to the <cite>stock_split_picking</cite> module.</p>
<p>The new mode <cite>Quantity of kits</cite> allows to split a transfer by a specified number of kits.</p>
<p>The new mode <cite>Quantity of kits</cite> allows splitting a transfer by a specified number of kits.
A new field on the wizard also allows specifying a sort order for the stock moves before
splitting the transfer.</p>
<p>Multi level boms are not supported.</p>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
Expand All @@ -398,13 +401,15 @@ <h1><a class="toc-backref" href="#toc-entry-2">Credits</a></h1>
<h2><a class="toc-backref" href="#toc-entry-3">Authors</a></h2>
<ul class="simple">
<li>Camptocamp</li>
<li>BCIM</li>
<li></li>
</ul>
</div>
<div class="section" id="contributors">
<h2><a class="toc-backref" href="#toc-entry-4">Contributors</a></h2>
<ul class="simple">
<li>Thierry Ducrest &lt;<a class="reference external" href="mailto:thierry.ducrest&#64;camptocamp.com">thierry.ducrest&#64;camptocamp.com</a>&gt;</li>
<li>Jacques-Etienne Baudoux (BCIM) &lt;<a class="reference external" href="mailto:je&#64;bcim.be">je&#64;bcim.be</a>&gt;</li>
</ul>
</div>
<div class="section" id="maintainers">
Expand Down
45 changes: 4 additions & 41 deletions stock_split_picking_kit/tests/test_stock_split_picking_kit.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,6 @@ def setUpClass(cls):
cls.partner = cls.env["res.partner"].create({"name": "Test partner"})
cls.product_model = cls.env["product.product"]

# TODO: How should we handle kit with multiple level
# cls.product_garden_furniture = cls.product_model.create(
# {
# "name": "GARDEN FURNITURE",
# "type": "product",
# "sale_ok": False,
# "purchase_ok": True,
# }
# )
# cls.tmpl_garden_furniture = cls.product_garden_furniture.product_tmpl_id
# cls.product_garden_chair = cls.product_model.create(
# {
# "name": "GARDEN CHAIR",
# "type": "product",
# "sale_ok": True,
# "purchase_ok": True,
# }
# )
cls.product_garden_table = cls.product_model.create(
{
"name": "GARDEN TABLE",
Expand Down Expand Up @@ -86,25 +68,6 @@ def setUpClass(cls):
],
}
)
# cls.bom_garden_furniture = cls.bom_model.create(
# {
# "product_tmpl_id": cls.tmpl_garden_furniture.id,
# "product_id": cls.product_garden_furniture.id,
# "type": "phantom",
# "bom_line_ids": [
# (
# 0,
# 0,
# {"product_id": cls.product_garden_chair.id, "product_qty": 4.0},
# ),
# (
# 0,
# 0,
# {"product_id": cls.product_garden_table.id, "product_qty": 1.0},
# ),
# ],
# }
# )

@classmethod
def _create_picking(cls, lines):
Expand All @@ -129,13 +92,13 @@ def _get_picking_ids_from_action(self, res, expected_quantity):
def _get_kit_quantity(cls, picking, bom):
"""Returns the quantity of kits in a transfer."""
filters = {
"incoming_moves": lambda m: m.location_id.usage == "supplier",
"outgoing_moves": lambda m: m.location_id.usage != "supplier",
"incoming_moves": lambda m: True,
"outgoing_moves": lambda m: False,
}
kit_quantity = picking.move_lines._compute_kit_quantities(
bom.product_id, 100, bom, filters
bom.product_id, max(picking.move_lines.mapped("product_qty")), bom, filters
)
return abs(kit_quantity)
return kit_quantity

def _check_move_lines(self, picking, move_lines):
moves = []
Expand Down
13 changes: 6 additions & 7 deletions stock_split_picking_kit/wizards/stock_split_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ class StockSplitPicking(models.TransientModel):

def _apply_kit_quantity(self):
pickings = self.env["stock.picking"]

Check warning on line 19 in stock_split_picking_kit/wizards/stock_split_picking.py

View check run for this annotation

Codecov / codecov/patch

stock_split_picking_kit/wizards/stock_split_picking.py#L19

Added line #L19 was not covered by tests
for picking in self.mapped("picking_ids"):
for picking in self.picking_ids:
pickings |= self._split_by_kit_quantity(picking)
return self._picking_action(pickings)

Check warning on line 22 in stock_split_picking_kit/wizards/stock_split_picking.py

View check run for this annotation

Codecov / codecov/patch

stock_split_picking_kit/wizards/stock_split_picking.py#L21-L22

Added lines #L21 - L22 were not covered by tests

def _split_by_kit_quantity(self, picking):
filters = {
"incoming_moves": lambda m: m.location_id.usage == "supplier",
"outgoing_moves": lambda m: m.location_id.usage != "supplier",
"incoming_moves": lambda m: True,
"outgoing_moves": lambda m: False,
}
move_lines = picking.move_lines
move_lines = picking.move_lines.filtered(lambda m: m.state not in ["done", "cancel"])
if self.split_kit_order_move:
move_lines = move_lines.sorted(self.split_kit_order_move)
moves_to_backorder = self.env["stock.move"]
Expand All @@ -48,7 +48,7 @@ def _split_by_kit_quantity(self, picking):
# Non kit moves, their quantity is the number of slots used
for move in moves:
quantity = move.product_qty

Check warning on line 50 in stock_split_picking_kit/wizards/stock_split_picking.py

View check run for this annotation

Codecov / codecov/patch

stock_split_picking_kit/wizards/stock_split_picking.py#L50

Added line #L50 was not covered by tests
if available_slots >= move.product_qty:
if available_slots >= quantity:
used_slots += quantity
available_slots = max_slots - used_slots

Check warning on line 53 in stock_split_picking_kit/wizards/stock_split_picking.py

View check run for this annotation

Codecov / codecov/patch

stock_split_picking_kit/wizards/stock_split_picking.py#L52-L53

Added lines #L52 - L53 were not covered by tests
elif available_slots <= 0:
Expand All @@ -67,7 +67,6 @@ def _split_by_kit_quantity(self, picking):
bom,
filters,
)
kit_quantity = abs(kit_quantity)
if kit_quantity <= available_slots:
used_slots += kit_quantity

Check warning on line 71 in stock_split_picking_kit/wizards/stock_split_picking.py

View check run for this annotation

Codecov / codecov/patch

stock_split_picking_kit/wizards/stock_split_picking.py#L71

Added line #L71 was not covered by tests
else:
Expand All @@ -82,7 +81,7 @@ def _split_by_kit_quantity(self, picking):
if moves_to_backorder:
new_picking = picking._create_split_backorder()
moves_to_backorder.write({"picking_id": new_picking.id})
moves_to_backorder.mapped("move_line_ids").write(
moves_to_backorder.move_line_ids.write(

Check warning on line 84 in stock_split_picking_kit/wizards/stock_split_picking.py

View check run for this annotation

Codecov / codecov/patch

stock_split_picking_kit/wizards/stock_split_picking.py#L82-L84

Added lines #L82 - L84 were not covered by tests
{"picking_id": new_picking.id}
)

Expand Down

0 comments on commit 3489641

Please sign in to comment.