-
-
Notifications
You must be signed in to change notification settings - Fork 112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ADD] hr_payslip_line_manually, [IMP] payroll (hr.payslip & hr.salary.rule) #51
Conversation
Hello @appstogrow, it's not clear to me which is a use case of this PR. I saw the demo examples but it didn't make more clear to me about the usage. Can you make an example so i can understand more? It seems interesting but i couldn't get it looking at the code only. About the question, hr.payslip _get_payslip_lines(), i don't think that an extra loop makes any harm. As i saw, you are using contract and analytic code for differentiating lines codes, so it works like the multiple contract implementation, so i think it works okay. Will test it tomorrow if i can. About hr.analytic.qty.rate.amount, what do you see that don't work well on 14.0? If you are saying this because the checks are failing, i think the build fails because payslip_line is a inherited model of salary_rule so it copy the fields added in salary_rule and that maybe could be fixed easily. Hope you get back with examples, it looks interesting module but couldn't figure out yet the usage. |
I have salary rules "Monthly wage" (for payslip) and "Fixed monthly wage" (for contract). |
See the description here. Why is indentation not allowed in a code demo in the description? |
@appstogrow i can't see in the link the part you are referring. But i think you are talking about pre-commit failing? pre-commit has some weird rules i suppose mandatory by oca code guidelines. Sometimes it fails in cases when it's wrong indentation. Think we have to adapt and fix all the error pre-commit says :/ |
@appstogrow I think we can work in a refactor of the function for allow them to be inherited and modified by another modules without the need to edit them in the main one. It's on my plans to do it. What do you think of wait for me to refactor that function to merge this module? Because i think that if we add more code to the function it will make it more and more large and we will end up with a huge function that supports other modules even if you don't install them. |
@appstogrow Great, this week I will have more than one PR ready so we will have it soon I hope. |
@appstogrow Hi Henrik, with #62 merged i think you can continue with this PR. I will wait for you to finish to introduce new PRs so we can get this merged before. If you need help, let me know. |
I have done some changes in hr.salary.rule hr.payslip |
How can we change the state from Draft to Open? |
@apps2grow What are you referring to? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@appstogrow I made some comments, maybe i'm missing something or it's not finished?
Payslip and salary_rule changes in payroll look good to me, but made some comments of improvements that we could make.
Also you should run pre-commit before you push, that way you will not get the error.
Thank you @nimarosa for reviewing. I answer to everything here. pre-commit still fails, because of documentation with demo code. I think this is ok. hr.salary.rule Currently, I don't need separate methods to compute fixed values or percentage values. I think it we should not make such methods until we expect that there is a need for them. hr.payslip.line.manually has a field for salary rule. When computing the rule, the code needs the records belonging to the rule. But the code doesn't know which rule is computing. Therefore I need localdict["rule"]. @nimarosa, do you see another way to do this? Thank you for pointing out that overriding methods ideally should call @mtelahun Would you also like to review? |
Hi @appstogrow,
I can't really comment on the module itself because I don't understand
the problem you are trying to solve. I can understand that this is
something you needed to solve a problem. I'm just saying I don't
understand what that is. However, I have some general comments on things
I noticed in the code.
- It seems to me it replicates large parts of the payroll code. For
example hr.payslip.line.manually replicates some the same fields as
hr.payslip.line. It also seems _compute_payslip_line() in hr.payslip is
replicated again (I don't know if this is intentional or a mistake). The
whole concept of hr.payslip.line.manually as a separate model escapes
me. Surely it should inherit from hr.payslip.line?
- Also, I don't understand what analytic accounts have to do with manual
payslip lines. Shouldn't they also apply to hr.payslip.line? And if
analytic accounts are not specific to manual payslip lines shouldn't it
be in a separate module: hr_payslip_line_analytic?
- In the demo data the condition python fields for both rules are
virtually identical. This to me is a clear sign that there must be a
better way to handle this. For example a fourth 'condition_select'
selection ("manual_payslip_line_rule", "Manual payslip line rule
match"). Then the module can do the matching that is repeated now in
every rule in the 'condition_python' field.
- As I've mentioned previously I am not a fan of complicated code in
salary rule python fields and the code in the demo rules makes me really
uneasy.
- The __manifest__ currently says it depends on payroll, but shouldn't
it include 'account_analytic' also? And if so, then it should also
depend on payroll_account, yes?
I have a "feeling" that there must be a better way to do what you want
to do but without understanding your problem I am not able to offer a
better solution 😬
…On 15/09/2022 19:07, Henrik Norlin wrote:
@mtelahun <https://github.com/mtelahun> Would you also like to review?
—
Reply to this email directly, view it on GitHub
<#51 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AB4YOHAO5HDL76KMCEMUGOTV6NCTLANCNFSM56TWWJVA>.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
@appstogrow
Maybe we can put this documentation in usage.rst? It's really necessary for it to be in demo xml? I think people will not look for documentation there.
I think it's better to leave the same name "_compute_rule()" if there is not any necessity to change it. I have some modules that inherit this method. It's not a trouble to change them but maybe people using the module who are not aware of this change will see their custom modules affected. If not crucial for you, I prefer we leave the current name, for me it's a good one.
I think that for good coding practices and because all refactoring we are doing in the past PRs will be great to separate each computation mode like you've done with _compute_python. You gave me the idea with your changes and I think it's a better approach to break the function in more smaller ones so they can be easily inherited if needed. I don't currently need this either but I think is good for the module. If you want to do it in this PR it's okay, if not, maybe I will include it in my next one as part of all the refactoring process of payroll. I think we are close to be ready for start the migration to version 15.0 so I think that all refactoring we can merge to 14.0 before that, will be great to have a strong module for 15.0 and 16.0 in the future. More maintainable and easy to develop. That's why I suggested this.
I think like @mtelahun i still don't understand what this new module currently does. Will try to look it more in depth and give you input, maybe we can crack a better way to archive it.
The problem with that is that if you override functions without using super, any user that wish to use your module will not be able to use any other module that inherits that functions. That makes your module very incompatible with all private payroll modules/localizations. Henrik, can you try to explain to us in a simple way, what is the use case or the problem your module solves? Maybe some images or videos will be helpful. I will install it tomorrow and try to understand it on the functional side, but I think that if we can understand more we can help you to improve it in a compatible way when you don't need too much override or repeated code. Look forward for your input. |
It is USAGE.rst which is failing in pre-commit. I will change the name back to I agree "it's a better approach to break the function in more smaller ones". One function should do only one thing. Please try out the
That is correct, and it is a temporary solution. Currently, the new module CANNOT call I have documented |
Now I have changed the name back to |
@appstogrow Hello, i'm trying the module, but when i try to add a manual payslip line in contract or payslip i get this error:
Is this expected? I can't add the lines. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@appstogrow
Hello Henrik, i've done a new review.
I tried the module, but i get the error that i described in my last comment every time i try to create a "manual_line". So i couldn't test much of it.
As saw, i understand the module is for making payslip lines manually in contract and/or payslip. So the payslip will compute the lines that you configured, no?
I can't think a use case but if you need it and use it, we can include it here in payroll.
I think that maybe you can move the changes in "payroll" to other PR? So we can review them and test it extensively. Then we can merge your module the way you want it to function. Despite that, i made some suggestions of your module code, that allows you calling super() in the right way in _compute_payslip_line. Please check it, that way you will edit the dict and don't override the compute method.
Regards
"license": "AGPL-3", | ||
"version": "14.0.1.0.0", | ||
"website": "https://github.com/OCA/payroll", | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe you want to add the maintainer key so you can maintain the module?
"name": "Manual payslip lines, with analytic account", | ||
"summary": "Easily create and use salary rules", | ||
"author": "AppsToGROW, Odoo Community Association (OCA)", | ||
"category": "Uncategorized", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use "Payroll" category.
copy=True, | ||
) | ||
|
||
def _compute_payslip_line(self, rule, localdict, lines_dict): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can just do this here:
def _compute_payslip_line(self, rule, localdict, lines_dict): localdict, lines_dict = super()._compute_payslip_line(rule, localdict, lines_dict) values = localdict["result_rules"].dict.get[rule.code] current_key = (rule.code+ "-"+ str(localdict["contract"].id)) new_key = (rule.code + "-" + str(localdict["contract"].id) + "-" + str(values.get("analytic_account_id"))) lines_dict[new_key] = lines_dict.pop(current_key) lines_dict[new_key].dict["analytic_account_id"] = values.get("analytic_account_id") return localdict, lines_dict
I didn't test it but surely you can do this without copying the whole method, just edit the returning values and the values you can get from "result_rules" you don't need to calculate them again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry gitgub broken my indentation. Please copy the code to python file to read it easily.
_description = "hr.payslip.line.manually" | ||
|
||
@api.model | ||
def _compute_default_model(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the function that gives me the error. Do you know why?
values["analytic_account_id"]: result_dict.get("result_analytic") | ||
result_list.append(values) | ||
return result_list | ||
return super(HrSalaryRule, self)._compute_rule_python(localdict) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure but this will generate a loop. You call super two times in the function.
return result_list | ||
return super(HrSalaryRule, self)._compute_rule_python(localdict) | ||
|
||
def _satisfy_condition_python(self, localdict): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I still don't get why this is necessary.
payroll/models/hr_payslip.py
Outdated
localdict["result_rules"].dict[rule.code] = BaseBrowsableObject( | ||
{"quantity": qty, "rate": rate, "amount": amount, "total": rule_total} | ||
) | ||
localdict["result_rules"].dict[rule.code] = BaseBrowsableObject(values) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you are leaving out including "total" in "result_rules". Original code is:
localdict["result_rules"].dict[rule.code] = BaseBrowsableObject( {"quantity": qty, "rate": rate, "amount": amount, "total": rule_total} )
It's okay for me to make a dict, but you should add the value values["total"] to values dict.
payroll/models/hr_salary_rule.py
Outdated
@@ -250,6 +234,16 @@ def _compute_rule(self, localdict): | |||
% (self.name, self.code, repr(ex)) | |||
) | |||
|
|||
def _compute_rule_python(self, localdict): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why leaving safe_eval out of _compute_rule_python?
payroll/models/hr_salary_rule.py
Outdated
@@ -288,3 +281,7 @@ def _satisfy_condition(self, localdict): | |||
) | |||
% (self.name, self.code, repr(ex)) | |||
) | |||
|
|||
def _satisfy_condition_python(self, localdict): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here you do the safe_eval inside function. Which approach are we going to use? both "python" functions must behave very similar.
Definitely we should implement this in next PRs. I take note of it for next one, so we can work in that. |
Please check if my suggestion works for allowing you to call super() in _compute_payslip_line() If we can't figure it out, maybe you can start a new PR with changes to "payroll" and maybe in that one we could implement the separation of methods of salary rule computation modes. Then we can merge this PR with only Anyways, i think the solution i pointed out could work with some adjustments. So in resume:
Hope this works for you. Thanks. |
@appstogrow If you want you can continue fixing the conflicts and checks in this PR since #70 is merged. Tell me if you need any input. |
@nimarosa Go ahead with your next PR. I am quite busy, and this PR may wait. |
@nimarosa Yes currently you need to do ca what it says: follow the menu,
refresh and then edit. I am still looking for a solution for this.
@mtelahun I saw your message now, didn't see it this morning. On Sunday I
will answer and provide a more clear description of the module and the
purpose.
fre. 16. sep. 2022, 16:32 skrev Nicolas Rodriguez Sande <
***@***.***>:
… @appstogrow <https://github.com/appstogrow> Hello, i'm trying the module,
but when i try to add a manual payslip line in contract or payslip i get
this error:
Please save changes, then refresh the page (F5). If needed, use the menu
Payroll / Employee Payslips, or the menu Employees / Employees / Contracts.
Is this expected? I can't add the lines.
—
Reply to this email directly, view it on GitHub
<#51 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ADXMQTYIHDDHYT4EXIG7YFDV6SAH5ANCNFSM56TWWJVA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
@appstogrow @norlinhenrik Hello Henrik, will this be finished o should i close it? |
We can close this PR. I think it is better to create a new PR for hr_payslip_line_manually when I take time for it. |
In previous payroll software, I registered payslip lines and contract lines (recurring payslip lines) directly. So I developed this for Odoo a few years ago when I transitioned to Odoo.
Usage:
Questions:
Do you think this is useful?
hr.payslip _get_payslip_lines() has an extra loop to create multiple lines for the same salary rule. There are several other changes also in
payroll
. I don't think they impact existing implementations, but I don't know. Are the changes acceptable?Model hr.analytic.qty.rate.amount has the fields model and res_id. Both payslip and contract has a field with one2many relation to hr.analytic.qty.rate.amount. This doesn't work so well in version 14.0. Do you know any other Odoo module with similar structure?