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.

40 lines
1.2 KiB

  1. # -*- coding: utf-8 -*-
  2. # © 2017 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  4. from odoo import models, fields
  5. class Agreement(models.Model):
  6. _name = 'agreement'
  7. _description = 'Agreement'
  8. code = fields.Char(required=True, copy=False)
  9. name = fields.Char(required=True)
  10. partner_id = fields.Many2one(
  11. 'res.partner', string='Partner', ondelete='restrict', required=True,
  12. domain=[('parent_id', '=', False)])
  13. company_id = fields.Many2one(
  14. 'res.company', string='Company',
  15. default=lambda self: self.env['res.company']._company_default_get(
  16. 'agreement'))
  17. active = fields.Boolean(default=True)
  18. signature_date = fields.Date()
  19. start_date = fields.Date()
  20. end_date = fields.Date()
  21. def name_get(self):
  22. res = []
  23. for agr in self:
  24. name = agr.name
  25. if agr.code:
  26. name = u'[%s] %s' % (agr.code, agr.name)
  27. res.append((agr.id, name))
  28. return res
  29. _sql_constraints = [(
  30. 'code_partner_company_unique',
  31. 'unique(code, partner_id, company_id)',
  32. 'This agreement code already exists for this partner!'
  33. )]