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

Hi,

I want the add a selection field to my model. In this selection i want the see companies. I tried something like this but didn't work.

"""

res_comp = fields.Many2one(comodel_name="res.company", string="TEST")
company = fields.Selection(related="res_comp.name", readonly=False)
"""

How Can I do something like that ?

-------------------------------------------------------------------------------------------

And I have a one question too. For example user select a company "A". I want the use this selection "A" inside of function. How can i use this. For example.

"""

res_comp = fields.Many2one(comodel_name="res.company", string="TEST")
company = fields.Selection(related="res_comp.name", readonly=False)
#I know the above 2 lines of code don't work but I suppose it does.
def test_func(self):
    print(company)

"""

But it's can't print the asd.

I need help about this two question. Thank you for time.


Avatar
Zrušit
Nejlepší odpověď

Morning Bro, 

related fields must have the same type :

so,

 company[name] is a Char fields 

and your company is a Selection field of other field 

not only that , but you may have multiple company  

so i think that you should compute the value of your selection field not to use the related option 

and in your compute function make sure to loop on your company List then: appened vals into your selection.


Avatar
Zrušit
Nejlepší odpověď

The only field that you need is the many2one from res.company, and then add that field to te view (with options="{'no_create_edit': True, 'no_open': True}")

Avatar
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
1
čvn 24
1332
0
bře 23
1679
2
dub 15
16293
2
bře 24
1652
1
pro 23
2574