mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[IMP]pms: validate number doc in checkin partner model
This commit is contained in:
@@ -6,7 +6,8 @@ import json
|
|||||||
import re
|
import re
|
||||||
|
|
||||||
from odoo import _, api, fields, models
|
from odoo import _, api, fields, models
|
||||||
from odoo.exceptions import ValidationError
|
from odoo.exceptions import UserError, ValidationError
|
||||||
|
from odoo.tools.safe_eval import safe_eval
|
||||||
|
|
||||||
|
|
||||||
class PmsCheckinPartner(models.Model):
|
class PmsCheckinPartner(models.Model):
|
||||||
@@ -470,6 +471,45 @@ class PmsCheckinPartner(models.Model):
|
|||||||
if record.document_number != number.name:
|
if record.document_number != number.name:
|
||||||
raise ValidationError(_("Document_type has already exists"))
|
raise ValidationError(_("Document_type has already exists"))
|
||||||
|
|
||||||
|
def _validation_eval_context(self, id_number):
|
||||||
|
self.ensure_one()
|
||||||
|
return {"self": self, "id_number": id_number}
|
||||||
|
|
||||||
|
@api.constrains("document_number", "document_type")
|
||||||
|
def validate_id_number(self):
|
||||||
|
"""Validate the given ID number
|
||||||
|
The method raises an odoo.exceptions.ValidationError if the eval of
|
||||||
|
python validation code fails
|
||||||
|
"""
|
||||||
|
for record in self:
|
||||||
|
if record.document_number and record.document_type:
|
||||||
|
if (
|
||||||
|
self.env.context.get("id_no_validate")
|
||||||
|
or not record.document_type.validation_code
|
||||||
|
):
|
||||||
|
return
|
||||||
|
eval_context = record._validation_eval_context(record.document_number)
|
||||||
|
try:
|
||||||
|
safe_eval(
|
||||||
|
record.document_type.validation_code,
|
||||||
|
eval_context,
|
||||||
|
mode="exec",
|
||||||
|
nocopy=True,
|
||||||
|
)
|
||||||
|
except Exception as e:
|
||||||
|
raise UserError(
|
||||||
|
_(
|
||||||
|
"Error when evaluating the id_category validation code:"
|
||||||
|
":\n %s \n(%s)"
|
||||||
|
)
|
||||||
|
% (self.name, e)
|
||||||
|
)
|
||||||
|
if eval_context.get("failed", False):
|
||||||
|
raise ValidationError(
|
||||||
|
_("%s is not a valid %s identifier")
|
||||||
|
% (record.document_number, record.document_type.name)
|
||||||
|
)
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def create(self, vals):
|
def create(self, vals):
|
||||||
# The checkin records are created automatically from adult depends
|
# The checkin records are created automatically from adult depends
|
||||||
|
|||||||
@@ -319,30 +319,6 @@ class ResPartner(models.Model):
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
@api.model
|
|
||||||
def name_search(self, name, args=None, operator="ilike", limit=100):
|
|
||||||
if not args:
|
|
||||||
args = []
|
|
||||||
domain = [
|
|
||||||
"|",
|
|
||||||
("mobile", operator, name),
|
|
||||||
]
|
|
||||||
partners = self.search(
|
|
||||||
domain + args,
|
|
||||||
limit=limit,
|
|
||||||
)
|
|
||||||
res = partners.name_get()
|
|
||||||
if limit:
|
|
||||||
limit_rest = limit - len(partners)
|
|
||||||
else:
|
|
||||||
limit_rest = limit
|
|
||||||
if limit_rest or not limit:
|
|
||||||
args += [("id", "not in", partners.ids)]
|
|
||||||
res += super(ResPartner, self).name_search(
|
|
||||||
name, args=args, operator=operator, limit=limit_rest
|
|
||||||
)
|
|
||||||
return res
|
|
||||||
|
|
||||||
@api.constrains("is_agency", "sale_channel_id")
|
@api.constrains("is_agency", "sale_channel_id")
|
||||||
def _check_is_agency(self):
|
def _check_is_agency(self):
|
||||||
for record in self:
|
for record in self:
|
||||||
|
|||||||
Reference in New Issue
Block a user