Skip to Content
Menu
This question has been flagged
1 Reply
259 Views

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
Discard
Best Answer

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
Discard
Related Posts Replies Views Activity
1
Apr 25
519
0
Jan 25
928
0
Jan 25
1036
1
Jul 25
432
1
May 25
990