3
votes

I need to use many2one product_id field in my one2many field product_lines and products should be filtered based on page_no.

Model1 contains product_lines(o2m : model2-model1_id) and page_no

class model1(models.Model):
    _name = "model1"

    ....
    page_no = fields.Integer('Page No.')
    ...
    product_lines = fields.One2many('model2', 'model1_id', 'Product lines')

model2 contains product_id and model1_id(m2o : model1)

class model2(models.Model):
    _name = "model2"

    model1_id = fields.Many2one('model1')
    product_id = fields.Many2one('product.product')

in my xml for form view of model1 is

    <field name="product_lines"  >
        <tree editable="bottom" name="petan_nos">
            <field name="model1_id" invisible="1" />
            <field name="product_id" domain="[('page_no', '=', model1_id.page_no)]" />
        </tree>
    </field>

And this is how I ma getting error front end error Uncaught Error: AttributeError: object has no attribute 'page_no' no error stack on terminal.

How to handle this and use field of relational fields in domain so I can use name_search and modify the behaviour?

Thanks in advance.

1
what you want please explain in details?Er CEO Vora Mayur
means that when open page so automatic by-default search selected?Er CEO Vora Mayur
While creating product_lines, in the product field I want only those products with the same page_no which I have added in model1 form.....Bhuro
Paste python code also.KbiR
@KbiR I edited my question and added python code...Bhuro

1 Answers

1
votes

Inherit product.product and add field page_no.

_inherit='product.product'

page_no = fields.Char('Page_no')

And also define page_no in model2

class model2(models.Model):
_name = "model2"

model1_id = fields.Many2one('model1')
product_id = fields.Many2one('product.product')
page_no = fields.Char('Page_no')

In xml

<field name="product_lines"  >
    <tree editable="bottom" name="petan_nos">
        <field name="page_no" />
        <field name="model1_id" invisible="1" />
        <field name="product_id" domain="[('page_no', '=', page_no)]" />
    </tree>
</field>

Hope it will help you.