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.

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