Skip to content

Commit

Permalink
[IMP] procurement_mto_analytic: improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AungKoKoLin1997 committed Oct 24, 2024
1 parent 48656ad commit 538a634
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 28 deletions.
4 changes: 1 addition & 3 deletions procurement_mto_analytic/models/purchase_order_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ class PurchaseOrderLine(models.Model):
def _prepare_purchase_order_line_from_procurement(
self, product_id, product_qty, product_uom, company_id, values, po
):
res = super(
PurchaseOrderLine, self
)._prepare_purchase_order_line_from_procurement(
res = super()._prepare_purchase_order_line_from_procurement(
product_id, product_qty, product_uom, company_id, values, po
)
res["analytic_distribution"] = values.get("analytic_distribution", False)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class TestPurchaseProcurementAnalytic(common.TransactionCase):

@classmethod
def setUpClass(cls):
super(TestPurchaseProcurementAnalytic, cls).setUpClass()
super().setUpClass()
cls.vendor = cls.env["res.partner"].create({"name": "Partner #2"})
supplierinfo = cls.env["product.supplierinfo"].create(
{"partner_id": cls.vendor.id}
Expand Down Expand Up @@ -39,7 +39,7 @@ def setUpClass(cls):
{str(cls.env.ref("analytic.analytic_agrolait").id): 100.0}
)

def test_sale_to_procurement(self):
def create_sale_order(self, product):
sale_order = self.env["sale.order"].create(
{
"partner_id": self.partner.id,
Expand All @@ -48,17 +48,21 @@ def test_sale_to_procurement(self):
0,
0,
{
"product_id": self.product.id,
"product_id": product.id,
"product_uom_qty": 1,
"price_unit": self.product.list_price,
"name": self.product.name,
"price_unit": product.list_price,
"name": product.name,
"analytic_distribution": self.analytic_distribution,
},
)
],
"picking_policy": "direct",
}
)
return sale_order

def test_sale_to_procurement(self):
sale_order = self.create_sale_order(self.product)
sale_order.with_context(test_enabled=True).action_confirm()
purchase_order_line = self.env["purchase.order.line"].search(
[("partner_id", "=", self.vendor.id)]
Expand All @@ -69,27 +73,8 @@ def test_sale_to_procurement(self):
)

def test_sale_service_product(self):
sale_order = self.env["sale.order"].create(
{
"partner_id": self.partner.id,
"order_line": [
(
0,
0,
{
"product_id": self.service_product.id,
"product_uom_qty": 1,
"price_unit": self.service_product.list_price,
"name": self.service_product.name,
"analytic_distribution": self.analytic_distribution,
},
)
],
"picking_policy": "direct",
}
)
sale_order = self.create_sale_order(self.service_product)
sale_order.with_context(test_enabled=True).action_confirm()

purchase_order_line = self.env["purchase.order.line"].search(
[("partner_id", "=", self.vendor.id)]
)
Expand Down

0 comments on commit 538a634

Please sign in to comment.