İçereği Atla
Menü
Bu soru işaretlendi
4 Cevaplar
9401 Görünümler

Hello to all , I have 3 fields which in my module page.2 are for product categories and 1 for product. The categories fields consist of different categories. Now I want to add filter so that what ever category I set in the field, only those product should list in the products field . It is a type of sorting or filtering. I dont have much idea of using filter in such a scenerio under form view. Here is my code.py:

class deg_form(osv.osv):
    _name = "deg.form"
    _columns = {
         'categ1':fields.many2one('product.category','Parent Category'),
         'categ2':fields.many2one('product.category','Child Category'),
         'my_products':fields.many2one('product.product','Products',size=64),

            }


deg_form()

and here is its xml:

<record id="mywin_form_view" model="ir.ui.view">
            <field name="name">mywin.form</field>
            <field name="model">deg.form</field>          
            <field eval="7" name="priority"/>
            <field name="arch" type="xml">
                <form string="FORM DATA" version="7.0">

                     <h1>
                       <label for="categ1" string="Parent category"/>
                           <field name="categ1" />
                     </h1>

                     <h1>
                       <label for="categ2" string="Child category"/>
                           <field name="categ2" />
                     </h1>
<newline/>

                     <h1> 
                       <label for="my_products" string="Products" domain = "[('categ1','=',True)]"/> 
                           <field name="my_products"/> 
                     </h1>


                 <button name="show_product" string="SHOW PRODUCT" type="action"/>
                 </form>
             </field>
    </record>

please help me fix this

Avatar
Vazgeç
En İyi Yanıt

Hello

You can put filter in dynamic fashion

example:

.py file format:

class my_class(): columns={'categ_id1':fields.many2one('product.category',Category),'product_id':fields.many2one('product.product',Products)}

def my_onchange_func(self,cr,uid,ids,categ_id,context):

if categ_id:

    pro_tmp_obj=self.pool.get('product.template')

    prod_obj=self.pool.get('product.product')

    prod_categ_ids=pro_tmp_obj.search(cr,uid,['categ_id','=',categ_id])
    pro_ids=prod_obj.search(cr,uid,['product_tmpl_id','in',[prod_categ_ids])



    return {'domain':{'product_id':[('id','in',pro_ids)]}}

my_class()

################
XML file format:

<field name="categ_id1" on_change="my_onchange_func"/>

<field name="product_id"/>

Avatar
Vazgeç
En İyi Yanıt

Try this: This shows the products that have category set from categ1 and categ2 field

<h1> 
      <label for="my_products" string="Products" /> 
      <field name="my_products" domain = "[('categ_id','in',[categ1, categ2])]"/> 
</h1>

For a button to call a function in PY FILE, we use type="object"

<button name="show_product" string="SHOW PRODUCT" type="object"/>
Avatar
Vazgeç
En İyi Yanıt

Try this

'my_products':fields.many2one('product.product','Products',size=64, domain="[('categ_id', '=', categ1)]")

Coz the many2one field for product_category in product_template is categ_id and product_product is based on product_template.

Avatar
Vazgeç
En İyi Yanıt

Hi,

Try this code:

'my_products':fields.many2one('product.product','Products',size=64, domain="[('categ1', '=', categ1)]")

Avatar
Vazgeç
Üretici

thanks for replying but it didnot work .

What issue you facing ?

Üretici

raise ValueError("Invalid field %r in leaf %r" % (left, str(leaf))) ValueError: Invalid field 'categ1' in leaf "<osv.ExtendedLeaf: ('categ1', '=', 'categ1') on product_product (ctx: )>" Ok

I have update code pls check it. and try it

Üretici

now I am having this error : ValueError: Invalid field 'categ1' in leaf "<osv.ExtendedLeaf: ('categ1', '=', 12) on product_product (ctx: )>"

HI try this 'my_products':fields.many2one('product.product','Products',size=64, domain="[('categ_id', '=', categ1)]")

Üretici

thanks a lot ,this worked. do you have any idea to set a route in openerp so that when we login , the first page we see is our module. ?

Change the sequence of your module main menu same as "Messaging"

Üretici

didnot get you. Can you explain plz

You need chnage sequnse of your customer module menu.

Üretici

yes thanks again . as you saw I have two categ fields . 1 is parent and other is child . But I want to do like when I set a categ in 1st field, then the 2nd field should just show the child of that parent , not all . Do I have to write function for this , to search for the child of that parent?

did not get you

Üretici

means like when I set a category in first field . and then when I try to search any category in the other field , then it should show only the child categories of that parent category which I set in the 1st field

set domain for that.

Üretici

but I can't filter through parent categories. look if I give values in all 3 categories then its ok . but if I try to give only parent_id , then it doesnot show anything although it should show everything in that parent_id

İlgili Gönderiler Cevaplar Görünümler Aktivite
0
Mar 25
1364
4
Nis 24
174245
0
Ara 23
2154
5
Tem 25
227972
1
Ara 22
3267