我有3个对象:
class PurchaseRequest(models.Model):
_name = 'purchase.request'
purchase_request_line = fields.One2many('purchase.request.line', 'purchase_request_id', copy=True)
supply_conditions_status = fields.One2many('supply.conditions', 'purchase_id', string='Order',copy=True)
和
class SupplyConditions(models.Model):
_name = 'supply.conditions'
name = fields.Many2one('purchase.request.line', string='Product')
和
class PurchaseRequestLine(models.Model):
_name = 'purchase.request.line
purchase_request_id = fields.Many2one('purchase.request', 'Purchase request')
使用域我想只过滤这些名称字段(many2one字段)值,这些值是在purchase.request表单purchase_request_line字段中编写和保存的。因为现在我可以看到保存在数据库中的所有值......
<openerp>
<data>
<record model="ir.ui.view" id="view_purchase_request_doc">
<field name="name">purchase.request.doc</field>
<field name="model">purchase.request</field>
<field name="arch" type="xml">
<form string="Purchase Request">
<field name="state" widget="statusbar" statusbar_visible="draft,to_approve_first,approved,rejected,canceled" statusbar_colors="{"approved":"green"}"/>
</header>
<sheet>
<field name="purchase_request_line" attrs="{'readonly': [('state','not in', ('draft'))]}">
<tree string="Purchase Order Lines" editable="bottom">
<field name="name"/>
<field name="quantity"/>
</tree>
</field>
<notebook>
<page string="Conditions" attrs="{'invisible': [('state','in', ('draft', 'to_approve_first'))]}">
<field name="supply_conditions_status">
<tree string="Purchase Order Lines">
<field name="name" domain="[('???', '???', '???')]"/>
<field name="name" options="{'no_create': True}" domain="[('name', '=', 'product_id')]"/>
我会尝试在这里形象化:
我想在购买条件产品名称many2one字段中进行过滤,只能看到2项:item1和item2。
答案 0 :(得分:0)
我有点理解。 你能发布所有3个型号的代码吗? 或者再解释一下。
但我对你有一点概念。
所以......你需要在* .py方面创建函数。
实施例
class PurchaseRequestLine(models.Model):
_name = 'purchase.request.line
purchase_request_id = fields.Many2one('purchase.request', 'Purchase request', domain=_getfilter)
@api.model
def _getfilter(self):
return [('purchase_request_id', '=', self.env['purchase.request'].search([('name','=',???)]).name)]
或另一个,因为我了解你。如果您需要在输入Many2one字段时返回所需的结果。
实施例。
@api.model
def name_search(self, name, args=None, operator='ilike', limit=100):
args = args or []
recs = self.browse()
if name:
recs = self.search(['|', ('purchase_request_id', 'ilike', name), ('name', 'ilike', name), ] + args, limit=limit)
if not recs:
recs = self.search(['|', ('purchase_request_id', operator, name), ('name', operator, name), ] + args, limit=limit)
return recs.name_get()