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.

55 lines
1.7 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  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="Duration in seconds",
  19. )
  20. duration_txt = fields.Char(
  21. string="Duration",
  22. compute="_get_duration",
  23. store=True,
  24. )
  25. @api.depends("date_start", "date_done")
  26. def _get_duration(self):
  27. for input in self:
  28. start = input.date_start
  29. done = input.date_done
  30. if not start:
  31. input.duration = 0
  32. input.duration_txt = _("Not started yet")
  33. elif not done:
  34. input.duration = 0
  35. input.duration_txt = _("Not done yet")
  36. else:
  37. input.duration = int((done - start).total_seconds())
  38. input.duration_txt = self.env["ir.qweb.field.duration"].value_to_html(
  39. (done - start).total_seconds(),
  40. {"unit": "second", "round": "second"},
  41. )
  42. @api.multi
  43. def write(self, vals):
  44. if vals.get("state", False) == "done":
  45. vals.update(
  46. {
  47. "date_done": fields.Datetime.now(),
  48. }
  49. )
  50. return super(SurveyUserInput, self).write(vals)