24 lines
817 B
Python
24 lines
817 B
Python
from odoo import api, fields, models, _
|
|
from odoo.exceptions import ValidationError
|
|
|
|
import logging
|
|
|
|
_logger = logging.getLogger(__name__)
|
|
|
|
class ResPartner(models.Model):
|
|
_inherit = "res.partner"
|
|
|
|
def unlink(self):
|
|
env = self.env
|
|
|
|
for partner in self:
|
|
grants = env['grant.benefit'].search([
|
|
('partner_id', '=', partner.id),
|
|
('state', 'not in', ['draft', 'new'])
|
|
])
|
|
if grants:
|
|
grant_info = ', '.join('[%s: %s]' % (g.code or g.name or g.id, dict(g._fields['state'].selection).get(g.state)) for g in grants)
|
|
raise ValidationError(
|
|
_("Cannot delete partner '%s': linked to Benefits - Profiles %s") % (partner.name, grant_info)
|
|
)
|
|
return super().unlink() |