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.

32 lines
1.0 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. @api.onchange('is_contract')
  14. def _change_is_contract(self):
  15. """ Clear the relation to contract_template_id when downgrading
  16. product from contract
  17. """
  18. if not self.is_contract:
  19. self.contract_template_id = False
  20. @api.constrains('is_contract', 'type')
  21. def _check_contract_product_type(self):
  22. """
  23. Contract product should be service type
  24. """
  25. if self.is_contract and self.type != 'service':
  26. raise ValidationError(_("Contract product should be service type"))