如何在树形视图中对检查的记录进行计数和求和,然后在表单字段中设置此结果。 Odoo 8

时间:2019-02-19 18:47:08

标签: odoo odoo-8

我需要对树视图中的检查记录进行计数和求和。

我有树视图: Mi tree view

我的代码是:

class summary_bidding_group(models.Model):
    _name = 'summary.bidding.group'
    _description = 'Summary Bidding Group'

    check_contract = fields.Boolean("Check Contract", store = 
    True)
    bidding_amount = fields.Float("plan.bidding", related = 
    'bidding_id.amount', store = True)

class plan_group(models.Model):
    _inherit = 'plan.group'
    summary_bidding_group_id = 
    fields.One2many('summary.bidding.group','group_id',store = True)

    award_bidding = fields.Integer('award bidding', store = True) 
    total_bidding = fields.Float('total bidding', store = True) 

1 个答案:

答案 0 :(得分:0)

不仅要寻求解决方案,还应提供您到目前为止所做的事情以及您遇到的困难。

award_bidding = fields.Integer('award bidding', store = True, compute='_compute_total_biddings') 
total_bidding = fields.Float('total bidding', store = True, compute='_compute_total_biddings')

@api.depends('summary_bidding_group_id')
@api.multi
def _compute_total_biddings(self):
  for record in self:
    selected_bid_lines = record.summary_bidding_group_id.filtered(lambda l: l.check_contract)
    record.update({
      'award_bidding': len(selected_bid_lines),
      'total_bidding': sum(selected_bid_lines.mapped(bidding_amount))
    })