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.

75 lines
2.5 KiB

  1. # Copyright 2017 LasLabs Inc.
  2. # Copyright 2018 ACSONE SA/NV.
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from odoo import api, fields, models, _
  5. from odoo.exceptions import ValidationError
  6. class ProductTemplate(models.Model):
  7. _inherit = 'product.template'
  8. is_contract = fields.Boolean('Is a contract')
  9. contract_template_id = fields.Many2one(
  10. comodel_name='account.analytic.contract', string='Contract Template'
  11. )
  12. recurring_rule_type = fields.Selection(
  13. [
  14. ('daily', 'Day(s)'),
  15. ('weekly', 'Week(s)'),
  16. ('monthly', 'Month(s)'),
  17. ('monthlylastday', 'Month(s) last day'),
  18. ('yearly', 'Year(s)'),
  19. ],
  20. default='monthly',
  21. string='Recurrence',
  22. help="Specify Interval for automatic invoice generation.",
  23. )
  24. recurring_invoicing_type = fields.Selection(
  25. [('pre-paid', 'Pre-paid'), ('post-paid', 'Post-paid')],
  26. default='pre-paid',
  27. string='Invoicing type',
  28. help="Specify if process date is 'from' or 'to' invoicing date",
  29. )
  30. recurring_interval = fields.Integer(
  31. default=1,
  32. string='Repeat Every',
  33. help="Repeat every (Days/Week/Month/Year)",
  34. )
  35. is_auto_renew = fields.Boolean(string="Auto Renew", default=False)
  36. auto_renew_interval = fields.Integer(
  37. default=1,
  38. string='Renew Every',
  39. help="Renew every (Days/Week/Month/Year)",
  40. )
  41. auto_renew_rule_type = fields.Selection(
  42. [('monthly', 'Month(s)'), ('yearly', 'Year(s)')],
  43. default='yearly',
  44. string='Renewal type',
  45. help="Specify Interval for automatic renewal.",
  46. )
  47. termination_notice_interval = fields.Integer(
  48. default=1, string='Termination Notice Before'
  49. )
  50. termination_notice_rule_type = fields.Selection(
  51. [('daily', 'Day(s)'), ('weekly', 'Week(s)'), ('monthly', 'Month(s)')],
  52. default='monthly',
  53. string='Termination Notice type',
  54. )
  55. @api.onchange('is_contract')
  56. def _change_is_contract(self):
  57. """ Clear the relation to contract_template_id when downgrading
  58. product from contract
  59. """
  60. if not self.is_contract:
  61. self.contract_template_id = False
  62. @api.constrains('is_contract', 'type')
  63. def _check_contract_product_type(self):
  64. """
  65. Contract product should be service type
  66. """
  67. if self.is_contract and self.type != 'service':
  68. raise ValidationError(_("Contract product should be service type"))