当我尝试从工资中扣除无薪休假时,出现错误
ValueError('<class \'AttributeError\'>: "\'float\' object has no attribute \'number_of_days\'" while evaluating\n\'result =-(contract.wage/31) * worked_days.Unpaid.number_of_days\'')
。我是 Odoo 的新人。请帮助我。
我最近安装了 https://apps.odoo.com/apps/modules/15.0/om_hr_payroll/ 这个第三方社区版本。
我创建了薪资规则,如下快照
现在,然后我在薪资结构
中添加了薪资规则现在,当我单击员工工资单中的计算表时,我收到如下快照所示的错误
我看到了该模块提供商公司的这篇博客文章https://www.cybrosys.com/blog/hr-unpaid-leaves-payroll-management-in-odoo-10
但我的工资单仍然有错误
我的Odoo版本是最新的odoo_15.0(社区版)
Odoo 将循环遍历
Worked Days
行,使用其 worked_days_dict
将这些行添加到
code
worked_days_dict = {}
payslip = self.env['hr.payslip'].browse(payslip_id)
for worked_days_line in payslip.worked_days_line_ids:
worked_days_dict[worked_days_line.code] = worked_days_line
要使用以下表达式,您需要添加带有
Unpaid
代码的工作日行:
result = (contract.wage/30) * worked_days.Unpaid.number_of_days
请注意,字段名称是:
number_of_days
如果您使用此https://apps.odoo.com/apps/modules/15.0/om_hr_payroll/工资模块,那么有许多对象变量可用于使用Python代码部分自定义工资规则。请参阅下面我共享的可用变量列表
# Available variables:
#----------------------
# payslip: object containing the payslips
# employee: hr.employee object
# contract: hr.contract object
# rules: object containing the rules code (previously computed)
# categories: object containing the computed salary rule categories (sum of amount of all rules belonging to that category).
# worked_days: object containing the computed worked days.
# inputs: object containing the computed inputs.
# Note: returned value have to be set in the variable 'result'
wagePerDay =contract.wage // 从合约中获取工资
totalWorkingDays =working_days.WORK100.number_of_days // 获取总工作日(不包括公众假期,星期日也...如果您设置星期六休息,则星期六也休息)
date2 = payslip.date_to // 用于获取选定的工资单 date_to
date1 = payslip.date_from // 用于获取选定的工资单 date_from
Leaves = 0
for line in payslip.worked_days_line_ids:
Leaves += line.number_of_days // get number of leave (category wise like, total unpaid leave, total of paid leaves, total of sick leaves, total of Global Leaves)
下面我分享我关于从工资中扣除无薪休假的最终答案
这是Python条件字段输入
unpaidLeaves = 0
for line in payslip.worked_days_line_ids:
if line.name == "Unpaid" and line.code == "UNPAID" :
result = line.number_of_days
这是Python代码字段输入
# Available variables:
#----------------------
# payslip: object containing the payslips
# employee: hr.employee object
# contract: hr.contract object
# rules: object containing the rules code (previously computed)
# categories: object containing the computed salary rule categories (sum of amount of all rules belonging to that category).
# worked_days: object containing the computed worked days.
# inputs: object containing the computed inputs.
# Note: returned value have to be set in the variable 'result'
# ---------------------
# totalWorkingDays = worked_days.WORK100.number_of_days
# date2 = payslip.date_to
# date1 = payslip.date_from
# sec_Of_1Day = 86400
# wagePerHour = contract.wage / 30 / employee.resource_calendar_id.hours_per_day
wagePerDay = contract.wage / 30
unpaidLeaves = 0
if worked_days.Unpaid and worked_days.Unpaid.number_of_days or False:
result= wagePerDay * unpaidLeaves
else:
for line in payslip.worked_days_line_ids:
if line.name == "Unpaid" and line.code == "UNPAID" :
unpaidLeaves = line.number_of_days
result_qty = round(unpaidLeaves, 2)
result = round(wagePerDay, 2)
# result = wagePerDay
# result = wagePerDay * unpaidLeaves
请参阅下面的输出快照
您可以在下面看到我的回答的快照
除了建议的答案之外, 人们可以用Python计算无薪休假金额,如下公式:
wagePerDay = contract.wage / worked_days.WORK100.number_of_days
totalUnpaidWage = wagePerDay*worked_days.LEAVE90.number_of_days;
result = round(totalUnpaidWage, 2)
地点: worked_days.WORK100.number_of_days 是 odoo 记录的当月工作总天数。
worked_days.LEAVE90.number_of_days 是无薪休假天数。 代码LEAVE90可以在无薪工作条目类型选项卡下配置,该选项卡可以在编辑薪资结构时找到。
查找随附的 Odoo 示例图像
请问,我如何计算该期间的天数,因为有些月份有30天,有些月份有31天和2月28/29天,以免放置/30规则,考虑到付款期间的日期