|
4 | 4 |
|
5 | 5 | import frappe
|
6 | 6 | from frappe.tests import IntegrationTestCase
|
| 7 | +from frappe.utils import nowdate |
7 | 8 |
|
8 | 9 | from erpnext.accounts.doctype.promotional_scheme.promotional_scheme import TransactionExists
|
9 | 10 | from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order
|
@@ -173,6 +174,50 @@ def test_validation_on_recurse_with_mixed_condition(self):
|
173 | 174 | ps.mixed_conditions = True
|
174 | 175 | self.assertRaises(frappe.ValidationError, ps.save)
|
175 | 176 |
|
| 177 | + def test_cumulative_product_discount_slabs(self): |
| 178 | + ps = make_promotional_scheme(applicable_for="Customer", customer="_Test Customer 1") |
| 179 | + ps.is_cumulative = True |
| 180 | + ps.valid_from = ps.valid_upto = nowdate() |
| 181 | + ps.set("price_discount_slabs", []) |
| 182 | + ps.set("items", []) |
| 183 | + ps.set( |
| 184 | + "items", |
| 185 | + [ |
| 186 | + { |
| 187 | + "item_code": "_Test Item 2", |
| 188 | + } |
| 189 | + ], |
| 190 | + ) |
| 191 | + ps.set( |
| 192 | + "product_discount_slabs", |
| 193 | + [ |
| 194 | + { |
| 195 | + "rule_description": "Test1", |
| 196 | + "min_qty": 500, |
| 197 | + "max_qty": 500, |
| 198 | + "same_item": True, |
| 199 | + "free_qty": 50, |
| 200 | + }, |
| 201 | + { |
| 202 | + "rule_description": "Test2", |
| 203 | + "min_qty": 1000, |
| 204 | + "max_qty": 1000, |
| 205 | + "same_item": True, |
| 206 | + "free_qty": 120, |
| 207 | + }, |
| 208 | + ], |
| 209 | + ) |
| 210 | + ps.save() |
| 211 | + |
| 212 | + so1 = make_sales_order(customer="_Test Customer 1", item_code="_Test Item 2", qty=500) |
| 213 | + self.assertEqual(so1.items[1].qty, 50) |
| 214 | + |
| 215 | + so2 = make_sales_order(customer="_Test Customer 1", item_code="_Test Item 2", qty=500) |
| 216 | + self.assertEqual(so2.items[1].qty, 70) |
| 217 | + |
| 218 | + so1.reload().cancel().delete() |
| 219 | + so2.reload().cancel().delete() |
| 220 | + |
176 | 221 |
|
177 | 222 | def make_promotional_scheme(**args):
|
178 | 223 | args = frappe._dict(args)
|
|
0 commit comments