changeset c5655dd9a3b9 in trytond:default
details: https://hg.tryton.org/trytond?cmd=changeset&node=c5655dd9a3b9
description:
        Add datetime_field, filename and digits to display_depends

        issue11134
diffstat:

 trytond/model/fields/binary.py    |  14 ++++++++------
 trytond/model/fields/float.py     |   6 ------
 trytond/model/fields/many2many.py |  12 +++++++-----
 trytond/model/fields/many2one.py  |  14 ++++++++------
 trytond/model/fields/one2many.py  |  12 +++++++-----
 5 files changed, 30 insertions(+), 28 deletions(-)

diffs (150 lines):

diff -r 5ffe1365040e -r c5655dd9a3b9 trytond/model/fields/binary.py
--- a/trytond/model/fields/binary.py    Fri Apr 08 21:56:25 2022 +0200
+++ b/trytond/model/fields/binary.py    Sat Apr 09 00:05:27 2022 +0200
@@ -3,7 +3,7 @@
 from sql import Column, Null
 
 from trytond.filestore import filestore
-from trytond.tools import grouped_slice, reduce_ids
+from trytond.tools import cached_property, grouped_slice, reduce_ids
 from trytond.transaction import Transaction
 
 from .field import Field
@@ -22,11 +22,6 @@
             on_change_with=None, depends=None, context=None, loading='lazy',
             filename=None, file_id=None, store_prefix=None):
         self.filename = filename
-        if filename is not None:
-            if depends is None:
-                depends = [filename]
-            else:
-                depends.append(filename)
         self.file_id = file_id
         self.store_prefix = store_prefix
         super(Binary, self).__init__(string=string, help=help,
@@ -34,6 +29,13 @@
             select=select, on_change=on_change, on_change_with=on_change_with,
             depends=depends, context=context, loading=loading)
 
+    @cached_property
+    def display_depends(self):
+        depends = super().display_depends
+        if self.filename:
+            depends.add(self.filename)
+        return depends
+
     def get(self, ids, model, name, values=None):
         '''
         Convert the binary value into ``bytes``
diff -r 5ffe1365040e -r c5655dd9a3b9 trytond/model/fields/float.py
--- a/trytond/model/fields/float.py     Fri Apr 08 21:56:25 2022 +0200
+++ b/trytond/model/fields/float.py     Sat Apr 09 00:05:27 2022 +0200
@@ -42,12 +42,6 @@
         :param digits: a list of two integers defining the total
             of digits and the number of decimals of the float.
         '''
-        if isinstance(digits, str):
-            if depends is None:
-                depends = [digits]
-            elif digits not in depends:
-                depends = depends.copy()
-                depends.append(digits)
         super(Float, self).__init__(string=string, help=help,
             required=required, readonly=readonly, domain=domain, states=states,
             select=select, on_change=on_change, on_change_with=on_change_with,
diff -r 5ffe1365040e -r c5655dd9a3b9 trytond/model/fields/many2many.py
--- a/trytond/model/fields/many2many.py Fri Apr 08 21:56:25 2022 +0200
+++ b/trytond/model/fields/many2many.py Sat Apr 09 00:05:27 2022 +0200
@@ -44,11 +44,6 @@
         :param search_context: The context to use when searching for a record
         :param filter: A domain to filter target records.
         '''
-        if datetime_field:
-            if depends:
-                depends.append(datetime_field)
-            else:
-                depends = [datetime_field]
         super(Many2Many, self).__init__(string=string, help=help,
             required=required, readonly=readonly, domain=domain, states=states,
             on_change=on_change, on_change_with=on_change_with,
@@ -111,6 +106,13 @@
         return self.domain
 
     @cached_property
+    def display_depends(self):
+        depends = super().display_depends
+        if self.datetime_field:
+            depends.add(self.datetime_field)
+        return depends
+
+    @cached_property
     def edition_depends(self):
         depends = super().edition_depends
         depends |= get_eval_fields(self.size)
diff -r 5ffe1365040e -r c5655dd9a3b9 trytond/model/fields/many2one.py
--- a/trytond/model/fields/many2one.py  Fri Apr 08 21:56:25 2022 +0200
+++ b/trytond/model/fields/many2one.py  Sat Apr 09 00:05:27 2022 +0200
@@ -7,7 +7,7 @@
 
 from trytond.pool import Pool
 from trytond.pyson import PYSONEncoder
-from trytond.tools import reduce_ids
+from trytond.tools import cached_property, reduce_ids
 from trytond.transaction import Transaction
 
 from .field import (
@@ -48,11 +48,6 @@
         if ondelete not in ('CASCADE', 'RESTRICT', 'SET NULL'):
             raise Exception('Bad arguments')
         self.ondelete = ondelete
-        if datetime_field:
-            if depends:
-                depends.append(datetime_field)
-            else:
-                depends = [datetime_field]
         super(Many2One, self).__init__(string=string, help=help,
             required=required, readonly=readonly, domain=domain, states=states,
             select=select, on_change=on_change, on_change_with=on_change_with,
@@ -98,6 +93,13 @@
         context_validate(value)
         self.__search_context = value
 
+    @cached_property
+    def display_depends(self):
+        depends = super().display_depends
+        if self.datetime_field:
+            depends.add(self.datetime_field)
+        return depends
+
     def get_target(self):
         'Return the target Model'
         return Pool().get(self.model_name)
diff -r 5ffe1365040e -r c5655dd9a3b9 trytond/model/fields/one2many.py
--- a/trytond/model/fields/one2many.py  Fri Apr 08 21:56:25 2022 +0200
+++ b/trytond/model/fields/one2many.py  Sat Apr 09 00:05:27 2022 +0200
@@ -45,11 +45,6 @@
         :param search_context: The context to use when searching for a record
         :param filter: A domain to filter target records.
         '''
-        if datetime_field:
-            if depends:
-                depends.append(datetime_field)
-            else:
-                depends = [datetime_field]
         super(One2Many, self).__init__(string=string, help=help,
             required=required, readonly=readonly, domain=domain, states=states,
             on_change=on_change, on_change_with=on_change_with,
@@ -109,6 +104,13 @@
         self.__search_context = value
 
     @cached_property
+    def display_depends(self):
+        depends = super().display_depends
+        if self.datetime_field:
+            depends.add(self.datetime_field)
+        return depends
+
+    @cached_property
     def edition_depends(self):
         depends = super().edition_depends
         for attribute in ['add_remove', 'size']:

Reply via email to