修复:在没有印度区域设置的站点上,专业税/公积金报告发生崩溃("未知列 component_type")
作者: jairofloress创建于 2026年9月29日更新于 2026年9月29日
环境
- frappe:
17.0.0-dev - erpnext:
17.0.0-dev - hrms:
17.0.0-dev
重现步骤
- 使用一个没有印度区域设置的站点/公司(例如,由非印度安装程序创建的尼加拉瓜公司)。
- 使用任何有效过滤器(公司 + 期间)打开薪酬报表“专业税扣除”(/app/query-report/Professional Tax Deductions)。3. 报表崩溃,出现 500 错误。 追踪(尾部)
File "apps/hrms/hrms/payroll/report/professional_tax_deductions/professional_tax_deductions.py", line 49, in get_data
.run(pluck="name")
MySQLdb.OperationalError: (1054, "Unknown column 'component_type' in 'field list'")
**根本原因**
`professional_tax_deductions.py` 从 `Salary Component` 中查询 `component_type`:
```Python
component_type_list = (
frappe.qb.from_(SalaryComponent)
.select(SalaryComponent.name, SalaryComponent.component_type)
.where(SalaryComponent.component_type == "Professional Tax")
.run(pluck="name")
)但 component_type 不是 Salary Component 的 doctype 字段(doctype 字段是 type)。它是一个仅由印度区域设置创建的 自定义字段(hrms/regional/india/setup.py → get_custom_fields(),选项为“公积金/额外公积金/公积金贷款/专业税”)。在任何未应用该区域设置的站点上,该列不存在,并且报表不可用。
相关
hrms/payroll/report/provident_fund_deductions/provident_fund_deductions.py 具有相同的潜在问题:execute() 调用 frappe.db.exists("Salary Component", {"component_type": ["in", ...]}),这也触发了缺失的列,默默失败,而报表显示了一个误导性的“类型为公积金的薪酬组件未设置”消息,而不是“不适用”。
建议的修复(最小,对印度站点没有行为变化)
在自定义字段不存在时提前返回,例如:
def get_data(filters):
data = []
SalarySlip = DocType("Salary Slip")
SalaryDetail = DocType("Salary Detail")
SalaryComponent = DocType("Salary Component")
# `component_type` 仅由印度区域设置创建
if not frappe.get_meta("Salary Component").has_field("component_type"):
return []
component_type_list = (...)以及 provident_fund_deductions.execute() / get_data() 中的同一保护措施。
或者,通过国家/区域设置来阻止这些法定报表,从而在非印度站点上完全不暴露它们(报表是印度专用:专业税/公积金)。
如果此方法可接受,我很乐意开发一个 PR 来添加保护措施。
内容来源: frappe/hrms