Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
1 Odpowiedz
3908 Widoki

Hello guys,

I'm working on this project and I'm stuck on this for a while now. I've created a tree view and I'm trying to populate the view with all the values through compute fields (every field in this view is compute). But I'm only getting the last record of all the records. I looked deeply into my code and found that there is no problem with my logic. If you could please guide me through it would be a great help. My code is as follows :

product.template.py

    product_location = fields.Char("Location", compute='get_location')

    location_role = fields.Char("Role", compute="get_location_role")

    product_pick_type = fields.Char("Pick Type", compute='get_product_pick_type')


    def get_location(self):

        quant = http.request.env['stock.quant'].get_quant_by_product(self.id)

        for res in quant:

            self.product_location = res.location_id.name

    def get_location_role(self):

                quant = self.env['stock.quant'].get_quant_by_product(self.id)

                for res in quant:

                    self.location_role = res.location_id.location_role_id.role

     def get_product_pick_type(self):

                quant = self.env['stock.quant'].get_quant_by_product(self.id)

                for res in quant:

                    self.product_pick_type = res.location_id.pick_type


xml file:


<page string="Location">

    <field name="product_variant_ids">

        <tree>

            <field name="product_location" />

            <field name="location_role"/>

            <field name="product_pick_type"/>  

        </tree>

    </field>

</page>


Thanks in advance.

Awatar
Odrzuć
Autor Najlepsza odpowiedź

Hey guys,

Eventually I solved my own problem. If you're in the same situation and looking for an answer, then you need to use One2many field instead of char.

Thanks

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
1
wrz 15
10505
1
paź 19
2682
3
maj 16
5528
1
wrz 15
3739
3
kwi 25
4659