Se rendre au contenu
Menu
Cette question a été signalée
1 Répondre
359 Vues

Dear All,


One of our customer requesting for encrypting Email IDs, Phone Numeber, Mobile Number for security purposes.

Does Odoo support encrypting personal information such as Email ID, Phone Number , Mobile Number etc.,?

If not so, Is there any readymade solution available to acheive this?


Thanks,

Odoo@Tenthplanet


Avatar
Ignorer
Meilleure réponse

Hi,

Try the following code,


from odoo import models, fields, api

from cryptography.fernet import Fernet

import base64


KEY = b'your_32_byte_key_here=='  # You must securely store this key

cipher = Fernet(KEY)


class ResPartner(models.Model):

    _inherit = 'res.partner'


    _encrypted_email = fields.Char(string="Encrypted Email", readonly=True)


    @api.depends('_encrypted_email')

    def _compute_email(self):

        for rec in self:

            try:

                rec.email = cipher.decrypt(rec._encrypted_email.encode()).decode()

            except:

                rec.email = ''


    email = fields.Char(compute="_compute_email", inverse="_inverse_email", store=True)


    def _inverse_email(self):

        for rec in self:

            if rec.email:

                rec._encrypted_email = cipher.encrypt(rec.email.encode()).decode()


Hope it helps


Avatar
Ignorer
Publications associées Réponses Vues Activité
1
avr. 25
620
0
janv. 25
1002
0
janv. 25
1102
1
août 25
175
1
juil. 25
670