跳至内容
菜单
此问题已终结
3 回复
5117 查看

Hi to all,

I'd like to extend the hr.attendance data model to manage a default break per day. So I switched to developer mode, then went to "technical" -> "data models" found hr.attendance model and added a float number field x_break. I also modified the corresponding view so that this field is shown. Now, how can I achieve, that this field carries a value of, for instance, 0.75 by default? The field should be editable but if no one edits, it should be 0.75. How can I do it? 

And, as a second step, I would like to have another field that shows the difference between worked_hours and this break. I think that this shoul be a calculated field. In the field definition I see a textbox "compute". Do I simply write down "worked_hours - x_break" in this textbox?

Best regards 

Thomas

形象
丢弃
最佳答案

Hi Thomas:

You can define the default value for x_break as follows:

  • Activate developer mode.

  • Go to the view/form where you have added the field.

  • Click on create to open a blank record and type 0.75 into the field.

  • Go into "Open Developer Tools" (the bug symbol at the top right of the screen) and choose "Set Defaults". Select "<name of x_break> = 0.75" and "All users" and click on "Save Default". This will save 0.75 as the default value for all users.

For the second step (assuming you have added another field called x_netto_hours), you can set the following in the Advanced Settings section of the field:

  • Dependencies: worked_hours,x_break

  • Compute:

for record in self:
    if record['worked_hours'] and record['x_break']:
        record['x_netto_hours'] = record['worked_hours'] - record['x_break']


形象
丢弃
最佳答案

Hey All,

i need this filed to but I don't get it worked in Version 16.

Could someone Help me?

形象
丢弃
编写者 最佳答案

Hi Paresh,

thank you very much for your quick answer. Setting the default value for the break works like a charm :)

But calculating the diff_hours gives this error when saving the model:

ValueError: <class 'AttributeError'>: "'hr.attendance' object has no attribute 'get'" while evaluating"for record in self:\n    record['x_netto_hours'] = record.get('worked_hours',0) - record.get('x_break',0)\n"

I've made a screenshot of the field definition, you can see it here: https://ibb.co/FsjcHxT

Do you have an idea how I can resolve this?

Kind regards 

Thomas


形象
丢弃

Try removing the space between the comma and x_break in "Dependencies".

I have also updated the code part of the solution since you got an error on the "get".

编写者

Wow, Paresh, thank you again, now it works, I'm happy and motivated learning a bit of python, it seems to me, it would not be bad.

相关帖文 回复 查看 活动
1
1月 20
7273
2
1月 21
7233
1
6月 25
5071
1
5月 25
1073
6
1月 23
16892