|
|
|
|
@@ -9,68 +9,33 @@ class TestStockQuantManualAssign(TransactionCase):
|
|
|
|
|
@classmethod
|
|
|
|
|
def setUpClass(cls):
|
|
|
|
|
super().setUpClass()
|
|
|
|
|
cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True))
|
|
|
|
|
cls.quant_model = cls.env["stock.quant"]
|
|
|
|
|
cls.picking_model = cls.env["stock.picking"]
|
|
|
|
|
cls.location_model = cls.env["stock.location"]
|
|
|
|
|
cls.move_model = cls.env["stock.move"]
|
|
|
|
|
cls.quant_assign_wizard = cls.env["assign.manual.quants"]
|
|
|
|
|
cls.ModelDataObj = cls.env["ir.model.data"]
|
|
|
|
|
cls.product = cls.env["product.product"].create(
|
|
|
|
|
{"name": "Product 4 test", "type": "product"}
|
|
|
|
|
)
|
|
|
|
|
cls.location_src = cls.env.ref("stock.stock_location_locations_virtual")
|
|
|
|
|
cls.location_dst = cls.env.ref("stock.stock_location_customers")
|
|
|
|
|
cls.picking_type_out = cls.ModelDataObj._xmlid_to_res_id(
|
|
|
|
|
cls.picking_type_out = cls.env["ir.model.data"]._xmlid_to_res_id(
|
|
|
|
|
"stock.picking_type_out"
|
|
|
|
|
)
|
|
|
|
|
cls.env["stock.picking.type"].browse(
|
|
|
|
|
cls.picking_type_out
|
|
|
|
|
).reservation_method = "manual"
|
|
|
|
|
cls.location1 = cls.location_model.create(
|
|
|
|
|
{
|
|
|
|
|
"name": "Location 1",
|
|
|
|
|
"usage": "internal",
|
|
|
|
|
"location_id": cls.location_src.id,
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
cls.location2 = cls.location_model.create(
|
|
|
|
|
{
|
|
|
|
|
"name": "Location 2",
|
|
|
|
|
"usage": "internal",
|
|
|
|
|
"location_id": cls.location_src.id,
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
cls.location3 = cls.location_model.create(
|
|
|
|
|
{
|
|
|
|
|
"name": "Location 3",
|
|
|
|
|
"usage": "internal",
|
|
|
|
|
"location_id": cls.location_src.id,
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
cls.location1 = cls._create_location(cls, "Location 1")
|
|
|
|
|
cls.location2 = cls._create_location(cls, "Location 2")
|
|
|
|
|
cls.location3 = cls._create_location(cls, "Location 3")
|
|
|
|
|
cls.picking_type = cls.env.ref("stock.picking_type_out")
|
|
|
|
|
cls.quant1 = cls.quant_model.sudo().create(
|
|
|
|
|
cls.quant1 = cls._create_quant(cls, cls.product, 100.0, cls.location1)
|
|
|
|
|
cls.quant2 = cls._create_quant(cls, cls.product, 100.0, cls.location2)
|
|
|
|
|
cls.quant3 = cls._create_quant(cls, cls.product, 100.0, cls.location3)
|
|
|
|
|
cls.picking = cls.env["stock.picking"].create(
|
|
|
|
|
{
|
|
|
|
|
"product_id": cls.product.id,
|
|
|
|
|
"quantity": 100.0,
|
|
|
|
|
"picking_type_id": cls.picking_type.id,
|
|
|
|
|
"location_id": cls.location1.id,
|
|
|
|
|
"location_dest_id": cls.location_dst.id,
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
cls.quant2 = cls.quant_model.sudo().create(
|
|
|
|
|
{
|
|
|
|
|
"product_id": cls.product.id,
|
|
|
|
|
"quantity": 100.0,
|
|
|
|
|
"location_id": cls.location2.id,
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
cls.quant3 = cls.quant_model.sudo().create(
|
|
|
|
|
{
|
|
|
|
|
"product_id": cls.product.id,
|
|
|
|
|
"quantity": 100.0,
|
|
|
|
|
"location_id": cls.location3.id,
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
cls.move = cls.move_model.create(
|
|
|
|
|
cls.move = cls.env["stock.move"].create(
|
|
|
|
|
{
|
|
|
|
|
"name": cls.product.name,
|
|
|
|
|
"product_id": cls.product.id,
|
|
|
|
|
@@ -78,15 +43,40 @@ class TestStockQuantManualAssign(TransactionCase):
|
|
|
|
|
"product_uom": cls.product.uom_id.id,
|
|
|
|
|
"location_id": cls.location_src.id,
|
|
|
|
|
"location_dest_id": cls.location_dst.id,
|
|
|
|
|
"picking_type_id": cls.picking_type.id,
|
|
|
|
|
"picking_id": cls.picking.id,
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
cls.move._action_confirm()
|
|
|
|
|
|
|
|
|
|
def test_quant_assign_wizard(self):
|
|
|
|
|
wizard = self.quant_assign_wizard.with_context(active_id=self.move.id).create(
|
|
|
|
|
{}
|
|
|
|
|
def _create_location(self, name):
|
|
|
|
|
return self.env["stock.location"].create(
|
|
|
|
|
{"name": name, "usage": "internal", "location_id": self.location_src.id}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
def _create_quant(self, product, qty, location):
|
|
|
|
|
return (
|
|
|
|
|
self.env["stock.quant"]
|
|
|
|
|
.sudo()
|
|
|
|
|
.create(
|
|
|
|
|
{"product_id": product.id, "quantity": qty, "location_id": location.id}
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
def _create_wizard(self):
|
|
|
|
|
return (
|
|
|
|
|
self.env["assign.manual.quants"]
|
|
|
|
|
.with_context(active_id=self.move.id)
|
|
|
|
|
.create({})
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
def _process_basic_manual_assign_steps(self, wizard):
|
|
|
|
|
wizard.quants_lines[0].write({"selected": True})
|
|
|
|
|
wizard.quants_lines[0]._onchange_selected()
|
|
|
|
|
wizard.quants_lines[1].write({"selected": True, "qty": 50.0})
|
|
|
|
|
self.assertEqual(wizard.lines_qty, 150.0)
|
|
|
|
|
|
|
|
|
|
def test_quant_assign_wizard(self):
|
|
|
|
|
wizard = self._create_wizard()
|
|
|
|
|
self.assertEqual(
|
|
|
|
|
len(wizard.quants_lines.ids),
|
|
|
|
|
3,
|
|
|
|
|
@@ -105,9 +95,7 @@ class TestStockQuantManualAssign(TransactionCase):
|
|
|
|
|
self.assertEqual(wizard.move_qty, self.move.product_uom_qty)
|
|
|
|
|
|
|
|
|
|
def test_quant_assign_wizard_constraint(self):
|
|
|
|
|
wizard = self.quant_assign_wizard.with_context(active_id=self.move.id).create(
|
|
|
|
|
{}
|
|
|
|
|
)
|
|
|
|
|
wizard = self._create_wizard()
|
|
|
|
|
self.assertEqual(
|
|
|
|
|
len(wizard.quants_lines.ids),
|
|
|
|
|
3,
|
|
|
|
|
@@ -129,18 +117,13 @@ class TestStockQuantManualAssign(TransactionCase):
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
def test_quant_manual_assign(self):
|
|
|
|
|
wizard = self.quant_assign_wizard.with_context(active_id=self.move.id).create(
|
|
|
|
|
{}
|
|
|
|
|
)
|
|
|
|
|
wizard = self._create_wizard()
|
|
|
|
|
self.assertEqual(
|
|
|
|
|
len(wizard.quants_lines.ids),
|
|
|
|
|
3,
|
|
|
|
|
"Three quants created, three quants got by default",
|
|
|
|
|
)
|
|
|
|
|
wizard.quants_lines[0].write({"selected": True})
|
|
|
|
|
wizard.quants_lines[0]._onchange_selected()
|
|
|
|
|
wizard.quants_lines[1].write({"selected": True, "qty": 50.0})
|
|
|
|
|
self.assertEqual(wizard.lines_qty, 150.0)
|
|
|
|
|
self._process_basic_manual_assign_steps(wizard)
|
|
|
|
|
self.assertEqual(wizard.move_qty, 250.0)
|
|
|
|
|
wizard.assign_quants()
|
|
|
|
|
self.assertAlmostEqual(
|
|
|
|
|
@@ -151,24 +134,25 @@ class TestStockQuantManualAssign(TransactionCase):
|
|
|
|
|
self.assertFalse(self.move.picking_type_id.auto_fill_qty_done)
|
|
|
|
|
self.assertEqual(sum(self.move.move_line_ids.mapped("qty_done")), 0.0)
|
|
|
|
|
|
|
|
|
|
def test_quant_manual_assign_auto_fill_qty_done(self):
|
|
|
|
|
wizard = self.quant_assign_wizard.with_context(active_id=self.move.id).create(
|
|
|
|
|
{}
|
|
|
|
|
)
|
|
|
|
|
wizard.quants_lines[0].write({"selected": True})
|
|
|
|
|
wizard.quants_lines[0]._onchange_selected()
|
|
|
|
|
wizard.quants_lines[1].write({"selected": True, "qty": 50.0})
|
|
|
|
|
self.assertEqual(wizard.lines_qty, 150.0)
|
|
|
|
|
def _process_quant_manual_assign_auto_fill_qty_done(self):
|
|
|
|
|
wizard = self._create_wizard()
|
|
|
|
|
self._process_basic_manual_assign_steps(wizard)
|
|
|
|
|
self.picking_type.auto_fill_qty_done = True
|
|
|
|
|
wizard.assign_quants()
|
|
|
|
|
self.assertTrue(self.move.picking_type_id.auto_fill_qty_done)
|
|
|
|
|
self.assertEqual(sum(self.move.move_line_ids.mapped("qty_done")), 150.0)
|
|
|
|
|
|
|
|
|
|
def test_quant_manual_assign_auto_fill_qty_done_planned(self):
|
|
|
|
|
self.assertFalse(self.picking.immediate_transfer)
|
|
|
|
|
self._process_quant_manual_assign_auto_fill_qty_done()
|
|
|
|
|
|
|
|
|
|
def test_quant_manual_assign_auto_fill_qty_done_immediate(self):
|
|
|
|
|
self.picking.immediate_transfer = True
|
|
|
|
|
self._process_quant_manual_assign_auto_fill_qty_done()
|
|
|
|
|
|
|
|
|
|
def test_quant_assign_wizard_after_availability_check(self):
|
|
|
|
|
self.move._action_assign()
|
|
|
|
|
wizard = self.quant_assign_wizard.with_context(active_id=self.move.id).create(
|
|
|
|
|
{}
|
|
|
|
|
)
|
|
|
|
|
wizard = self._create_wizard()
|
|
|
|
|
self.assertEqual(
|
|
|
|
|
len(wizard.quants_lines.ids),
|
|
|
|
|
3,
|
|
|
|
|
|