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.

48 lines
1.7 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. agreement_type = fields.Selection([
  11. ('sale', 'Sale'),
  12. ('purchase', 'Purchase'),
  13. ], string='Type', required=True)
  14. partner_id = fields.Many2one(
  15. 'res.partner', string='Partner', ondelete='restrict', required=True,
  16. domain=[('parent_id', '=', False)])
  17. company_id = fields.Many2one(
  18. 'res.company', string='Company',
  19. default=lambda self: self.env['res.company']._company_default_get(
  20. 'agreement'))
  21. active = fields.Boolean(default=True)
  22. signature_date = fields.Date()
  23. out_invoice_ids = fields.One2many(
  24. 'account.invoice', 'agreement_id', string='Customer Invoices',
  25. readonly=True, domain=[('type', 'in', ('out_invoice', 'out_refund'))])
  26. in_invoice_ids = fields.One2many(
  27. 'account.invoice', 'agreement_id', string='Supplier Invoices',
  28. readonly=True, domain=[('type', 'in', ('in_invoice', 'in_refund'))])
  29. def name_get(self):
  30. res = []
  31. for agr in self:
  32. name = agr.name
  33. if agr.code:
  34. name = u'[%s] %s' % (agr.code, agr.name)
  35. res.append((agr.id, name))
  36. return res
  37. _sql_constraints = [(
  38. 'code_partner_company_unique',
  39. 'unique(code, partner_id, company_id)',
  40. 'This agreement code already exists for this partner!'
  41. )]