Match also with parent categories
issue7133 review43991002
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
* Match also with parent categories
|
||||
|
||||
Version 4.6.0 - 2017-10-30
|
||||
* Bug fixes (see mercurial logs for details)
|
||||
* Don't match product and category lines when product is empty
|
||||
|
||||
+8
-1
@@ -141,10 +141,17 @@ class Plan(ModelSQL, ModelView):
|
||||
|
||||
def compute(self, amount, product, pattern=None):
|
||||
'Compute commission amount for the amount'
|
||||
def parents(categories):
|
||||
for category in categories:
|
||||
while category:
|
||||
yield category
|
||||
category = category.parent
|
||||
|
||||
if pattern is None:
|
||||
pattern = {}
|
||||
if product:
|
||||
pattern['categories'] = [c.id for c in product.categories_all]
|
||||
pattern['categories'] = [
|
||||
c.id for c in parents(product.categories_all)]
|
||||
pattern['product'] = product.id
|
||||
else:
|
||||
pattern['categories'] = []
|
||||
|
||||
@@ -63,6 +63,8 @@ class CommissionTestCase(ModuleTestCase):
|
||||
|
||||
category = Category(name="Category")
|
||||
category.save()
|
||||
child_category = Category(name="Child Category", parent=category)
|
||||
child_category.save()
|
||||
|
||||
company = create_company()
|
||||
with set_company(company):
|
||||
@@ -83,6 +85,11 @@ class CommissionTestCase(ModuleTestCase):
|
||||
|
||||
self.assertEqual(plan.compute(Decimal(1), product), Decimal(1))
|
||||
|
||||
template.categories = [child_category]
|
||||
template.save()
|
||||
|
||||
self.assertEqual(plan.compute(Decimal(1), product), Decimal('0.8'))
|
||||
|
||||
@with_transaction()
|
||||
def test_plan_no_product(self):
|
||||
"Test plan with no product"
|
||||
|
||||
Reference in New Issue
Block a user