[IMP] procurement_auto_create_group: auto_create_group for push rules

This commit is contained in:
Bernat Puig Font
2021-11-04 16:22:28 +01:00
parent 66d0923b1c
commit bffa69da42
6 changed files with 162 additions and 25 deletions

View File

@@ -16,6 +16,14 @@ class StockRule(models.Model):
if self.group_propagation_option != "propagate":
self.auto_create_group = False
def _push_prepare_move_copy_values(self, move_to_copy, new_date):
new_move_vals = super()._push_prepare_move_copy_values(move_to_copy, new_date)
if self.auto_create_group:
group_data = self._prepare_auto_procurement_group_data()
group = self.env["procurement.group"].create(group_data)
new_move_vals["group_id"] = group.id
return new_move_vals
def _prepare_auto_procurement_group_data(self):
name = self.env["ir.sequence"].next_by_code("procurement.group") or False
if not name:

View File

@@ -2,7 +2,8 @@
'Multi-Step Routes' and press the 'Save' button.
#. Activate the developer mode.
#. Go to *Inventory / Configuration / Warehouse Management / Routes*
and select the route you want to change. Select the pull rule you wish
to change and Select 'Propagation of Procurement Group': 'Propagate'.
The checkbox 'Auto-create Procurement Group' will then appear and you can
set it if you want to procurement group to be automatically created.
and select the route you want to change. Select the rule you wish
to change, and in case of a Pull rule or Push & Pull rule Select
'Propagation of Procurement Group': 'Propagate'. The checkbox
'Auto-create Procurement Group' will then appear and you can set
it if you want to procurement group to be automatically created.

View File

@@ -2,3 +2,4 @@
* Lois Rilo <lois.rilo@forgeflow.com>
* Héctor Villarreal Ortega <hector.villarreal@forgeflow.com>
* Jacques-Etienne Baudoux (BCIM) <je@bcim.be>
* Bernat Puig <bernat.puig@forgeflow.com>

View File

@@ -1,4 +1,5 @@
#. Run a new procurement and make sure that it determines a pull rule
#. Run a new procurement and make sure that it determines a rule
with the option 'Auto-create Procurement Group' set.
#. When the procurement rule is executed, a procurement group with
format 'PG/000001' will be created.
format 'PG/000001' will be created. You can find this procurement
group in 'Additional info' tab of a transfer.

View File

@@ -11,57 +11,106 @@ class TestProcurementAutoCreateGroup(TransactionCase):
self.rule_obj = self.env["stock.rule"]
self.route_obj = self.env["stock.location.route"]
self.move_obj = self.env["stock.move"]
self.picking_obj = self.env["stock.picking"]
self.product_obj = self.env["product.product"]
self.warehouse = self.env.ref("stock.warehouse0")
self.location = self.env.ref("stock.stock_location_stock")
loc_components = self.env.ref("stock.stock_location_components")
self.company_id = self.env.ref("base.main_company")
self.supplier_location = self.env.ref("stock.stock_location_suppliers")
self.loc_components = self.env.ref("stock.stock_location_components")
picking_type_id = self.env.ref("stock.picking_type_internal").id
self.partner = self.env["res.partner"].create({"name": "Partner"})
# Create rules and routes:
route_auto = self.route_obj.create({"name": "Auto Create Group"})
pull_push_route_auto = self.route_obj.create({"name": "Auto Create Group"})
self.rule_1 = self.rule_obj.create(
{
"name": "rule with autocreate",
"route_id": route_auto.id,
"route_id": pull_push_route_auto.id,
"auto_create_group": True,
"action": "pull_push",
"warehouse_id": self.warehouse.id,
"picking_type_id": picking_type_id,
"location_id": self.location.id,
"location_src_id": loc_components.id,
"location_src_id": self.loc_components.id,
"partner_address_id": self.partner.id,
}
)
route_no_auto = self.route_obj.create({"name": "Not Auto Create Group"})
pull_push_route_no_auto = self.route_obj.create(
{"name": "Not Auto Create Group"}
)
self.rule_obj.create(
{
"name": "rule with no autocreate",
"route_id": route_no_auto.id,
"route_id": pull_push_route_no_auto.id,
"auto_create_group": False,
"action": "pull_push",
"warehouse_id": self.warehouse.id,
"picking_type_id": picking_type_id,
"location_id": self.location.id,
"location_src_id": loc_components.id,
"location_src_id": self.loc_components.id,
}
)
push_route_auto = self.route_obj.create({"name": "Auto Create Group"})
self.rule_1 = self.rule_obj.create(
{
"name": "route_auto",
"location_src_id": self.location.id,
"location_id": self.loc_components.id,
"route_id": push_route_auto.id,
"auto_create_group": True,
"auto": "manual",
"picking_type_id": picking_type_id,
"warehouse_id": self.warehouse.id,
"company_id": self.company_id.id,
"action": "push",
}
)
push_route_no_auto = self.route_obj.create({"name": "Not Auto Create Group"})
self.rule_obj.create(
{
"name": "route_no_auto",
"location_src_id": self.location.id,
"location_id": self.loc_components.id,
"route_id": push_route_no_auto.id,
"auto_create_group": False,
"auto": "manual",
"picking_type_id": picking_type_id,
"warehouse_id": self.warehouse.id,
"company_id": self.company_id.id,
"action": "push",
}
)
# Prepare products:
self.prod_auto = self.product_obj.create(
self.prod_auto_pull_push = self.product_obj.create(
{
"name": "Test Product 1",
"type": "product",
"route_ids": [(6, 0, [route_auto.id])],
"route_ids": [(6, 0, [pull_push_route_auto.id])],
}
)
self.prod_no_auto = self.product_obj.create(
self.prod_no_auto_pull_push = self.product_obj.create(
{
"name": "Test Product 2",
"type": "product",
"route_ids": [(6, 0, [route_no_auto.id])],
"route_ids": [(6, 0, [pull_push_route_no_auto.id])],
}
)
self.prod_auto_push = self.product_obj.create(
{
"name": "Test Product 3",
"type": "product",
"route_ids": [(6, 0, [push_route_auto.id])],
}
)
self.prod_no_auto_push = self.product_obj.create(
{
"name": "Test Product 4",
"type": "product",
"route_ids": [(6, 0, [push_route_no_auto.id])],
}
)
@@ -83,22 +132,53 @@ class TestProcurementAutoCreateGroup(TransactionCase):
)
return True
def test_01_no_auto_create_group(self):
def _push_trigger(self, product):
picking = self.picking_obj.create(
{
"picking_type_id": self.ref("stock.picking_type_in"),
"location_id": self.supplier_location.id,
"location_dest_id": self.location.id,
"move_lines": [
(
0,
0,
{
"name": "Test move",
"product_id": product.id,
"date_deadline": "2099-06-01 18:00:00",
"date": "2099-06-01 18:00:00",
"product_uom": product.uom_id.id,
"product_uom_qty": 1.0,
"location_id": self.supplier_location.id,
"location_dest_id": self.location.id,
},
)
],
}
)
picking.move_lines.write({"quantity_done": 1.0})
picking.button_validate()
def test_01_pull_push_no_auto_create_group(self):
"""Test auto creation of group."""
move = self.move_obj.search([("product_id", "=", self.prod_no_auto.id)])
move = self.move_obj.search(
[("product_id", "=", self.prod_no_auto_pull_push.id)]
)
self.assertFalse(move)
self._procure(self.prod_no_auto)
move = self.move_obj.search([("product_id", "=", self.prod_no_auto.id)])
self._procure(self.prod_no_auto_pull_push)
move = self.move_obj.search(
[("product_id", "=", self.prod_no_auto_pull_push.id)]
)
self.assertTrue(move)
self.assertFalse(
move.group_id, "Procurement Group should not have been assigned."
)
def test_02_auto_create_group(self):
move = self.move_obj.search([("product_id", "=", self.prod_auto.id)])
def test_02_pull_push_auto_create_group(self):
move = self.move_obj.search([("product_id", "=", self.prod_auto_pull_push.id)])
self.assertFalse(move)
self._procure(self.prod_auto)
move = self.move_obj.search([("product_id", "=", self.prod_auto.id)])
self._procure(self.prod_auto_pull_push)
move = self.move_obj.search([("product_id", "=", self.prod_auto_pull_push.id)])
self.assertTrue(move)
self.assertTrue(move.group_id, "Procurement Group not assigned.")
self.assertEqual(
@@ -114,3 +194,43 @@ class TestProcurementAutoCreateGroup(TransactionCase):
proc_rule.write({"group_propagation_option": "none"})
proc_rule._onchange_group_propagation_option()
self.assertFalse(proc_rule.auto_create_group)
def test_04_push_no_auto_create_group(self):
"""Test no auto creation of group."""
move = self.move_obj.search(
[
("product_id", "=", self.prod_no_auto_push.id),
("location_dest_id", "=", self.loc_components.id),
]
)
self.assertFalse(move)
self._push_trigger(self.prod_no_auto_push)
move = self.move_obj.search(
[
("product_id", "=", self.prod_no_auto_push.id),
("location_dest_id", "=", self.loc_components.id),
]
)
self.assertTrue(move)
self.assertFalse(
move.group_id, "Procurement Group should not have been assigned."
)
def test_05_push_auto_create_group(self):
"""Test auto creation of group."""
move = self.move_obj.search(
[
("product_id", "=", self.prod_auto_push.id),
("location_dest_id", "=", self.loc_components.id),
]
)
self.assertFalse(move)
self._push_trigger(self.prod_auto_push)
move = self.move_obj.search(
[
("product_id", "=", self.prod_auto_push.id),
("location_dest_id", "=", self.loc_components.id),
]
)
self.assertTrue(move)
self.assertTrue(move.group_id, "Procurement Group not assigned.")

View File

@@ -11,6 +11,12 @@
attrs="{'invisible':[('group_propagation_option','!=','propagate')]}"
/>
</field>
<field name="auto" position="after">
<field
name="auto_create_group"
attrs="{'invisible':[('action','!=','push')]}"
/>
</field>
</field>
</record>
</odoo>