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.

50 lines
1.5 KiB

5 years ago
5 years ago
  1. # © 2017 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  3. from odoo import models, fields
  4. class Agreement(models.Model):
  5. _name = 'agreement'
  6. _description = 'Agreement'
  7. code = fields.Char(required=True, copy=False)
  8. name = fields.Char(required=True)
  9. partner_id = fields.Many2one(
  10. 'res.partner', string='Partner', ondelete='restrict',
  11. domain=[('parent_id', '=', False)])
  12. company_id = fields.Many2one(
  13. 'res.company', string='Company',
  14. default=lambda self: self.env['res.company']._company_default_get())
  15. is_template = fields.Boolean(
  16. string="Is a Template?",
  17. default=False,
  18. copy=False,
  19. help="Set if the agreement is a template. "
  20. "Template agreements don't require a partner."
  21. )
  22. agreement_type_id = fields.Many2one(
  23. 'agreement.type',
  24. string="Agreement Type",
  25. help="Select the type of agreement",
  26. )
  27. active = fields.Boolean(default=True)
  28. signature_date = fields.Date()
  29. start_date = fields.Date()
  30. end_date = fields.Date()
  31. def name_get(self):
  32. res = []
  33. for agr in self:
  34. name = agr.name
  35. if agr.code:
  36. name = '[%s] %s' % (agr.code, agr.name)
  37. res.append((agr.id, name))
  38. return res
  39. _sql_constraints = [(
  40. 'code_partner_company_unique',
  41. 'unique(code, partner_id, company_id)',
  42. 'This agreement code already exists for this partner!'
  43. )]