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
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Comptabilité
- Inventaire
- PoS
- Project
- MRP
Cette question a été signalée
Thank you Mike a lot your solution helps me a lot :)
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.
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
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
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
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),
}
Vous appréciez la discussion ? Ne vous contentez pas de lire, rejoignez-nous !
Créez un compte dès aujourd'hui pour profiter de fonctionnalités exclusives et échanger avec notre formidable communauté !
S'inscrirePublications associées | Réponses | Vues | Activité | |
---|---|---|---|---|
|
3
févr. 25
|
26228 | ||
|
0
mai 15
|
3764 | ||
|
1
mars 15
|
4736 | ||
CRM in offline mode?
Résolu
|
|
4
août 23
|
20614 | |
|
5
sept. 22
|
11719 |
waiting for someone else answer