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.

65 lines
2.2 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='contract.template', string='Contract Template'
  11. )
  12. default_qty = fields.Integer(string="Default Quantity", default=1)
  13. recurring_rule_type = fields.Selection(
  14. [
  15. ('daily', 'Day(s)'),
  16. ('weekly', 'Week(s)'),
  17. ('monthly', 'Month(s)'),
  18. ('monthlylastday', 'Month(s) last day'),
  19. ('yearly', 'Year(s)'),
  20. ],
  21. default='monthly',
  22. string='Invoice Every',
  23. help="Specify Interval for automatic invoice generation.",
  24. )
  25. recurring_interval = fields.Integer(
  26. default=1,
  27. string='Invoice Every',
  28. help="Invoice every (Days/Week/Month/Year)",
  29. required=True,
  30. )
  31. recurring_invoicing_type = fields.Selection(
  32. [('pre-paid', 'Pre-paid'), ('post-paid', 'Post-paid')],
  33. default='pre-paid',
  34. string='Invoicing type',
  35. help="Specify if process date is 'from' or 'to' invoicing date",
  36. )
  37. is_auto_renew = fields.Boolean(string="Auto Renew", default=False)
  38. termination_notice_interval = fields.Integer(
  39. default=1, string='Termination Notice Before'
  40. )
  41. termination_notice_rule_type = fields.Selection(
  42. [('daily', 'Day(s)'), ('weekly', 'Week(s)'), ('monthly', 'Month(s)')],
  43. default='monthly',
  44. string='Termination Notice type',
  45. )
  46. @api.onchange('is_contract')
  47. def _change_is_contract(self):
  48. """ Clear the relation to contract_template_id when downgrading
  49. product from contract
  50. """
  51. if not self.is_contract:
  52. self.contract_template_id = False
  53. @api.constrains('is_contract', 'type')
  54. def _check_contract_product_type(self):
  55. """
  56. Contract product should be service type
  57. """
  58. if self.is_contract and self.type != 'service':
  59. raise ValidationError(_("Contract product should be service type"))