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.

56 lines
1.8 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2017 LasLabs Inc.
  3. # Copyright 2018 ACSONE SA/NV.
  4. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  5. from odoo import api, fields, models, _
  6. from odoo.exceptions import ValidationError
  7. class ProductTemplate(models.Model):
  8. _inherit = 'product.template'
  9. is_contract = fields.Boolean('Is a contract')
  10. contract_template_id = fields.Many2one(
  11. comodel_name='account.analytic.contract', string='Contract Template'
  12. )
  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='Recurrence',
  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. recurring_interval = fields.Integer(
  32. default=1,
  33. string='Repeat Every',
  34. help="Repeat every (Days/Week/Month/Year)",
  35. )
  36. @api.onchange('is_contract')
  37. def _change_is_contract(self):
  38. """ Clear the relation to contract_template_id when downgrading
  39. product from contract
  40. """
  41. if not self.is_contract:
  42. self.contract_template_id = False
  43. @api.constrains('is_contract', 'type')
  44. def _check_contract_product_type(self):
  45. """
  46. Contract product should be service type
  47. """
  48. if self.is_contract and self.type != 'service':
  49. raise ValidationError(_("Contract product should be service type"))