Skip to content

Commit

Permalink
[FIX] tests on procurement production from subcontractor
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiocorato committed Nov 11, 2024
1 parent 34a103b commit 32f3634
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 30 deletions.
1 change: 1 addition & 0 deletions mrp_manual_procurement_subcontractor/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"sale", # for test purposes
],
"data": [
"security/ir.model.access.csv",
"wizard/mrp_production_procure_subcontractor.xml",
"views/mrp.xml",
"views/purchase.xml",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ def setUpClass(cls):
super().setUpClass()
cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True))
cls.warehouse = cls.env["stock.warehouse"].search([], limit=1)
cls.product_categ_order_grouping = cls.env["product.category"].create({
"name": "Product Categ with order",
"procured_purchase_grouping": "order",
})
cls.resupply_sub_on_order_route = cls.env["stock.location.route"].search(
[("name", "=", "Resupply Subcontractor on Order")]
)
Expand Down Expand Up @@ -83,7 +87,7 @@ def setUpClass(cls):
"name": cls.subcontractor_partner3.id,
}
)
# ADD to top_product buy and (resupply route is necessary?)
# ADD to top_product buy route
cls.top_product.write(
{
"purchase_ok": True,
Expand All @@ -108,6 +112,7 @@ def setUpClass(cls):
)
],
"seller_ids": [(6, 0, [supplierinfo_3.id])],
"categ_id": cls.product_categ_order_grouping.id,
}
)
cls.sub_bom3 = cls.env["mrp.bom"].create(
Expand Down Expand Up @@ -194,10 +199,10 @@ def test_01_mo_from_sale_with_subcontracting_and_mto(self):
# do nothing anyway)
with mute_logger("odoo.addons.stock.models.procurement"):
self.procurement_model.run_scheduler()
self.production = self.env["mrp.production"].search(
production = self.env["mrp.production"].search(
[("product_id", "=", self.top_product.id)]
)
self.assertTrue(self.production.is_subcontractable)
self.assertTrue(production.is_subcontractable)
po_ids = self.env["purchase.order"].search(
[
("state", "=", "draft"),
Expand All @@ -208,14 +213,14 @@ def test_01_mo_from_sale_with_subcontracting_and_mto(self):
# continue production with subcontrator
procure_form = Form(
self.env["mrp.production.procure.subcontractor"].with_context(
active_id=self.production.id,
active_ids=[self.production.id],
active_id=production.id,
active_ids=[production.id],
)
)
procure_form.subcontractor_id = self.subcontractor_partner2
wizard = procure_form.save()
wizard.action_done()
self.assertEqual(self.production.state, "cancel")
self.assertEqual(production.state, "cancel")
new_production = self.env["mrp.production"].search(
[("product_id", "=", self.top_product.id), ("state", "!=", "cancel")]
)
Expand Down Expand Up @@ -253,10 +258,10 @@ def test_02_normal_mo_from_sale_with_mto(self):
# do nothing anyway)
with mute_logger("odoo.addons.stock.models.procurement"):
self.procurement_model.run_scheduler()
self.production = self.env["mrp.production"].search(
production = self.env["mrp.production"].search(
[("product_id", "=", self.top_product.id)]
)
self.assertTrue(self.production.is_subcontractable)
self.assertTrue(production.is_subcontractable)
po_ids = self.env["purchase.order"].search(
[
("state", "=", "draft"),
Expand All @@ -265,7 +270,7 @@ def test_02_normal_mo_from_sale_with_mto(self):
)
self.assertFalse(po_ids)
# continue with normal production
self.production.button_proceed_to_production()
production.button_proceed_to_production()
# run scheduler to start orderpoint rule to check RDP are not created
# for top product
with mute_logger("odoo.addons.stock.models.procurement"):
Expand Down Expand Up @@ -316,11 +321,11 @@ def test_03_mo_from_sale_with_subcontracting_and_orderpoint(self):
# (which will do nothing anyway)
with mute_logger("odoo.addons.stock.models.procurement"):
self.procurement_model.run_scheduler()
self.production = self.env["mrp.production"].search(
production = self.env["mrp.production"].search(
[("product_id", "=", self.top_product.id), ("state", "!=", "cancel")]
)
self.assertTrue(self.production)
self.assertTrue(self.production.is_subcontractable)
self.assertTrue(production)
self.assertTrue(production.is_subcontractable)
po_ids = self.env["purchase.order"].search(
[
("state", "=", "draft"),
Expand All @@ -331,8 +336,8 @@ def test_03_mo_from_sale_with_subcontracting_and_orderpoint(self):
# continue production with subcontrator
procure_form = Form(
self.env["mrp.production.procure.subcontractor"].with_context(
active_id=self.production.id,
active_ids=[self.production.id],
active_id=production.id,
active_ids=[production.id],
)
)
procure_form.subcontractor_id = self.subcontractor_partner2
Expand All @@ -352,16 +357,19 @@ def test_03_mo_from_sale_with_subcontracting_and_orderpoint(self):
with mute_logger("odoo.addons.stock.models.procurement"):
self.procurement_model.run_scheduler()
# check purchase order for manufactured product is in purchase state
# subproduct3_po_ids = self.env["purchase.order"].search(
# [
# ("order_line.product_id", "in", self.subproduct3.ids),
# ]
# )
# self.assertEqual(len(subproduct3_po_ids), 1)
# self.assertEqual(subproduct3_po_ids.state, "purchase")
# self.assertEqual(
# subproduct3_po_ids.origin, self.subproduct3.orderpoint_ids.name
# )
subproduct3_po_ids = self.env["purchase.order"].search(
[
("order_line.product_id", "in", self.subproduct3.ids),
]
)
self.assertEqual(len(subproduct3_po_ids), 1)
self.assertEqual(subproduct3_po_ids.state, "purchase")
self.assertIn(
self.subproduct3.orderpoint_ids.name, subproduct3_po_ids.origin
)
self.assertIn(
new_po_ids.picking_ids.name, subproduct3_po_ids.origin
)

def test_04_normal_mo_from_sale_with_orderpoint(self):
self._remove_mto_and_create_orderpoint()
Expand All @@ -376,10 +384,10 @@ def test_04_normal_mo_from_sale_with_orderpoint(self):
# (which will do nothing anyway)
with mute_logger("odoo.addons.stock.models.procurement"):
self.procurement_model.run_scheduler()
self.production = self.env["mrp.production"].search(
production = self.env["mrp.production"].search(
[("product_id", "=", self.top_product.id)]
)
self.assertTrue(self.production.is_subcontractable)
self.assertTrue(production.is_subcontractable)
po_ids = self.env["purchase.order"].search(
[
("state", "=", "draft"),
Expand All @@ -388,7 +396,8 @@ def test_04_normal_mo_from_sale_with_orderpoint(self):
)
self.assertFalse(po_ids)
# continue with normal production
self.production.button_proceed_to_production()
production.button_proceed_to_production()
self.assertFalse(production.is_subcontractable)
# run scheduler to start orderpoint rule to check RDP are not created
# for top product
with mute_logger("odoo.addons.stock.models.procurement"):
Expand Down
2 changes: 1 addition & 1 deletion mrp_manual_procurement_subcontractor/views/purchase.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<field name="model">purchase.order</field>
<field name="inherit_id" ref="purchase.purchase_order_form" />
<field name="arch" type="xml">
<xpath expr="//div[@class='oe_button_box']" position="inside">
<xpath expr="//div[hasclass('oe_button_box')]" position="inside">
<button
name="action_view_subcontract_picking"
type="object"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ class MrpProductionProcureSubcontractor(models.TransientModel):
_name = "mrp.production.procure.subcontractor"
_description = "Procure from subcontractor"

subcontractor_ids = fields.Many2many(comodel_name="res.partner")
subcontractor_id = fields.Many2one(comodel_name="res.partner")
subcontractor_ids = fields.Many2many(string="Subcontractors", comodel_name="res.partner")
subcontractor_id = fields.Many2one(string="Subcontractor", comodel_name="res.partner")
route_id = fields.Many2one(comodel_name="stock.location.route")

@api.model
Expand Down

0 comments on commit 32f3634

Please sign in to comment.