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.

41 lines
1.1 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2016-2017 LasLabs Inc.
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from odoo import api, fields, models, _
  5. from odoo.exceptions import ValidationError
  6. class ResPartnerAlias(models.Model):
  7. _inherits = {'res.partner': 'partner_id'}
  8. _name = 'res.partner.alias'
  9. _description = 'Res Partner Alias'
  10. partner_id = fields.Many2one(
  11. string='Related Partner',
  12. comodel_name='res.partner',
  13. required=True,
  14. ondelete='cascade',
  15. index=True,
  16. )
  17. firstname = fields.Char(
  18. string='First Name',
  19. required=True,
  20. )
  21. @api.multi
  22. @api.constrains('firstname')
  23. def _check_firstname(self):
  24. for record in self:
  25. if record.firstname == record.partner_id.firstname:
  26. raise ValidationError(_(
  27. 'Alias first name cannot be the same as '
  28. 'primary firstname'
  29. ))
  30. _sql_constraints = [
  31. ('alias_name_uniq',
  32. 'UNIQUE(firstname)',
  33. 'Alias first name must be unique'),
  34. ]