changeset e027e2640a20 in
modules/sale_product_recommendation_association_rule:default
details:
https://hg.tryton.org/modules/sale_product_recommendation_association_rule?cmd=changeset&node=e027e2640a20
description:
Use declarative index definition for ModelSQL
issue5757
review361251002
diffstat:
sale.py | 20 +++++++++++++++-----
1 files changed, 15 insertions(+), 5 deletions(-)
diffs (64 lines):
diff -r c6a748557319 -r e027e2640a20 sale.py
--- a/sale.py Wed Sep 14 01:02:41 2022 +0200
+++ b/sale.py Tue Oct 11 00:44:50 2022 +0200
@@ -6,7 +6,7 @@
from efficient_apriori import apriori
from trytond.cache import Cache
-from trytond.model import ModelSQL, ModelView, fields
+from trytond.model import Index, ModelSQL, ModelView, fields
from trytond.pool import Pool, PoolMeta
from trytond.transaction import Transaction
@@ -103,7 +103,7 @@
],
help="The frequency of consequents and antecedents appear together.")
lift = fields.Float(
- "Lift", select=True,
+ "Lift",
domain=[
('lift', '>=', 0),
],
@@ -113,13 +113,23 @@
"dependent on one another.\n"
"If less than 1, the items are substitute to each other.")
conviction = fields.Float(
- "Conviction", select=True,
+ "Conviction",
domain=[
('conviction', '>=', 0),
],
help="The frequency that the rule makes an incorrect prediction.")
_find_rules_cache = Cache(__name__ + '._find_rules', context=False)
+ @classmethod
+ def __setup__(cls):
+ super().__setup__()
+ t = cls.__table__()
+ cls._sql_indexes.add(
+ Index(
+ t,
+ (t.lift, Index.Range(order='DESC')),
+ (t.conviction, Index.Range(order='ASC'))))
+
def get_product_names(self, name):
return ', '.join(
p.rec_name for p in getattr(self, name[:-len('_names')] + 's'))
@@ -232,7 +242,7 @@
rule = fields.Many2One(
'sale.product.association.rule', "Rule",
- required=True, select=True, ondelete='CASCADE')
+ required=True, ondelete='CASCADE')
product = fields.Many2One(
'product.product', "Product", required=True, ondelete='CASCADE')
@@ -243,7 +253,7 @@
rule = fields.Many2One(
'sale.product.association.rule', "Rule",
- required=True, select=True, ondelete='CASCADE')
+ required=True, ondelete='CASCADE')
product = fields.Many2One(
'product.product', "Product", required=True, ondelete='CASCADE')