Skip to content

Commit

Permalink
[MIG] purchase_merge: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
flalexg committed Jun 5, 2023
1 parent 6910ea8 commit e196284
Show file tree
Hide file tree
Showing 3 changed files with 229 additions and 2 deletions.
2 changes: 1 addition & 1 deletion purchase_merge/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
"name": "Purchase Merge",
"summary": "Wizard to merge purchase with required conditions",
"version": "15.0.1.0.0",
"version": "16.0.1.0.0",
"author": "Camptocamp, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/purchase-workflow",
"license": "AGPL-3",
Expand Down
225 changes: 225 additions & 0 deletions purchase_merge/tests/test_purchase_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def setUpClass(cls):
cls.product_1 = cls.env["product.product"].create({"name": "Product 1"})
cls.product_2 = cls.env["product.product"].create({"name": "Product 2"})
cls.partner = cls.env["res.partner"].create({"name": "Partner"})
cls.partner_2 = cls.env["res.partner"].create({"name": "Partner 2"})
cls.PurchaseOrder = cls.env["purchase.order"]
cls.purchase_order_1 = cls.PurchaseOrder.create(
{
Expand All @@ -27,6 +28,36 @@ def setUpClass(cls):
],
}
)
cls.purchase_order_eur = cls.PurchaseOrder.create(
{
"partner_id": cls.partner.id,
"currency_id": cls.env.ref("base.EUR").id,
"order_line": [
(0, 0, {"product_id": cls.product_2.id, "price_unit": 10})
],
}
)
cls.purchase_order_usd = cls.PurchaseOrder.create(
{
"partner_id": cls.partner.id,
"currency_id": cls.env.ref("base.USD").id,
"order_line": [
(0, 0, {"product_id": cls.product_2.id, "price_unit": 10})
],
}
)
cls.fiscal_position_1 = cls.env["account.fiscal.position"].create(
{"name": "Fiscal Position 1"}
)
cls.fiscal_position_2 = cls.env["account.fiscal.position"].create(
{"name": "Fiscal Position 2"}
)
cls.incoterm_1 = cls.env["account.incoterms"].create(
{"name": "Incoterm 1", "code": "INC1"}
)
cls.incoterm_2 = cls.env["account.incoterms"].create(
{"name": "Incoterm 2", "code": "INC2"}
)

def test_count_purchase_order_lines(self):
self.purchase_merge_1 = self.PurchaseMerge.create(
Expand Down Expand Up @@ -81,3 +112,197 @@ def test_purchase_order_states(self):
r"You can't merge purchase orders that aren't in draft state like: .+",
):
self.purchase_merge_4._check_state(self.purchase_merge_4.purchase_ids)

def test_purchase_order_currency(self):
purchase_order_dst = self.env["purchase.order"].create(
{
"partner_id": self.partner.id,
"order_line": [
(0, 0, {"product_id": self.product_2.id, "price_unit": 10})
],
}
)
purchase_order_dst.write({"state": "sent"})
purchase_merge_4 = self.PurchaseMerge.create(
{
"purchase_ids": [
(6, 0, [self.purchase_order_eur.id, self.purchase_order_usd.id])
],
"dst_purchase_id": purchase_order_dst.id,
}
)
with self.assertRaisesRegex(
UserError,
r"You can't merge purchase orders with different currencies: .+",
):
purchase_merge_4._check_all_values(purchase_merge_4.purchase_ids)

def test_purchase_order_fiscal_position(self):
purchase_order_fp_1 = self.env["purchase.order"].create(
{
"partner_id": self.partner.id,
"order_line": [
(0, 0, {"product_id": self.product_2.id, "price_unit": 10})
],
"fiscal_position_id": self.fiscal_position_1.id,
}
)
purchase_order_fp_2 = self.env["purchase.order"].create(
{
"partner_id": self.partner.id,
"order_line": [
(0, 0, {"product_id": self.product_2.id, "price_unit": 10})
],
"fiscal_position_id": self.fiscal_position_2.id,
}
)
purchase_order_dst = self.env["purchase.order"].create(
{
"partner_id": self.partner.id,
"order_line": [
(0, 0, {"product_id": self.product_2.id, "price_unit": 10})
],
}
)
purchase_order_dst.write({"state": "sent"})
purchase_merge = self.PurchaseMerge.create(
{
"purchase_ids": [
(6, 0, [purchase_order_fp_1.id, purchase_order_fp_2.id])
],
"dst_purchase_id": purchase_order_dst.id,
}
)
with self.assertRaisesRegex(
UserError,
r"You can't merge purchase orders with different fiscal positions: .+",
):
purchase_merge._check_all_values(purchase_merge.purchase_ids)

def test_purchase_order_incoterms(self):
purchase_order_inc_1 = self.env["purchase.order"].create(
{
"partner_id": self.partner.id,
"order_line": [
(0, 0, {"product_id": self.product_2.id, "price_unit": 10})
],
"incoterm_id": self.incoterm_1.id,
}
)
purchase_order_inc_2 = self.env["purchase.order"].create(
{
"partner_id": self.partner.id,
"order_line": [
(0, 0, {"product_id": self.product_2.id, "price_unit": 10})
],
"incoterm_id": self.incoterm_2.id,
}
)
purchase_order_dst = self.env["purchase.order"].create(
{
"partner_id": self.partner.id,
"order_line": [
(0, 0, {"product_id": self.product_2.id, "price_unit": 10})
],
}
)
purchase_order_dst.write({"state": "sent"})
purchase_merge = self.PurchaseMerge.create(
{
"purchase_ids": [
(6, 0, [purchase_order_inc_1.id, purchase_order_inc_2.id])
],
"dst_purchase_id": purchase_order_dst.id,
}
)
with self.assertRaisesRegex(
UserError,
r"You can't merge purchase orders with different incoterms: .+",
):
purchase_merge._check_all_values(purchase_merge.purchase_ids)

def test_purchase_order_payment_terms(self):
purchase_order_pt_1 = self.env["purchase.order"].create(
{
"partner_id": self.partner.id,
"order_line": [
(0, 0, {"product_id": self.product_2.id, "price_unit": 10})
],
"payment_term_id": self.env.ref(
"account.account_payment_term_end_following_month"
).id,
}
)
purchase_order_pt_2 = self.env["purchase.order"].create(
{
"partner_id": self.partner.id,
"order_line": [
(0, 0, {"product_id": self.product_2.id, "price_unit": 10})
],
"payment_term_id": self.env.ref(
"account.account_payment_term_15days"
).id,
}
)
purchase_order_dst = self.env["purchase.order"].create(
{
"partner_id": self.partner.id,
"order_line": [
(0, 0, {"product_id": self.product_2.id, "price_unit": 10})
],
}
)
purchase_order_dst.write({"state": "sent"})
purchase_merge = self.PurchaseMerge.create(
{
"purchase_ids": [
(6, 0, [purchase_order_pt_1.id, purchase_order_pt_2.id])
],
"dst_purchase_id": purchase_order_dst.id,
}
)
with self.assertRaisesRegex(
UserError,
r"You can't merge purchase orders with different payment terms: .+",
):
purchase_merge._check_all_values(purchase_merge.purchase_ids)

def test_purchase_order_partners(self):
purchase_order_partner1 = self.env["purchase.order"].create(
{
"partner_id": self.partner.id,
"order_line": [
(0, 0, {"product_id": self.product_2.id, "price_unit": 10})
],
}
)
purchase_order_partner2 = self.env["purchase.order"].create(
{
"partner_id": self.partner_2.id,
"order_line": [
(0, 0, {"product_id": self.product_2.id, "price_unit": 10})
],
}
)
purchase_order_dst = self.env["purchase.order"].create(
{
"partner_id": self.partner.id,
"order_line": [
(0, 0, {"product_id": self.product_2.id, "price_unit": 10})
],
}
)
purchase_order_dst.write({"state": "sent"})
purchase_merge = self.PurchaseMerge.create(
{
"purchase_ids": [
(6, 0, [purchase_order_partner1.id, purchase_order_partner2.id])
],
"dst_purchase_id": purchase_order_dst.id,
}
)
with self.assertRaisesRegex(
UserError,
r"You can't merge purchase orders with different suppliers: .+",
):
purchase_merge._check_all_values(purchase_merge.purchase_ids)
4 changes: 3 additions & 1 deletion purchase_merge/wizard/purchase_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ class MergePurchaseAutomatic(models.TransientModel):

_name = "purchase.merge.automatic.wizard"

purchase_ids = fields.Many2many("purchase.order")
purchase_ids = fields.Many2many(
comodel_name="purchase.order",
)
dst_purchase_id = fields.Many2one(
comodel_name="purchase.order",
string="Destination",
Expand Down

0 comments on commit e196284

Please sign in to comment.