|
@ -1,18 +1,24 @@ |
|
|
# Copyright 2016 Antonio Espinosa |
|
|
# Copyright 2016 Antonio Espinosa |
|
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
|
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
|
|
|
|
|
|
|
|
from odoo import _, api, models |
|
|
|
|
|
|
|
|
from odoo import _, api, fields, models |
|
|
from odoo.exceptions import ValidationError |
|
|
from odoo.exceptions import ValidationError |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ResPartner(models.Model): |
|
|
class ResPartner(models.Model): |
|
|
_inherit = "res.partner" |
|
|
_inherit = "res.partner" |
|
|
|
|
|
|
|
|
|
|
|
# This related is needed in order to trigger the check when changing the |
|
|
|
|
|
# value on res.company |
|
|
|
|
|
partner_ref_unique = fields.Selection( |
|
|
|
|
|
related='company_id.partner_ref_unique', store=True, |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
@api.multi |
|
|
@api.multi |
|
|
@api.constrains('ref', 'is_company', 'company_id') |
|
|
|
|
|
|
|
|
@api.constrains('ref', 'is_company', 'company_id', 'partner_ref_unique') |
|
|
def _check_ref(self): |
|
|
def _check_ref(self): |
|
|
for partner in self: |
|
|
for partner in self: |
|
|
mode = partner.company_id.partner_ref_unique |
|
|
|
|
|
|
|
|
mode = partner.partner_ref_unique |
|
|
if (partner.ref and ( |
|
|
if (partner.ref and ( |
|
|
mode == 'all' or |
|
|
mode == 'all' or |
|
|
(mode == 'companies' and partner.is_company))): |
|
|
(mode == 'companies' and partner.is_company))): |
|
|