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

Hello, i'm writing a module for OpenErp and i have some troubles with user's first and last names.

 

this is my piece of code:

def _user_get(self, cr, uid, context=None):
    cr.execute("select id,name from resource_resource")
    return cr.fetchall()
 .....

 

_columns = {

....

'users' : fields.selection(_user_get, 'Users')

...}

 

But it doesn't work. Can someone help me?

It saves data in the table, but does't show user name and family. The rest info is displayed.

Avatar
Zrušit
Autor

Thank you  * Bole [1]  *for your answer. I know about "'my_user':fields.many2one('res.users','User')", but the problem is that it displays too much info, such as "Language, Login and date". But i need only first and last name [1] https://www.odoo.com/forum/help-1/user/6104

o, so create a new view that shows only the fields you need .. in xml do like: that should do the trick of custom tree view fro many 2 one;) also you can define custom form view;) the same way

i have edited my answer so now you have example on how to show only the fields you want , and not all of them ;)

Nejlepší odpověď

Well.. you are looking at wrong data.. 

In odoo/openerp resource_resource contains(actualy is hr_employee name i related to this field) 
 the name for employees, not users.. 

there is a table res_users where some user data is stored... (login, password, mail.. etc..) and a relation to res_partner (partner_id) wich contains actual name of user, along with other data (address, phone , mail....)

So eather you rewrite your sql acordingly (using some joins for foreign key ids..) ,

or.. simply user orm methods like.. if you want to search for user wich has login : 'someuser' it would look like:

ids = self.pool.get('res.users').search(cr, uid, [('login'.'=','someuser')])    #expecting a list of ids returned

now that you have list of ids, you can browse those records and read/modify any data stored in fields...

 

but in your case... i think it would be much easier if you do not use fields.selection.. but instead, 

define your:

_columns = {
...
'my_user':fields.many2one('res.users','User'),
...
}
 

this is common usage for many to one field, and it preserves most orm methods in it ( addins and modifying user) 
in case you want to show just a selection on the view... define a view like: (addon after comment:)
<field name="my_user" widget="selection" /> 

If you need only a few fields shown and not the default view for related field, define them in the same view like:

<field name="my_user" widget="selection" > 
    <tree>
        <field name="first_name"/>
        <filed name="last_name"/>
    </tree>
</field>


 

Avatar
Zrušit
Nejlepší odpověď

HI. Andrew 

Here right way TODO.

_columns = {

          'user_id': fields.many2one('res.users', 'Salesperson',),

}

_defaults = {
         'user_id': lambda obj, cr, uid, context: uid,

}

I suggest you to read existing code of sale module or account module, and just go through code and understand existing codes and utilize it in your modules.

 

Avatar
Zrušit
Autor Nejlepší odpověď

Thank you. I solved this isue in the next way:

_columns = {

...

'user_id': fields.many2many('res.users'),

...

}

 

but in the xml view I inserted this string

 

<field name="user_id" string='Assigned Users' widget="many2many_tags" />

Avatar
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
2
zář 23
7498
2
bře 23
46529
2
pro 23
57435
0
bře 22
2169
3
čvn 20
10464