企业里最容易被低估的工资流程,是“工资单发出去以后谁还能取回、谁能看、离职后链接会不会失效”。Odoo 企业版用 documents_hr_payroll 把 Payroll 与 Documents 绑在一起,让工资单不只是一个邮件附件,而是进入员工文档空间的长期对象。
## 1. 工资单先变成 document,再谈邮件或重发
在 enterprise/documents_hr_payroll/models/hr_payslip.py,hr.payslip 继承了 documents.mixin,并计算 document_access_url。这说明工资单真正对外暴露的不是某次发送邮件时附带的 PDF,而是 Documents 里的一个有访问策略的文档对象。
2. 文件夹与访问权限按员工身份动态路由
同模块里的 _get_document_folder()、_get_document_partner() 与公司级 _get_or_create_worker_payroll_folder() 决定了:有系统用户的员工走个人文档空间,没有用户的员工走集中 payroll folder;同时 payroll 用户组会被加到相应 folder 的编辑权限里。这里传递的是 ownership、folder 与 partner access,不只是文件路径。
3. 声明行与 PDF 发布动作继续复用 Documents 主链
在 enterprise/documents_hr_payroll/models/hr_payroll_employee_declaration.py,action_post_in_documents() 会把声明行生成的 PDF 发布成 documents.document,并把 res_model=hr.payslip、owner、folder、partner access 一起写进去。也因此后续“重新发送工资单”并不是重新渲染所有文档,而是复用已有 document 及其 access URL。
4. 长期可访问性是这条链最像企业系统的地方
源码明确写着 payslip document 应当支持“Anyone with the link”,目的是员工被归档或离职后仍能取回历史工资单。这是一种很典型的跨模块边界:Payroll 负责合法生成,Documents 负责持久存储与访问策略,邮件只负责通知。
## 结论
所以,Odoo 企业版工资单并不是“算完生成 PDF 发一次”就结束,而是 Payroll 先把文件交给 Documents 建档,再由 Documents 管 folder、owner、访问链接和长期留痕。
主要源码锚点:
- `enterprise/documents_hr_payroll/models/hr_payslip.py`
enterprise/documents_hr_payroll/models/hr_payroll_employee_declaration.pyenterprise/documents_hr_payroll/models/res_company.pyenterprise/documents_hr_payroll/models/hr_employee.py
DISCUSSION
评论区