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.

55 lines
1.6 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 fields, models
  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",
  11. string="Partner",
  12. ondelete="restrict",
  13. domain=[("parent_id", "=", False)],
  14. )
  15. company_id = fields.Many2one(
  16. "res.company",
  17. string="Company",
  18. default=lambda self: self.env["res.company"]._company_default_get(),
  19. )
  20. is_template = fields.Boolean(
  21. string="Is a Template?",
  22. default=False,
  23. copy=False,
  24. help="Set if the agreement is a template. "
  25. "Template agreements don't require a partner.",
  26. )
  27. agreement_type_id = fields.Many2one(
  28. "agreement.type", string="Agreement Type", help="Select the type of agreement"
  29. )
  30. active = fields.Boolean(default=True)
  31. signature_date = fields.Date()
  32. start_date = fields.Date()
  33. end_date = fields.Date()
  34. def name_get(self):
  35. res = []
  36. for agr in self:
  37. name = agr.name
  38. if agr.code:
  39. name = "[{}] {}".format(agr.code, agr.name)
  40. res.append((agr.id, name))
  41. return res
  42. _sql_constraints = [
  43. (
  44. "code_partner_company_unique",
  45. "unique(code, partner_id, company_id)",
  46. "This agreement code already exists for this partner!",
  47. )
  48. ]