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

hi all,

I am creating a model which will select name from contacts (res.partner), had a field type Many2one which point to 'res.partner' but when created a view on it, it is showing a grid (tree view) for that.

1) how i can restrict it to behave like other Many2one fields ( just open a combo list )

2) name field copy the name field from res.partner and store 

2) how i can add demain filter for its category_id (Tags) to select from only a particular category_id (Tag) list


please help.

regards


py file:
class Stores(models.Model):
    _name = 'tests.stores'
    _rec_name = 'name'
    _description = "Stores"

    store_id = fields.Many2many('res.partner', string="Select Store", domain="[('category_id','ilike','stores')]")  -- Note: i knew category_id is not Char but how I can add filter
    name = fields.Char(related="res.partner.name", string="Store Name", store=True, invisible="1")


View xml:
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
    <record model="ir.ui.view" id="stores_form_view">
        <field name="name">stores.form</field>
        <field name="model">test.stores</field>
        <field name="arch" type="xml">
            <form string="Stores Setup">
                <sheet>
                    <group>
                        <field name="store_id"/>
                        <field name="name"/>
                        <field name="description"/>
                    </group>
                </sheet>
            </form>
        </field>
    </record>

    <record model="ir.ui.view" id="stores_tree_view">
        <field name="name">stores.tree</field>
        <field name="model">tests.stores</field>
        <field name="arch" type="xml">
            <tree string="Stores Tree">
                <field name="store_id"/>
                <field name="name"/>
                <field name="description"/>
            </tree>
        </field>
    </record>
</odoo>
Awatar
Odrzuć

Can you attach a screenshot of your current UI

Najlepsza odpowiedź

Hi,

Seems you have added many2many field not Many2one field, if you need to get this as like the selection field or many2one field, you can use the widget many2many_tags.

Sample:

<field name="country_ids" widget="many2many_tags"/>

For Reference: Understanding Many2many Field In Odoo


Thanks

Awatar
Odrzuć
Autor

@Niyas Raphy, thanks a bunch, its my mistake, i added as Many2many instead of Many2one which is my requirement.

what about domain filter, please help as category_id is not Char and I have to restrict the list to populate only related records for selection.

regards

Autor Najlepsza odpowiedź

@Odoophile here is screenshot


Awatar
Odrzuć

Hope its working now

Powiązane posty Odpowiedzi Widoki Czynność
2
kwi 23
2867
2
lut 25
40631
2
lis 22
2908
1
lut 22
7934
2
gru 21
4197