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.

39 lines
1.2 KiB

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