Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
(cherry picked from commit 366ae85)

# Conflicts:
#	erpnext/stock/doctype/pick_list/test_pick_list.py
  • Loading branch information
mihir-kandoi authored and mergify[bot] committed Feb 19, 2025
1 parent 2edf083 commit e515b91
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 1 deletion.
2 changes: 1 addition & 1 deletion erpnext/accounts/doctype/pricing_rule/pricing_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ def remove_pricing_rule_for_item(pricing_rules, item_details, item_code=None, ra
if pricing_rule.margin_type in ["Percentage", "Amount"]:
item_details.margin_rate_or_amount = 0.0
item_details.margin_type = None
elif pricing_rule.get("free_item"):
elif pricing_rule.get("free_item") and pricing_rule.get("enforce_free_item_qty"):
item_details.remove_free_item = (
item_code if pricing_rule.get("same_item") else pricing_rule.get("free_item")
)
Expand Down
5 changes: 5 additions & 0 deletions erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ def test_pricing_rule_for_product_discount_on_same_item(self):
"price_or_product_discount": "Product",
"same_item": 1,
"free_qty": 1,
"enforce_free_item_qty": 1,
"company": "_Test Company",
}
frappe.get_doc(test_record.copy()).insert()
Expand Down Expand Up @@ -418,6 +419,7 @@ def test_pricing_rule_for_product_discount_on_different_item(self):
"same_item": 0,
"free_item": "_Test Item 2",
"free_qty": 1,
"enforce_free_item_qty": 1,
"company": "_Test Company",
}
frappe.get_doc(test_record.copy()).insert()
Expand Down Expand Up @@ -961,6 +963,7 @@ def test_pricing_rule_for_product_free_item_rounded_qty_and_recursion(self):
"price_or_product_discount": "Product",
"same_item": 1,
"free_qty": 1,
"enforce_free_item_qty": 1,
"round_free_qty": 1,
"is_recursive": 1,
"recurse_for": 2,
Expand Down Expand Up @@ -1006,6 +1009,7 @@ def test_pricing_rule_for_product_free_item_round_free_qty(self):
"price_or_product_discount": "Product",
"same_item": 1,
"free_qty": 10,
"enforce_free_item_qty": 1,
"round_free_qty": 1,
"is_recursive": 1,
"recurse_for": 100,
Expand Down Expand Up @@ -1239,6 +1243,7 @@ def make_pricing_rule(**args):
"discount_amount": args.discount_amount or 0.0,
"apply_multiple_pricing_rules": args.apply_multiple_pricing_rules or 0,
"has_priority": args.has_priority or 0,
"enforce_free_item_qty": args.enforce_free_item_qty or 1,
}
)

Expand Down
96 changes: 96 additions & 0 deletions erpnext/stock/doctype/pick_list/test_pick_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,102 @@ def test_validate_picked_qty_with_manual_option(self):

self.assertRaises(frappe.ValidationError, pl.save)

<<<<<<< HEAD
=======
def test_over_allowance_picking(self):
warehouse = "_Test Warehouse - _TC"
item = make_item(
"Test Over Allowance Picking Item",
properties={
"is_stock_item": 1,
},
).name

make_stock_entry(item=item, to_warehouse=warehouse, qty=100)

so = make_sales_order(item_code=item, qty=10, rate=100)

pl_doc = create_pick_list(so.name)
pl_doc.save()
self.assertEqual(pl_doc.locations[0].qty, 10)

pl_doc.locations[0].qty = 15
pl_doc.locations[0].stock_qty = 15
pl_doc.save()

self.assertEqual(pl_doc.locations[0].qty, 15)
self.assertRaises(frappe.ValidationError, pl_doc.submit)

frappe.db.set_single_value("Stock Settings", "over_picking_allowance", 50)

pl_doc.reload()
pl_doc.submit()

frappe.db.set_single_value("Stock Settings", "over_picking_allowance", 0)

def test_ignore_pricing_rule_in_pick_list(self):
frappe.flags.print_stmt = False
warehouse = "_Test Warehouse - _TC"
item = make_item(
properties={
"is_stock_item": 1,
"has_batch_no": 1,
"batch_number_series": "IPR-PICKLT-.######",
"create_new_batch": 1,
}
).name

make_stock_entry(
item=item,
to_warehouse=warehouse,
qty=2,
basic_rate=100,
)

pricing_rule = frappe.get_doc(
{
"doctype": "Pricing Rule",
"title": "Same Free Item",
"price_or_product_discount": "Product",
"selling": 1,
"apply_on": "Item Code",
"items": [
{
"item_code": item,
}
],
"same_item": 1,
"is_recursive": 1,
"recurse_for": 2,
"free_qty": 1,
"enforce_free_item_qty": 1,
"company": "_Test Company",
"customer": "_Test Customer",
}
)

pricing_rule.save()
frappe.flags.print_stmt = True

so = make_sales_order(item_code=item, qty=2, rate=100, do_not_save=True)
so.set_warehouse = warehouse
so.submit()

self.assertEqual(len(so.items), 2)
self.assertTrue(so.items[1].is_free_item)

pl = create_pick_list(so.name)
pl.ignore_pricing_rule = 1
pl.save()
pl.submit()

self.assertEqual(len(pl.locations), 1)

delivery_note = create_delivery_note(pl.name)

self.assertEqual(len(delivery_note.items), 1)

>>>>>>> 366ae85d85 (fix: tests)
def test_pick_list_not_reset_batch(self):
warehouse = "_Test Warehouse - _TC"
item = make_item(
Expand Down

0 comments on commit e515b91

Please sign in to comment.