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.

38 lines
1.2 KiB

6 years ago
6 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', required=True,
  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. active = fields.Boolean(default=True)
  16. signature_date = fields.Date()
  17. start_date = fields.Date()
  18. end_date = fields.Date()
  19. def name_get(self):
  20. res = []
  21. for agr in self:
  22. name = agr.name
  23. if agr.code:
  24. name = '[%s] %s' % (agr.code, agr.name)
  25. res.append((agr.id, name))
  26. return res
  27. _sql_constraints = [(
  28. 'code_partner_company_unique',
  29. 'unique(code, partner_id, company_id)',
  30. 'This agreement code already exists for this partner!'
  31. )]