odoo - 如何在树视图中对检查记录进行计数和求和,然后在表单字段中设置此结果。奥多 8
问题描述
我需要从树形视图中计算和汇总检查记录。
我的代码是:
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)
解决方案
不要只是寻求解决方案,尝试提供到目前为止您所做的事情以及您遇到的问题。
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))
})
推荐阅读
- sql - 将 Millis 公式化为 HHH:MM:SS
- python - 在 TensorFlow 中传递和使用稀疏矩阵
- javascript - 有没有办法设置网格行/列开始,如:[行名] + 2?
- c# - 关于 DateTime.Now.AddDays(-5).ToString("dd-MMM-yyyy")
- jquery - TypeError:不能使用“in”运算符在“created_at”中搜索“length”
- testing - 使用柏树重定向
- eclipse - 在 Windows 8.1 上的 Eclipse Oxygen 4.7 中安装 Google Cloud Tools Plugin 1.6.1 时出错
- android - 使用 Gradle 插件 3.1.2 改造 2.4.0
- xamarin - 如何在 xamarin 中将 .aar 文件转换为 .dll 时修复警告,因为它没有生成所有必需的类/接口
- python - 熊猫,合并 2 个数据框