[英]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.