1
0
forked from Mapan/odoo17e
odoo17e-kedaikipas58/addons/pos_blackbox_be/models/res_users.py
2024-12-10 09:04:09 +07:00

45 lines
1.4 KiB
Python

from odoo import models, fields, api
from odoo.exceptions import ValidationError
from odoo.tools.translate import _
class ResUser(models.Model):
_inherit = "res.users"
# bis number is for foreigners in Belgium
insz_or_bis_number = fields.Char(
"INSZ or BIS number",
help="Social security identification number",
)
session_clocked_ids = fields.Many2many(
"pos.session",
"users_session_clocking_info",
string="Session Clocked In",
help="This is a technical field used for tracking the status of the session for each users.",
)
@property
def SELF_READABLE_FIELDS(self):
return super().SELF_READABLE_FIELDS + ["insz_or_bis_number"]
@property
def SELF_WRITEABLE_FIELDS(self):
return super().SELF_WRITEABLE_FIELDS + ["insz_or_bis_number"]
@api.constrains("insz_or_bis_number")
def _check_insz_or_bis_number(self):
for rec in self:
if rec.insz_or_bis_number and not self.is_valid_insz_or_bis_number(rec.insz_or_bis_number):
raise ValidationError(_("The INSZ or BIS number is not valid."))
def is_valid_insz_or_bis_number(self, number):
if not number:
return False
if len(number) != 11 or not number.isdigit():
return False
partial_number = number[:-2]
modulo = int(partial_number) % 97
return modulo == 97 - int(number[-2:])