Merge pull request #40388 from GursheenK/promotional-scheme-recurse-for

feat: add recursion qty field in promotional scheme
This commit is contained in:
Gursheen Kaur Anand
2024-03-12 14:28:17 +05:30
committed by GitHub
5 changed files with 52 additions and 5 deletions

View File

@@ -60,6 +60,8 @@ product_discount_fields = [
"free_item_rate",
"same_item",
"is_recursive",
"recurse_for",
"apply_recursion_over",
"apply_multiple_pricing_rules",
]

View File

@@ -107,6 +107,28 @@ class TestPromotionalScheme(unittest.TestCase):
price_rules = frappe.get_all("Pricing Rule", filters={"promotional_scheme": ps.name})
self.assertEqual(price_rules, [])
def test_pricing_rule_for_product_discount_slabs(self):
ps = make_promotional_scheme()
ps.set("price_discount_slabs", [])
ps.set(
"product_discount_slabs",
[
{
"rule_description": "12+1",
"min_qty": 12,
"free_item": "_Test Item 2",
"free_qty": 1,
"is_recursive": 1,
"recurse_for": 12,
}
],
)
ps.save()
pr = frappe.get_doc("Pricing Rule", {"promotional_scheme_id": ps.product_discount_slabs[0].name})
self.assertSequenceEqual(
[pr.min_qty, pr.free_item, pr.free_qty, pr.recurse_for], [12, "_Test Item 2", 1, 12]
)
def make_promotional_scheme(**args):
args = frappe._dict(args)

View File

@@ -27,7 +27,9 @@
"threshold_percentage",
"column_break_15",
"priority",
"is_recursive"
"is_recursive",
"recurse_for",
"apply_recursion_over"
],
"fields": [
{
@@ -161,17 +163,36 @@
"fieldname": "is_recursive",
"fieldtype": "Check",
"label": "Is Recursive"
},
{
"default": "0",
"depends_on": "is_recursive",
"description": "Give free item for every N quantity",
"fieldname": "recurse_for",
"fieldtype": "Float",
"label": "Recurse Every (As Per Transaction UOM)",
"mandatory_depends_on": "is_recursive"
},
{
"default": "0",
"depends_on": "is_recursive",
"description": "Qty for which recursion isn't applicable.",
"fieldname": "apply_recursion_over",
"fieldtype": "Float",
"label": "Apply Recursion Over (As Per Transaction UOM)",
"mandatory_depends_on": "is_recursive"
}
],
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2021-03-06 21:58:18.162346",
"modified": "2024-03-12 12:53:58.199108",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Promotional Scheme Product Discount",
"owner": "Administrator",
"permissions": [],
"sort_field": "modified",
"sort_order": "DESC"
"sort_order": "DESC",
"states": []
}

View File

@@ -15,6 +15,7 @@ class PromotionalSchemeProductDiscount(Document):
from frappe.types import DF
apply_multiple_pricing_rules: DF.Check
apply_recursion_over: DF.Float
disable: DF.Check
free_item: DF.Link | None
free_item_rate: DF.Currency
@@ -51,6 +52,7 @@ class PromotionalSchemeProductDiscount(Document):
"19",
"20",
]
recurse_for: DF.Float
rule_description: DF.SmallText
same_item: DF.Check
threshold_percentage: DF.Percent

View File

@@ -1826,8 +1826,8 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe
let items = [];
me.frm.doc.items.forEach(d => {
// if same item was added a free item through a different pricing rule, keep it
if(d.item_code != item.remove_free_item || !d.is_free_item || removed_pricing_rule?.includes(d.pricing_rules)) {
// if same item was added as free item through a different pricing rule, keep it
if(d.item_code != item.remove_free_item || !d.is_free_item || !removed_pricing_rule?.includes(d.pricing_rules)) {
items.push(d);
}
});