changeset b799d79f78b2 in modules/account_invoice_history:default
details: 
https://hg.tryton.org/modules/account_invoice_history?cmd=changeset;node=b799d79f78b2
description:
        Ensure the datetime is greater than the target creation

        The target may be replaced with a record created after the numbering for
        example to fix a duplicated party.

        issue9300
        review349101002
diffstat:

 account.py |  31 ++++++++++++++++++++++---------
 1 files changed, 22 insertions(+), 9 deletions(-)

diffs (48 lines):

diff -r d0edab59e5fd -r b799d79f78b2 account.py
--- a/account.py        Sat Dec 19 17:08:44 2020 +0100
+++ b/account.py        Mon Jan 11 00:02:13 2021 +0100
@@ -10,6 +10,9 @@
 class Invoice(metaclass=PoolMeta):
     __name__ = 'account.invoice'
     numbered_at = fields.Timestamp("Numbered At")
+    history_datetime = fields.Function(
+        fields.Timestamp("History DateTime"),
+        'get_history_datetime')
 
     @classmethod
     def __register__(cls, module_name):
@@ -30,15 +33,25 @@
     def __setup__(cls):
         super(Invoice, cls).__setup__()
         cls._check_modify_exclude.append('numbered_at')
-        cls.party.datetime_field = 'numbered_at'
-        if 'numbered_at' not in cls.party.depends:
-            cls.party.depends.append('numbered_at')
-        cls.invoice_address.datetime_field = 'numbered_at'
-        if 'numbered_at' not in cls.invoice_address.depends:
-            cls.invoice_address.depends.append('numbered_at')
-        cls.payment_term.datetime_field = 'numbered_at'
-        if 'numbered_at' not in cls.payment_term.depends:
-            cls.payment_term.depends.append('numbered_at')
+        cls.party.datetime_field = 'history_datetime'
+        if 'history_datetime' not in cls.party.depends:
+            cls.party.depends.append('history_datetime')
+        cls.invoice_address.datetime_field = 'history_datetime'
+        if 'history_datetime' not in cls.invoice_address.depends:
+            cls.invoice_address.depends.append('history_datetime')
+        cls.payment_term.datetime_field = 'history_datetime'
+        if 'history_datetime' not in cls.payment_term.depends:
+            cls.payment_term.depends.append('history_datetime')
+
+    def get_history_datetime(self, name):
+        values = [
+            self.numbered_at,
+            self.party.create_date,
+            self.invoice_address.create_date,
+            ]
+        if self.payment_term:
+            values.append(self.payment_term.create_date)
+        return max(values)
 
     @classmethod
     def set_number(cls, invoices):

Reply via email to