Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

2

Show Account Number(Partial or Semi Visible Number) Formatting in OpenERP 7.0

By
komala kiran kumar. Parepalli
on 6/20/14, 3:45 AM 1,116 views

HI All,

Here I am in a situation to display either a charecter or integer field which is capable to store a 10 digit value,

and need to display it in semi password/ semi visible format.

I mean if the account number is 9876543210123, i just want to show 987*******123 in the list or tree view.

Can anyone help me to do the above formatting, Is there any default widget available.

Also any suggestions for creating a custom widget or any other way to acheive the above need is appeciable.

Thanks In Advance.

This question has been included in the official documentation.
1

Serpent Consulting Services Pvt. Ltd.

--Serpent Consulting Services Pvt. Ltd.--
4341
| 6 6 8
Gandhinagar, India
--Serpent Consulting Services Pvt. Ltd.--

Serpent Consulting Services Pvt. Ltd. Your Odoo/OpenERP Solution, just an email away!

Serpent Consulting Services Pvt. Ltd.
On 6/20/14, 9:26 AM

Komala Kiran Kumar,

If you want the whole text as *, use widget="password", or password='1'.

You can override the read method which can do the job better.

See the example:

vals = super(account_voucher, self).read(cr, uid, ids, fields, context, load)
        for val in vals:
            if val.get('cc_number', False) :
                dec_data = rsa_encrypt.decrypt(val.get('cc_number', False), val.get('key', False))
                val['cc_number'] = dec_data
                if context.get('cc_no', '') != 'no_mask':
                    i = len(val['cc_number']) - 4
                    val['cc_number'] = 'X' * i + val['cc_number'][-4:len(val['cc_number'])]
        if not is_list:
            vals = vals[0]
        return vals

Thanks.

Hi, This has really helped me, but i am here with a small problem where as in form view also it is showing the same, but i just want to show that in Tree or List view

komala kiran kumar. Parepalli
on 6/20/14, 12:01 PM

Dear Friend, you may do this based on context. Set context on the xml definition and check!

Serpent Consulting Services Pvt. Ltd.
on 6/21/14, 3:33 AM
This question has been included in the official documentation.
0
Bruno PLANCHER
On 1/7/15, 6:33 AM

Hello Komala,

Based of the answer of Serpent CS, you can also create a new char field (fields.function), which will store the formatted value based on the original one. With this, you could use your original field in the form view, and only display the new computed field in your list.

The solution of Serpent CS (using the context to customize the value returned by read() ) is a bit simple than mine to implement, but i prefer not to override the read() method for each customization (this is more difficult to maintain and less optimized than a dedicated field) ^^

Finally, it is easier to define the groups access when 2 different fields are defined (one for users having 'full' access to sensitve data, the other for 'restricted' access users).

For this function field, you can make it with the parameter store to True (as the original value is on the same model), and use the method posted by Serpent CS to compute the value. For example : 

'new_field': fields.function(_get_formatted_account, type='char', method=True, store=True)  # get_formatted_account is the method to define with the code of Serpent CS

# for optimiaztion: store={'your.model.name': (lambda self, cr, uid, ids, ctx: ids, ['your_account_field'], 10)}

Hope it helps you,

Regards

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 6/20/14, 3:45 AM
Seen: 1116 times
Last updated: 3/16/15, 8:10 AM