Я хочу передать значение поля many2one в поле one2many, чтобы отфильтровать результаты последнего, я пытаюсь использовать контекст, но я не знаю, правильно ли я его использую
Идея состоит в том, что я хочу фильтровать продукты (часть поля one2many) по выбранной ветви (поле many2one)
мой код такой, как показано ниже
class CustomTransRequest(models.Model):
_name = 'custom.trans.request'
branch_from_id = fields.Many2one('custom.branch', string="From", required=True)
branch_to_id = fields.Many2one('custom.branch', string="To", required=True)
product_ids = fields.One2many(comodel_name="custom.trans.line", inverse_name="request_id", string="Products", required=False, )
class CustomTransLine(models.Model):
_name = 'custom.trans.line'
request_id = fields.Many2one("custom.trans.request", string="Request ID", required=True, )
product_id = fields.Many2one("custom.product", string="Product", required=True)
qty = fields.Integer(string="Qty", required=True)
class CustomProduct(models.Model):
_name = 'custom.product'
product_name = fields.Char(string="Name", required=False, )
branch_line = fields.One2many('custom.branch.line', 'product_id', string='Branch', )
class CustomBranchLine(models.Model):
_name = 'custom.branch.line'
branch_id = fields.Many2one('custom.branch', string='Branch', ondelete='cascade')
product_id = fields.Many2one('custom.product', string='Product', required=True, )
qty = fields.Integer(string="QTY", required=True, )
<record id="form_custom_trans_request" model="ir.ui.view">
<field name="name">custom.trans.request.form</field>
<field name="model">custom.trans.request</field>
<field name="arch" type="xml">
<form string="Transfer Request">
<sheet>
<group>
<field name="branch_from_id"/>
<field name="branch_to_id"/>
</group>
<notebook>
<page string="Products" name="order_lines">
<field name="product_ids" context="{'default_branch_id':branch_from_id}" mode="tree">
<tree editable="bottom">
<control>
<create string="Open list view"/>
</control>
<field name="product_id" domain="[('branch_line.branch_id','=',default_branch_id)]" />
<field name="qty"/>
</tree>
</field>
</page>
</notebook>
</sheet>
</form>
</field>
</record>