Cédric Krier pushed to branch branch/default at Tryton / Tryton


Commits:
ccc4bc07 by Cédric Krier at 2023-07-05T12:36:46+02:00
Document active field part of DeactivableMixin
- - - - -
c2cb25b9 by Cédric Krier at 2023-07-05T12:39:48+02:00
Set default value of active_test from transaction

Instead of testing the context in _search_domain_active, it is simpler to set
the active_test default value using the transaction context.
- - - - -
1a79f305 by Cédric Krier at 2023-07-05T12:57:15+02:00
Document active test in ModelStorage
- - - - -


5 changed files:

- modules/web_shop/web.py
- trytond/doc/ref/models.rst
- trytond/doc/ref/transaction.rst
- trytond/trytond/model/modelsql.py
- trytond/trytond/model/modelstorage.py


Changes:

=====================================
modules/web_shop/web.py
=====================================
@@ -27,7 +27,7 @@
 class Inactivate(ModelSQL, DeactivableMixin):
 
     @classmethod
-    def search_domain(cls, domain, active_test=True, tables=None):
+    def search_domain(cls, domain, active_test=None, tables=None):
         context = Transaction().context
         if context.get('inactive_test'):
             domain = [domain, ('active', '=', False)]


=====================================
trytond/doc/ref/models.rst
=====================================
@@ -605,6 +605,7 @@
 .. classmethod:: ModelSQL.search(domain[, offset[, limit[, order[, count[, 
query]]]]])
 
    Same as :meth:`ModelStorage.search` with the additional ``query`` argument.
+   The ``domain`` is converted by :meth:`~ModelSQL.search_domain`.
 
    If ``query`` is set to ``True``, the the result is the SQL query.
 
@@ -613,6 +614,9 @@
    Convert a :ref:`domain <topics-domain>` into a SQL expression by returning
    the updated tables dictionary and a SQL expression.
 
+   If ``active_test`` is set to ``False``, no clause against
+   :attr:`DeactivableMixin.active` field is added to the domain.
+
    .. _ref-tables:
 
    Where ``tables`` is a nested dictionary containing the existing joins::
@@ -1072,7 +1076,7 @@
 
 Class attributes are:
 
-.. attribute:: DictSchemaMixin.active
+.. attribute:: DeactivableMixin.active
 
    The definition of the :class:`trytond.model.fields.Boolean` field to store
    soft deletion state.


=====================================
trytond/doc/ref/transaction.rst
=====================================
@@ -68,7 +68,7 @@
 
 .. attribute:: Transaction.active_records
 
-   If the active test is enabled.
+   If the active test is enabled for :class:`~trytond.model.DeactivableMixin`.
 
 .. staticmethod:: Transaction.monotonic_time
 


=====================================
trytond/trytond/model/modelsql.py
=====================================
@@ -1856,9 +1856,9 @@
         return cls.browse([x['id'] for x in rows])
 
     @classmethod
-    def search_domain(cls, domain, active_test=True, tables=None):
+    def search_domain(cls, domain, active_test=None, tables=None):
         '''
         Return SQL tables and expression
         Set active_test to add it.
         '''
         transaction = Transaction()
@@ -1860,8 +1860,10 @@
         '''
         Return SQL tables and expression
         Set active_test to add it.
         '''
         transaction = Transaction()
+        if active_test is None:
+            active_test = transaction.active_records
         domain = cls._search_domain_active(domain, active_test=active_test)
 
         if tables is None:


=====================================
trytond/trytond/model/modelstorage.py
=====================================
@@ -595,10 +595,8 @@
         # reduce_domain return a new instance so we can safety modify domain
         domain = reduce_domain(domain)
         # if the object has a field named 'active', filter out all inactive
-        # records unless they were explicitely asked for
-        if not ('active' in cls._fields
-                and active_test
-                and Transaction().active_records):
+        # records unless they were explicitly asked for
+        if not ('active' in cls._fields and active_test):
             return domain
 
         def process(domain):



View it on Heptapod: 
https://foss.heptapod.net/tryton/tryton/-/compare/a68700c8e1f6c252ad518dd412e3526110e766a9...1a79f3058e6cf82c0a9a0bee19eff9703b041f3d

-- 
View it on Heptapod: 
https://foss.heptapod.net/tryton/tryton/-/compare/a68700c8e1f6c252ad518dd412e3526110e766a9...1a79f3058e6cf82c0a9a0bee19eff9703b041f3d
You're receiving this email because of your account on foss.heptapod.net.


Reply via email to