Skip to content

Commit

Permalink
remove stock_picking_analyitc dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
yostashiro committed Mar 11, 2024
1 parent 67d0fb4 commit aa76cb8
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 28 deletions.
3 changes: 2 additions & 1 deletion mrp_mto_analytic/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
This module transfers the analyic_distribution from the source MO to a newly created MO that is generated based on the stock rule.
This module transfers the analyic distribution from the origin stock move to the
manufacturing order newly created by the stock rule.
2 changes: 1 addition & 1 deletion purchase_mto_analytic/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"author": "Quartile Limited, Odoo Community Association (OCA)",
"category": "Purchase Management",
"website": "https://github.com/OCA/purchase-workflow",
"depends": ["purchase_analytic", "stock_picking_analytic"],
"depends": ["purchase_analytic", "stock_analytic"],
"license": "AGPL-3",
"installable": True,
}
14 changes: 1 addition & 13 deletions purchase_mto_analytic/models/purchase_order_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,5 @@ def _prepare_purchase_order_line_from_procurement(
)
move_dest = values.get("move_dest_ids")
if move_dest:
if move_dest.picking_id.analytic_distribution:
vals[
"analytic_distribution"
] = move_dest.picking_id.analytic_distribution
else:
# Handle the case where mrp_production_ids exists
mrp_productions = getattr(
move_dest.group_id, "mrp_production_ids", None
)
if mrp_productions:
vals["analytic_distribution"] = mrp_productions[
0
].analytic_distribution
vals["analytic_distribution"] = move_dest[0].analytic_distribution
return vals
3 changes: 2 additions & 1 deletion purchase_mto_analytic/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
This module propagates the analytic_distribution from a source document to new Purchase Order created by the stock rule.
This module propagates the analytic distribution from the origin stock move to the
purchase order newly created by the stock rule.
20 changes: 8 additions & 12 deletions purchase_mto_analytic/tests/test_purchase_mto_analytic.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,33 @@
class TestPurchaseMtoAnalytic(TransactionCase):
@classmethod
def setUpClass(cls):
super(TestPurchaseMtoAnalytic, cls).setUpClass()
super().setUpClass()
purchase_route = cls.env.ref("purchase_stock.route_warehouse0_buy")
# Get the MTO route and activate it if necessary
mto_route = cls.env.ref("stock.route_warehouse0_mto")
purchase_route = cls.env.ref("purchase_stock.route_warehouse0_buy")
if not mto_route.active:
mto_route.write({"active": True})
# Create a product
cls.product = cls.env["product.product"].create(
{
"name": "Product 1",
"type": "product",
"route_ids": [(6, 0, [mto_route.id, purchase_route.id])],
}
)
# Create a vendor
cls.vendor = cls.env["res.partner"].create({"name": "Vendor 1"})

# Link the vendor to the product
cls.env["product.supplierinfo"].create(
{
"partner_id": cls.vendor.id,
"product_tmpl_id": cls.product.product_tmpl_id.id,
}
)
analytic_plan = cls.env["account.analytic.plan"].create(
{"name": "Plan Test", "company_id": False}
{"name": "test plan", "company_id": False}
)
analytic_account_manual = cls.env["account.analytic.account"].create(
{"name": "manual", "plan_id": analytic_plan.id}
analytic_account = cls.env["account.analytic.account"].create(
{"name": "test account", "plan_id": analytic_plan.id}
)
cls.analytic_distribution_manual = {str(analytic_account_manual.id): 100}
cls.analytic_distribution = {str(analytic_account.id): 100}

def test_purchase_analytic(self):
# Create an outgoing stock picking for the product
Expand All @@ -49,7 +45,6 @@ def test_purchase_analytic(self):
"picking_type_id": picking_type_out.id,
"location_id": stock_location.id,
"location_dest_id": customer_location.id,
"analytic_distribution": self.analytic_distribution_manual,
"move_ids": [
(
0,
Expand All @@ -62,6 +57,7 @@ def test_purchase_analytic(self):
"product_uom": self.product.uom_id.id,
"location_id": stock_location.id,
"location_dest_id": customer_location.id,
"analytic_distribution": self.analytic_distribution,
},
),
],
Expand All @@ -74,5 +70,5 @@ def test_purchase_analytic(self):
)
self.assertTrue(purchase_order, "No purchase order created.")
self.assertEqual(
purchase_order.analytic_distribution, self.analytic_distribution_manual
purchase_order.analytic_distribution, self.analytic_distribution
)

0 comments on commit aa76cb8

Please sign in to comment.