float 对象没有属性“工资模块中的 number_of_day 错误”在奥杜 15

发布于 2025-01-11 15:07:41 字数 1261 浏览 0 评论 0 原文

我在评估时遇到错误 ValueError(': "\'float\' object has no attribute \'number_of_days\'" result =-(contract.wage/ 31) *working_days.Unpaid.number_of_days\'') 当我试图从工资单中扣除无薪休假时。我是 Odoo 的新人。请帮我。

我最近安装了 https://apps.odoo.com/apps/modules/15.0/ om_hr_payroll/ 这个第三方社区版本。

我创建了薪资规则,如下快照

salaryrule

现在,然后我在薪资结构中添加了该薪资规则

在此处输入图像描述

现在,当我单击员工工资单中的计算表时,出现如下错误

在此处输入图像描述

我看到了该模块提供商公司的这篇博客文章https://www.cybrosys.com/blog/hr-unpaid-leaves-payroll-management-in-odoo-10

但我的工资单仍然有错误

我的 Odoo 版本是最新的 odoo_15.0(社区版)

I got error ValueError('<class \'AttributeError\'>: "\'float\' object has no attribute \'number_of_days\'" while evaluating\n\'result =-(contract.wage/31) * worked_days.Unpaid.number_of_days\'') when I'm trying to deduct Unpaid Leave from Payroll. I'm new in Odoo. Please help me.

I recently installed https://apps.odoo.com/apps/modules/15.0/om_hr_payroll/ this third party community edition.

I have created Salary Rule as like below Snapshot

salary rule

now, then I added that salary rule in Salary Structures

enter image description here

Now then when I click Compute Sheet in Employee Payslips then I got error as like below snapshot

enter image description here

I was seen this Blog post of this Module Provider Company https://www.cybrosys.com/blog/hr-unpaid-leaves-payroll-management-in-odoo-10

but still I got error in payroll

My Odoo Version is latest odoo_15.0 (Community Edition)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

挽清梦 2025-01-18 15:07:41

Odoo 将循环遍历 Worked Days 行,以使用其 code 将这些行添加到 worked_days_dict

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 代码的 days 行:

result = (contract.wage/30) * worked_days.Unpaid.number_of_days

请注意,字段名称为:number_of_days

Odoo will loop over Worked Days lines to add the lines to the worked_days_dict using their 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

To use the following expression, you need to add a worked days line with Unpaid code :

result = (contract.wage/30) * worked_days.Unpaid.number_of_days

Note that the field name is : number_of_days

岛徒 2025-01-18 15:07:41

如果您使用此 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

参见下面的输出快照

snapshot of Output

你可以看到下面我的答案的快照

-:python 条件:-
快照python 条件
-: python 代码:-
快照python代码

If you are using this https://apps.odoo.com/apps/modules/15.0/om_hr_payroll/ payroll module, then there are many object variables available for customize salary rule using python code section. see below I shared available variables list

# 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 // for get Wage from Contract

totalWorkingDays = worked_days.WORK100.number_of_days // for get total working days (excluded public holidays, Sunday also... if you set Saturday off then Saturdays also)

date2 = payslip.date_to // for get selected Payslip date_to

date1 = payslip.date_from // for get selected Payslip 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) 

Now below I shared my Final Answered for Deduct Unpaid Leave from salary

This is Python condition field input

unpaidLeaves = 0
for line in payslip.worked_days_line_ids:
  if line.name == "Unpaid" and line.code == "UNPAID" :
    result = line.number_of_days

This is Python code field input

# 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

See below Snapshot of Output

snapshot of Output

you can see below snapshot of my answer

-: python condition :-
snapshot of python condition
-: python code :-
snapshot of python code

南街九尾狐 2025-01-18 15:07:41

除了建议的答案之外,
可以在 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 示例图像

在此处输入图像描述

In addition to the suggested answers,
One can calculate in python the unpaid leave amount with this formular:

wagePerDay = contract.wage / worked_days.WORK100.number_of_days      
totalUnpaidWage = wagePerDay*worked_days.LEAVE90.number_of_days;
result = round(totalUnpaidWage, 2)

Where:
worked_days.WORK100.number_of_days is the total number of days worked for that month as recroded by odoo.

worked_days.LEAVE90.number_of_days is the number of unpaid leave.
The code LEAVE90 can be configured under the tab Unpaid Work Entry Type which can be found when editing Salary Structure.

Find attached the example image from Odoo

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文