Skip to content

Commit

Permalink
Merge PR #1744 into 16.0
Browse files Browse the repository at this point in the history
Signed-off-by rousseldenis
  • Loading branch information
OCA-git-bot committed Oct 15, 2024
2 parents b4b00c0 + 2d4afe2 commit a2f122a
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 6 deletions.
6 changes: 4 additions & 2 deletions stock_picking_group_by_max_weight/models/stock_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ class StockPicking(models.Model):
def _assignation_max_weight_precision(self):
return self._fields["assignation_max_weight"].get_digits(self.env)[1]

@api.depends("picking_type_id.group_pickings_maxweight", "weight", "state")
@api.depends("picking_type_id", "weight", "state")
def _compute_assignation_max_weight(self):
precision_digits = self._assignation_max_weight_precision
for picking in self:
for picking in self.filtered(
lambda picking: picking.state not in ("draft", "done", "cancel")
):
max_weight = (
picking.picking_type_id.group_pickings_maxweight - picking.weight
)
Expand Down
58 changes: 54 additions & 4 deletions stock_picking_group_by_max_weight/tests/test_group_maxweight.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Copyright 2023 ACSONE SA/NV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo.tests.common import Form, TransactionCase
from odoo.tests.common import Form

from odoo.addons.base.tests.common import BaseCommon

class TestGroupMaxWeight(TransactionCase):

class TestGroupMaxWeight(BaseCommon):
@classmethod
def setUpClass(cls):
super().setUpClass()

cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True))
cls.partner = cls.env["res.partner"].create({"name": "Test Partner"})
cls.product = cls.env.ref("product.product_delivery_01")
cls.product_2 = cls.env.ref("product.product_delivery_02")
Expand All @@ -33,6 +33,9 @@ def _get_new_sale_order(self, amount=10.0, partner=None):
sale = sale_form.save()
return sale

def test_init(self):
self.env["stock.picking"].init()

def test_group_max_weight(self):
"""
Create a Sale order with first product
Expand All @@ -58,6 +61,53 @@ def test_group_max_weight(self):

self.assertEqual(2, len(sale.picking_ids))

def test_group_max_weight_change_parameter(self):
"""
Create a Sale order with first product
Confirm the Sale Order
Add a new product
New move should be assigned to a new picking
Create inventory quantity
Assign the picking
"""
self.product.weight = 6.0
self.product_2.weight = 3.0
self.product_3.weight = 9.0
sale = self._get_new_sale_order(amount=1.0)
sale.action_confirm()
self.assertEqual(1, len(sale.picking_ids))
picking_1 = sale.picking_ids
self.assertEqual(2.0, sale.picking_ids.assignation_max_weight)
with Form(sale) as sale_form:
self._set_line(sale_form, self.product_2, 1.0)
self.assertEqual(2, len(sale.picking_ids))

# Change the strategy, check if the number of pickings still == 2
self.picking_type_out.group_pickings_maxweight = 0
with Form(sale) as sale_form:
self._set_line(sale_form, self.product_3, 1.0)

self.assertEqual(2, len(sale.picking_ids))

self.env["stock.quant"].with_context(inventory_mode=True).create(
{
"product_id": self.product.id,
"inventory_quantity": 50.0,
"location_id": self.env.ref("stock.stock_location_stock").id,
}
)._apply_inventory()

picking_1.action_assign()
self.assertEqual("assigned", picking_1.state)
for line in picking_1.move_line_ids:
line.qty_done = line.reserved_qty
picking_1._action_done()

self.picking_type_out.group_pickings_maxweight = 2.0

self.assertEqual(2.0, picking_1.assignation_max_weight)

def test_group_max_weight_several_quantities(self):
"""
Create a Sale order with first product
Expand Down

0 comments on commit a2f122a

Please sign in to comment.