Commits

Bruno Villasanti committed 0b969a7

health_invoice : Fix wrong on_change_appointment_date function

Appointment validity date not calculated on appointment date changes.

Fix bug #35905 : https://savannah.gnu.org/bugs/index.php?35905

  • Participants
  • Parent commits 45135a4

Comments (0)

Files changed (1)

File tryton/health_invoice/health_invoice.py

 #
 ##############################################################################
 
-from datetime import datetime
+from datetime import timedelta
 from trytond.model import ModelView, ModelSQL, fields
 from trytond.pyson import Eval, Not, Equal, If, In, Bool, Get, Or, And, \
         PYSONEncoder
         default.update({'validity_status': 'tobe'})
         return super(Appointment, self).copy(ids, default=default)
 
-    # TODO
     def on_change_appointment_date(self, apt_date):
         if apt_date:
-            validity_date = datetime.datetime.fromtimestamp(
-                    time.mktime(time.strptime(apt_date, '%Y-%m-%d %H:%M:%S')))
-            validity_date = validity_date + datetime.timedelta(days=7)
-            v = {'appointment_validity_date': str(validity_date)}
-            return {'value': v}
+            validity_date = apt_date['appointment_date']
+            validity_date += timedelta(days=7)
+            return {'appointment_validity_date': validity_date}
         return {}
 
     no_invoice = fields.Boolean('Invoice exempt',
         states={'invisible': Equal(Eval('validity_status'), 'invoiced')},
         depends=['validity_status'])
+    appointment_date = fields.DateTime('Date and Time',
+        on_change=['appointment_date'])
     appointment_validity_date = fields.DateTime('Validity Date')
     validity_status = fields.Selection([
         ('invoiced', 'Invoiced'),