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.

59 lines
2.1 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_invoicing_type = fields.Selection(
  26. [('pre-paid', 'Pre-paid'), ('post-paid', 'Post-paid')],
  27. default='pre-paid',
  28. string='Invoicing type',
  29. help="Specify if process date is 'from' or 'to' invoicing date",
  30. )
  31. is_auto_renew = fields.Boolean(string="Auto Renew", default=False)
  32. termination_notice_interval = fields.Integer(
  33. default=1, string='Termination Notice Before'
  34. )
  35. termination_notice_rule_type = fields.Selection(
  36. [('daily', 'Day(s)'), ('weekly', 'Week(s)'), ('monthly', 'Month(s)')],
  37. default='monthly',
  38. string='Termination Notice type',
  39. )
  40. @api.onchange('is_contract')
  41. def _change_is_contract(self):
  42. """ Clear the relation to contract_template_id when downgrading
  43. product from contract
  44. """
  45. if not self.is_contract:
  46. self.contract_template_id = False
  47. @api.constrains('is_contract', 'type')
  48. def _check_contract_product_type(self):
  49. """
  50. Contract product should be service type
  51. """
  52. if self.is_contract and self.type != 'service':
  53. raise ValidationError(_("Contract product should be service type"))