[英]how to set domain with python in odoo
Is it possible to set domain on the python side without putting it in view?是否可以在不查看域的情况下在 python 端设置域? I tried to set the domain in the customer field (sale order) based on branch in the Customer menu/template
我尝试根据客户菜单/模板中的分支在客户字段(销售订单)中设置域
I have tried this but why it doesn't work?我试过这个但为什么它不起作用?
@api.onchange('partner_id')
def _onchange_cust_domain(self):
for rec in self:
if self.branch_id.id:
cust_list = rec.partner_id.branch_id.id
return {'domain' : {'partner_id' : [('branch_id', '=', cust_list)]}}
I think your problem is that you are making a domain for a field partner_id, but in the onchange method of the same field.我认为您的问题是您正在为字段 partner_id 创建一个域,但是在同一字段的 onchange 方法中。 It makes no sense to me.
对我来说完全是无稽之谈。 So if you put a Customer with branch X, then you can only search customers of branch X for that sale_order (if that domain do the job).
因此,如果您将 Customer 与分支机构 X 放在一起,那么您只能为该 sale_order 搜索分支机构 X 的客户(如果该域执行此工作)。 I dont know what are you trying to do exactly, but i think than changing a domain in the same field you are changing the value it is no possible.
我不知道你到底想做什么,但我认为比起在同一领域改变一个域,你改变的是价值,这是不可能的。
Your code would be correct if that domain applies to another field.如果该域适用于另一个字段,您的代码将是正确的。
This is a working exaple.这是一个有效的例子。 Notice that onchange field method and field to apply domain are diferent:
请注意,onchange 字段方法和应用域的字段是不同的:
@api.onchange('operating_unit_id')
def _applicants_onchange(self):
if self.operating_unit_id:
return {'domain': {'applicant_id': [('default_operating_unit_id', '=', self.operating_unit_id.id)]}}
return {}
To set the partner_id
domain when the branch_id
field value changes, use the following onchange
function:要在
branch_id
字段值更改时设置partner_id
域,请使用以下onchange
函数:
Example:例子:
@api.onchange('branch_id')
def onchange_branch_id(self):
if self.branch_id:
return {'domain': {'partner_id': [('branch_id', '=', self.branch_id.id)]}}
Odoo sets by default the following domain from the python code: Odoo 默认设置来自 python 代码的以下域:
['|', ('company_id', '=', False), ('company_id', '=', company_id)]
Returning a domain using onchange method
has been deprecated in Odoo 14.使用
onchange method
返回域已在 Odoo 14 中弃用。
I'm using this OCA module to filter field depend on another field.我正在使用这个 OCA 模块来过滤依赖于另一个字段的字段。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.