Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
8 Odpovědi
10330 Zobrazení

Hi, I'am developping a module where i have a field named "user_id" in this field i would like to fill lit automatically by the name of the current user, exactly like it's done in crm.lead module with the field vendor. I know a function named default_user_get is defined but i don't know in what module?. Thanks for your answers

Avatar
Zrušit
Autor

waiting for someone else answer

Nejlepší odpověď

Thank you Mike a lot your solution helps me a lot :)

Avatar
Zrušit
Nejlepší odpověď

Check the file addons\crm\crm_lead_view.xml. There you find the screen definition for the LEADS screen.

The field which is filled with the user logged in, is called "user_id". It looks like it is automatically filled with the content / name of the user with ID = uid (uid is a variable which is always needed in every call to a method within openERP. It is the User ID, hence uid). In order to fill it, you might have to copy uid from the call of the method/function to that field.

<update> In the file addons/base_status/base_state.py there is a method _get_default_user defined

#def _get_default_user(self, cr, uid, context=None):

""" Gives current user id

   :param context: if portal not in context returns False

"""
if context is None:
    context = {}
if not context or not context.get('portal'):
    return False
return uid

So as I said before, it is just using the given uid.

Conclusion: If you need to store the user, use uid from the input.

Avatar
Zrušit
Autor

Ok I see it. But what i really want is in addons/crm/crm_lead.py. If you look the defaults definition you'ill see " 'user_id': lambda s, cr, uid, c: s._get_default_user(cr, uid, c), it's the _get_default_user that i wanna see it's definition

Autor

yes i See it but i get the whole list of ids of all the users and i want only the current user id

Douada, you mean if you the following, you get all the users? my_field = uid

Autor

i didn't do my_field = uid. I did my_field = lambda s, cr, uid, c: s._get_default_user(cr, uid, c),, because i copied the _get_default_user function

Nejlepší odpověď

To use the currently logged in user's id as a default value you don't need the specific function in crm/crm_lead.py. You can use a simple lambda function:

_defaults = {
    'my_field': lambda s, cr, uid, c: uid,
}

If you need to do any special processing (like in crm/crm_lead.py) you can use a function:

def _get_my_field(self, cr, uid, context=None):
    if ...:
        ....
        return uid
    else:
        ...
        return False

_defaults = {
    'my_field': _get_my_field,
}

If you really need to use the base_stage mixin, then you have to import it into you module and inherit from it in your class:

from openerp.addons.base_status.base_stage import base_stage

class my_class(base_stage, osv.Model):
    ...
    ...
    _defaults = {
        'my_field': lambda s, cr, uid, c: s._get_default_user(cr, uid, c),
    }
Avatar
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
3
úno 25
26226
0
kvě 15
3759
1
bře 15
4733
4
srp 23
20608
5
zář 22
11717