Skip to Content
मेन्यू
This question has been flagged
1 Reply
276 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
अप्रैल 25
539
0
जन॰ 25
946
0
जन॰ 25
1048
1
जुल॰ 25
514
1
मई 25
1053