Odoo modules related to surveys
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.3 KiB

  1. from odoo import models, fields, api, _
  2. class SurveyUserInput(models.Model):
  3. _inherit = "survey.user_input"
  4. date_start = fields.Datetime(
  5. string="Start date",
  6. readonly=True,
  7. help='This date is set when the user clicks on "Start survey" button for the first time.',
  8. )
  9. date_done = fields.Datetime(
  10. string="Date done",
  11. readonly=True,
  12. help='This date is set when the user input is set ton "Done" status.',
  13. )
  14. duration = fields.Integer(
  15. string="Duration",
  16. compute="_get_duration",
  17. store=True,
  18. help="Time expressed in seconds, neet 'duration' widget to be read by user.",
  19. )
  20. @api.depends("date_start", "date_stop")
  21. def _get_duration(self):
  22. for input in self:
  23. start = input.date_start
  24. done = input.date_done
  25. if not start and done:
  26. input.duration = 0
  27. else:
  28. input.duration = int((done - start).total_seconds())
  29. @api.multi
  30. def write(self, vals):
  31. if vals.get("state", False) == "done":
  32. vals.update(
  33. {
  34. "date_done": fields.Datetime.now(),
  35. }
  36. )
  37. return super(SurveyUserInput, self).write(vals)