当期应收数据穿透

This commit is contained in:
李鹏宇
2026-02-24 11:24:48 +08:00
parent 33e8d88c62
commit f42e08cd2d
2 changed files with 59 additions and 4 deletions
@@ -77,7 +77,11 @@ class CurrentReceivableRentReport(models.Model):
"序号": idx,
"应收开始": rec.due_date.strftime("%Y-%m-%d") if rec.due_date else "",
"应收结束": rec.due_date_end.strftime("%Y-%m-%d") if rec.due_date_end else "",
"承租方名称": rec.lessee_id.name if rec.lessee_id else "",
"承租方名称": {
'model': 'property.tenant.information',
'id': rec.lessee_id.id,
'display_name': rec.lessee_id.name,
} if rec.lessee_id else "",
"原始金额": round(amt, 2),
"减免金额": round(discount, 2) if discount else "",
"实际金额(含税)": round(actual_amt, 2),
@@ -85,8 +89,16 @@ class CurrentReceivableRentReport(models.Model):
"实际金额(不含税)": round(actual_amt_nt, 2),
"物业名称": rec.property_name or "",
"产权证": rec.title_deed or "",
"合同编号": rec.contract_id.contract_code if rec.contract_id else "",
"管理员": rec.admin_id.name if rec.admin_id else "",
"合同编号": {
'model': 'property.lease.contract',
'id': rec.contract_id.id,
'display_name': rec.contract_id.contract_code,
} if rec.contract_id else "",
"管理员": {
'model': 'res.users',
'id': rec.admin_id.id,
'display_name': rec.admin_id.name,
} if rec.admin_id else "",
"acc_type": rec.acc_type if rec.acc_type else False,
})
@@ -20,6 +20,7 @@ class ReceivableReport extends Component {
console.log(this.props.action.context.report_config)
this.serviceOrm = useService("orm")
this.actionService = useService("action"); // 获取 actionService 用于跳转
// 计算 本月的开始,结束
@@ -47,10 +48,16 @@ class ReceivableReport extends Component {
// 加载 ag-grid
//await loadJS("https://cdn.jsdelivr.net/npm/ag-grid-community/dist/ag-grid-community.min.js");
// 统一处理 columns:给所有列添加穿透渲染器
const columns = this.config.columns || [];
columns.forEach((col) => {
col.cellRenderer = this.linkRender.bind(this);
});
this.gridOptions = {
localeText: AG_GRID_LOCALE_CN,
theme: agGrid.themeMaterial,
columnDefs: this.config.columns || [],
columnDefs: columns,
rowData: [],
rowClassRules: {
'ag-row-new-rent': function(params) {
@@ -102,6 +109,9 @@ class ReceivableReport extends Component {
const items = params.defaultItems.slice();
items.push("chartRange");
return items;
},
context: {
actionService: this.actionService // 传递 actionService 用于穿透跳转
}
};
@@ -110,6 +120,39 @@ class ReceivableReport extends Component {
});
}
/**
* 穿透渲染器:将对象格式的字段渲染为可点击的链接
* 如果字段值是对象(包含 model、id、display_name),则渲染为可点击链接
* 否则直接显示原值
*/
linkRender(params) {
if (!params.value) return '';
// 如果是对象格式(包含 model 和 id),渲染为可点击链接
if (typeof params.value === 'object' && params.value.model && params.value.id) {
const { model, id, display_name } = params.value;
const el = document.createElement('div');
el.className = 'o_record_cell';
el.innerText = display_name || '';
el.classList.add('btn');
el.classList.add('btn-link');
el.onclick = () => {
params.context.actionService.doAction({
type: 'ir.actions.act_window',
res_model: model,
res_id: id,
views: [[false, 'form']]
});
};
return el;
}
// 否则直接返回原值(纯文本/数字)
return params.value;
}
/**
* 改变布尔值
* @param e