[英]Odoo: domain not working with a related field
我有一个模型“custom.products”,它通过 one2many 字段“branch_line”连接到模型“custom.branch.line”,我想在相关字段“branch1”和“branch2”上应用域过滤器,我想要它显示每个分支中每个产品的数量,但是当我将域应用于相关字段时它不起作用,它只是检索数据库表中的第一个条目,我的代码如下
class CustomProduct(models.Model):
_name = 'custom.product'
_description = 'Product Record'
branch_line = fields.One2many('custom.branch.line', 'product_id', string='Branch Lines', )
branch1 = fields.Integer(string="branch 1", related="branch_line.qty", domain="[('branch_line.branch_id','=', 3)]", )
branch2 = fields.Integer(string="branch 2", related="branch_line.qty", domain="[('branch_line.branch_id','=', 4)]", )
class CustomBranchLine(models.Model):
_name = 'custom.branch.line'
_description = 'Branch Line Record'
branch_id = fields.Many2one('custom.branch', string='Branch')
product_id = fields.Many2one('custom.product', string='Product')
qty = fields.Integer(string="QTY", required=False, )
您应该使用计算字段来获取 branch1 和 branch2 字段的正确值:
branch1 = fields.Integer(string="branch 1",compute="_get_branch")
branch2 = fields.Integer(string="branch 2",compute="_get_branch")
@api.multi
def _get_branch(self):
for line in self:
line.branch1 = self.env['custom.branch.line'].search([('branch_id','=',3)],limit=1).qty
line.branch2 = self.env['custom.branch.line'].search([('branch_id','=',4)],limit=1).qty
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.