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.8 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. @api.onchange('is_contract')
  36. def _change_is_contract(self):
  37. """ Clear the relation to contract_template_id when downgrading
  38. product from contract
  39. """
  40. if not self.is_contract:
  41. self.contract_template_id = False
  42. @api.constrains('is_contract', 'type')
  43. def _check_contract_product_type(self):
  44. """
  45. Contract product should be service type
  46. """
  47. if self.is_contract and self.type != 'service':
  48. raise ValidationError(_("Contract product should be service type"))