Odoo报表自定义用户案例:制造业生产报表优化
用户背景
申通制造公司是一家J工中小型机械设备制造商,使用Odoo管理生产流程。他们遇到以下问题:
- 现有生产订单报表缺少关键生产指标
- 无法直观查看物料消耗与计划的对比
- 需要添加质检结果到生产报表中
- 报表格式不符合公司文档标准
业务需求
在生产订单报表中添加实际工时与计划工时对比
显示物料消耗与BOM计划的差异百分比
集成质检结果摘要
按照公司标准添加页眉页脚和LOGO
解决方案实施
1. 创建自定义模块
开发了mrp_custom_reports模块,继承标准MRP功能
2. 报表模板修改
xml
<!-- 添加工时对比部分 -->
<div class="row mt-2">
<div class="col-4">
<strong>计划工时:</strong>
<span t-field="production.planned_hours"/>
</div>
<div class="col-4">
<strong>实际工时:</strong>
<span t-field="production.total_hours"/>
</div>
<div class="col-4" t-att-style="'color: ' + (production.total_hours > production.planned_hours*1.1 ? 'red' : 'green')">
<strong>差异:</strong>
<span t-esc="(production.total_hours/production.planned_hours-1)*100 if production.planned_hours else 0"/>%
</div>
</div>
<!-- 添加物料消耗对比表 -->
<table class="table table-sm mt-3">
<thead>
<tr>
<th>物料</th>
<th>计划数量</th>
<th>实际消耗</th>
<th>差异</th>
</tr>
</thead>
<tbody>
<t t-foreach="production.move_raw_ids" t-as="move">
<tr>
<td><span t-field="move.product_id.display_name"/></td>
<td><span t-field="move.product_uom_qty"/></td>
<td><span t-field="move.quantity_done"/></td>
<td t-att-style="'color: ' + (move.quantity_done > move.product_uom_qty*1.05 ? 'red' : 'green')">
<span t-esc="(move.quantity_done/move.product_uom_qty-1)*100 if move.product_uom_qty else 0"/>%
</td>
</tr>
</t>
</tbody>
</table>
3. 添加质检结果
python
# 在模型中添加计算字段
def _compute_quality_check_results(self):
for production in self:
checks = self.env['quality.check'].search([('production_id', '=', production.id)])
production.quality_pass = len(checks.filtered(lambda x: x.quality_state == 'pass'))
production.quality_fail = len(checks.filtered(lambda x: x.quality_state == 'fail'))
quality_pass = fields.Integer(compute='_compute_quality_check_results')
quality_fail = fields.Integer(compute='_compute_quality_check_results')
实施效果
生产报表现在显示关键KPI对比,帮助快速识别异常
物料消耗差异可视化,减少浪费
质检结果集成使报表更全面
符合公司文档标准的格式提高了专业度
用户反馈
"自定义报表后,我们的生产会议效率提高了40%,能够快速定位问题工序。物料消耗差异可视化帮助我们发现了3个主要的浪费点,每年可节约约人民币75,000。" — 生产总监