效果图
模型之间的关系以及逻辑
这里是有两个模型:bom.configure 和 sale.mrp.bom
bom.configure的form视图里面需要显示链接区域指向sale.mrp.bom的tree视图
bom.configure模型的xml: form视图
<sheet>
<div class="oe_button_box" name="button_box">
<button name="action_sale_mrp_bom" class="oe_stat_button" icon="fa-book" type="object">
<field name="sale_mrp_bom_count" widget="statinfo" string="订单Bom"/>
</button>
</div>
...
</sheet>
- name=“action_sale_mrp_bom”: 指的是一个按钮
- icon=“fa-book”: 小图标(图标网, 想使用哪个小图标点进去复制就行了)
- name=“sale_mrp_bom_count”: 指的是一个字段
- widget=“statinfo”: 小部件
小部件类型可参照该文章
bom.configure模型的py文件
_name = 'bom.configure'
sale_mrp_bom_count = fields.Integer('订单Bom', compute='_compute_sale_mrp_bom_count')
def _compute_sale_mrp_bom_count(self):
for item in self:
item.sale_mrp_bom_count = self.env['sale.mrp.bom'].search_count([('sale_id', '=', item.sale_line_id.order_id.id), ('product_tmpl_id', '=', item.product_name.product_tmpl_id.id)])
def action_sale_mrp_bom(self):
self.ensure_one()
action = self.env.ref('dd_sale_bom.dd_sale_mrp_bom_action').read()[0]
action['domain'] = [('sale_id', '=', self.sale_line_id.order_id.id), ('product_tmpl_id', '=', self.product_name.product_tmpl_id.id)]
return action
实现:
- 字段定义成计算字段: 计算出该链接的数目
- 按钮: 返回符合条件的tree视图