Skip to content

Commit

Permalink
[MIG] payroll: Migration to 18.0
Browse files Browse the repository at this point in the history
  • Loading branch information
regispirard committed Nov 16, 2024
1 parent f2d45b4 commit 1d138f2
Show file tree
Hide file tree
Showing 20 changed files with 100 additions and 88 deletions.
1 change: 1 addition & 0 deletions payroll/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ Contributors
- Hilar AK <[email protected]>
- Nimarosa (Nicolas Rodriguez) <[email protected]>
- Henrik Norlin (@appstogrow)
- Régis Pirard <[email protected]>

Maintainers
-----------
Expand Down
2 changes: 1 addition & 1 deletion payroll/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

{
"name": "Payroll",
"version": "17.0.1.0.0",
"version": "18.0.1.0.0",
"category": "Payroll",
"website": "https://github.com/OCA/payroll",
"sequence": 38,
Expand Down
2 changes: 1 addition & 1 deletion payroll/models/hr_payroll_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def _compute_require_code(self):

@api.constrains("parent_id")
def _check_parent_id(self):
if not self._check_recursion():
if self._has_cycle():
raise ValidationError(_("You cannot create a recursive salary structure."))

@api.returns("self", lambda value: value.id)
Expand Down
34 changes: 21 additions & 13 deletions payroll/models/hr_payslip.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
from dateutil.relativedelta import relativedelta
from pytz import timezone

from odoo import _, api, fields, models, tools
from odoo import _, api, fields, models
from odoo.exceptions import UserError, ValidationError
from odoo.tools.safe_eval import safe_eval

from .base_browsable import (
BaseBrowsableObject,
Expand Down Expand Up @@ -228,34 +227,44 @@ def action_payslip_cancel(self):
return self.write({"state": "cancel"})

def refund_sheet(self):
copied_payslips = self.env["hr.payslip"]
for payslip in self:
# Create a refund slip
copied_payslip = payslip.copy(
{"credit_note": True, "name": _("Refund: %s") % payslip.name}
)
# Assign a number
number = copied_payslip.number or self.env["ir.sequence"].next_by_code(
"salary.slip"
)
copied_payslip.write({"number": number})
# Validated refund slip
copied_payslip.with_context(
without_compute_sheet=True
).action_payslip_done()
# Write refund reference on payslip
payslip.write(
{"refunded_id": copied_payslip.id if copied_payslip else False}
)
# Add to list of refund slips
copied_payslips |= copied_payslip
# Action to open list view of refund slips
formview_ref = self.env.ref("payroll.hr_payslip_view_form", False)
treeview_ref = self.env.ref("payroll.hr_payslip_view_tree", False)
res = {
"name": _("Refund Payslip"),
"view_mode": "tree, form",
"view_mode": "list, form",
"view_id": False,
"res_model": "hr.payslip",
"type": "ir.actions.act_window",
"target": "current",
"domain": "[('id', 'in', %s)]" % copied_payslip.ids,
"domain": [("id", "in", copied_payslips.ids)],
"views": [
(treeview_ref and treeview_ref.id or False, "tree"),
(treeview_ref and treeview_ref.id or False, "list"),
(formview_ref and formview_ref.id or False, "form"),
],
"context": {},
}
payslip.write({"refunded_id": safe_eval(res["domain"])[0][2][0] or False})
return res

def unlink(self):
Expand Down Expand Up @@ -756,15 +765,14 @@ def onchange_employee(self):

def _compute_name(self):
for record in self:
date_formatted = babel.dates.format_date(
date=datetime.combine(record.date_from, time.min),
format="MMMM-y",
locale=record.env.context.get("lang") or "en_US",
)
record.name = _("Salary Slip of %(name)s for %(dt)s") % {
"name": record.employee_id.name,
"dt": tools.ustr(
babel.dates.format_date(
date=datetime.combine(record.date_from, time.min),
format="MMMM-y",
locale=record.env.context.get("lang") or "en_US",
)
),
"dt": str(date_formatted),
}

@api.onchange("contract_id")
Expand Down
15 changes: 10 additions & 5 deletions payroll/models/hr_salary_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class HrSalaryRule(models.Model):
help="Used to display the salary rule on payslip.",
)
parent_rule_id = fields.Many2one(
"hr.salary.rule", string="Parent Salary Rule", index=True
comodel_name="hr.salary.rule", string="Parent Salary Rule", index=True
)
company_id = fields.Many2one(
"res.company",
Expand Down Expand Up @@ -167,10 +167,15 @@ class HrSalaryRule(models.Model):

@api.constrains("parent_rule_id")
def _check_parent_rule_id(self):
if not self._check_recursion(parent="parent_rule_id"):
raise ValidationError(
_("Error! You cannot create recursive hierarchy of Salary Rules.")
)
if self.env.registry[self._name]._name != "hr.salary.rule":
# HrPayslipLine inherits from "hr.salary.rule" and we don't
# want to do this check on a payslip line
return
for rule in self:
if rule._has_cycle(field_name="parent_rule_id"):
raise ValidationError(
_("Error! You cannot create recursive hierarchy of Salary Rules.")
)

def _recursive_search_of_rules(self):
"""
Expand Down
2 changes: 1 addition & 1 deletion payroll/models/hr_salary_rule_category.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def _compute_require_code(self):

@api.constrains("parent_id")
def _check_parent_id(self):
if not self._check_recursion():
if self._has_cycle():
raise ValidationError(
_(
"Error! You cannot create recursive hierarchy of Salary "
Expand Down
1 change: 1 addition & 0 deletions payroll/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
- Hilar AK \<<[email protected]>\>
- Nimarosa (Nicolas Rodriguez) \<<[email protected]>\>
- Henrik Norlin (@appstogrow)
- Régis Pirard \<<[email protected]>\>
1 change: 1 addition & 0 deletions payroll/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ <h2><a class="toc-backref" href="#toc-entry-4">Contributors</a></h2>
<li>Hilar AK &lt;<a class="reference external" href="mailto:hilarak&#64;gmail.com">hilarak&#64;gmail.com</a>&gt;</li>
<li>Nimarosa (Nicolas Rodriguez) &lt;<a class="reference external" href="mailto:nicolarsande&#64;gmail.com">nicolarsande&#64;gmail.com</a>&gt;</li>
<li>Henrik Norlin (&#64;appstogrow)</li>
<li>Régis Pirard &lt;<a class="reference external" href="mailto:regis.pirard&#64;tincid.com">regis.pirard&#64;tincid.com</a>&gt;</li>
</ul>
</div>
<div class="section" id="maintainers">
Expand Down
4 changes: 2 additions & 2 deletions payroll/tests/test_hr_payslip_worked_days.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import time
from datetime import date, datetime

from odoo.tests.common import Form
from odoo.tests import Form

from .common import TestPayslipBase

Expand All @@ -20,7 +20,7 @@ def setUp(self):
{
"name": "TestLeaveType",
"code": "TESTLV",
"allocation_validation_type": "no",
"allocation_validation_type": "no_validation",
"leave_validation_type": "no_validation",
}
)
Expand Down
10 changes: 5 additions & 5 deletions payroll/views/hr_contribution_register_views.xml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="hr_contribution_register_view_tree" model="ir.ui.view">
<field name="name">hr.contribution.register.tree</field>
<field name="name">hr.contribution.register.list</field>
<field name="model">hr.contribution.register</field>
<field name="arch" type="xml">
<tree>
<list>
<field name="name" />
<field
name="company_id"
groups="base.group_multi_company"
options="{'no_create': True}"
/>
</tree>
</list>
</field>
</record>
<record id="hr_contribution_register_view_kanban" model="ir.ui.view">
Expand All @@ -20,7 +20,7 @@
<field name="arch" type="xml">
<kanban class="o_kanban_mobile">
<templates>
<t t-name="kanban-box">
<t t-name="card">
<div t-attf-class="oe_kanban_content oe_kanban_global_click">
<div class="row">
<div class="col-12">
Expand Down Expand Up @@ -72,7 +72,7 @@
<record id="hr_contribution_register_action" model="ir.actions.act_window">
<field name="name">Contribution Registers</field>
<field name="res_model">hr.contribution.register</field>
<field name="view_mode">tree,kanban,form</field>
<field name="view_mode">list,kanban,form</field>
<field name="help" type="html">
<p class="o_view_nocontent_smiling_face">Add a new contribution register</p>
<p>
Expand Down
20 changes: 10 additions & 10 deletions payroll/views/hr_payroll_structure_views.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="hr_payroll_structure_view_tree" model="ir.ui.view">
<field name="name">hr.payroll.structure.tree</field>
<field name="name">hr.payroll.structure.list</field>
<field name="model">hr.payroll.structure</field>
<field name="arch" type="xml">
<tree>
<list>
<field name="name" />
<field name="code" />
<field name="rule_ids" />
Expand All @@ -13,22 +13,22 @@
groups="base.group_multi_company"
options="{'no_create': True}"
/>
</tree>
</list>
</field>
</record>
<record id="hr_payroll_structure_view_tree_children" model="ir.ui.view">
<field name="name">hr.payroll.structure.tree</field>
<field name="name">hr.payroll.structure.list</field>
<field name="model">hr.payroll.structure</field>
<field name="arch" type="xml">
<tree>
<list>
<field name="name" />
<field name="code" />
<field
name="company_id"
groups="base.group_multi_company"
options="{'no_create': True}"
/>
</tree>
</list>
</field>
</record>
<record id="hr_payroll_structure_view_kanban" model="ir.ui.view">
Expand All @@ -37,7 +37,7 @@
<field name="arch" type="xml">
<kanban class="o_kanban_mobile">
<templates>
<t t-name="kanban-box">
<t t-name="card">
<div t-attf-class="oe_kanban_content oe_kanban_global_click">
<div class="row">
<div class="col-12">
Expand Down Expand Up @@ -92,13 +92,13 @@
<notebook colspan="4">
<page string="Salary Rules">
<field name="rule_ids" domain="[('parent_rule_id','=',False)]">
<tree>
<list>
<field name="name" />
<field name="code" />
<field name="category_id" />
<field name="sequence" column_invisible="1" />
<field name="register_id" />
</tree>
</list>
</field>
</page>
</notebook>
Expand All @@ -108,7 +108,7 @@
<record id="hr_payroll_structure_action" model="ir.actions.act_window">
<field name="name">Salary Structures</field>
<field name="res_model">hr.payroll.structure</field>
<field name="view_mode">tree,kanban,form</field>
<field name="view_mode">list,kanban,form</field>
</record>
<menuitem
id="hr_payroll_structure_menu"
Expand Down
16 changes: 8 additions & 8 deletions payroll/views/hr_payslip_line_views.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="hr_payslip_line_view_tree" model="ir.ui.view">
<field name="name">hr.payslip.line.tree</field>
<field name="name">hr.payslip.line.list</field>
<field name="model">hr.payslip.line</field>
<field name="arch" type="xml">
<tree editable="bottom" decoration-info="total == 0">
<list editable="bottom" decoration-info="total == 0">
<field name="allow_edit_payslip_lines" column_invisible="1" />
<field name="category_id" />
<field name="employee_id" column_invisible="1" />
Expand All @@ -18,7 +18,7 @@
<field name="amount_select" column_invisible="1" />
<field name="register_id" column_invisible="1" />
<field name="payslip_run_id" optional="hide" />
</tree>
</list>
</field>
</record>
<record id="hr_payslip_line_view_form" model="ir.ui.view">
Expand Down Expand Up @@ -62,8 +62,8 @@
<page name="child_ids" string="Child Line Details">
<group>
<field name="child_ids" readonly="1" nolabel="1">
<tree
editable="false"
<list
edit="false"
decoration-info="total == 0"
decoration-bf="parent_line_id == False"
>
Expand All @@ -82,7 +82,7 @@
decoration-success="total > 0 and parent_line_id == False"
sum="total_net"
/>
</tree>
</list>
</field>
</group>
</page>
Expand Down Expand Up @@ -155,14 +155,14 @@
>
<field name="name">Payslip Computation Details</field>
<field name="res_model">hr.payslip.line</field>
<field name="view_mode">tree,pivot,form</field>
<field name="view_mode">list,pivot,form</field>
<field name="domain">[('slip_id', 'in', active_ids)]</field>
<field name="binding_model_id" ref="model_hr_payslip" />
</record>
<record id="action_get_batch_payslip_lines" model="ir.actions.act_window">
<field name="name">Batch Payslip Lines</field>
<field name="res_model">hr.payslip.line</field>
<field name="view_mode">pivot,tree,form</field>
<field name="view_mode">pivot,list,form</field>
<field name="domain">[('payslip_run_id', 'in', active_ids)]</field>
<field name="binding_model_id" ref="model_hr_payslip_run" />
</record>
Expand Down
10 changes: 5 additions & 5 deletions payroll/views/hr_payslip_run_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
</field>
</record>
<record id="hr_payslip_run_view_tree" model="ir.ui.view">
<field name="name">hr.payslip.run.tree</field>
<field name="name">hr.payslip.run.list</field>
<field name="model">hr.payslip.run</field>
<field name="arch" type="xml">
<tree
<list
decoration-info="state in ('confirm','hr_check','accont_check')"
decoration-muted="state == 'cancel'"
multi_edit="1"
Expand All @@ -53,7 +53,7 @@
groups="base.group_multi_company"
optional="show"
/>
</tree>
</list>
</field>
</record>
<record id="hr_payslip_run_view_kanban" model="ir.ui.view">
Expand All @@ -62,7 +62,7 @@
<field name="arch" type="xml">
<kanban class="o_kanban_mobile">
<templates>
<t t-name="kanban-box">
<t t-name="card">
<div t-attf-class="oe_kanban_content oe_kanban_global_click">
<div class="row">
<div class="col-6">
Expand Down Expand Up @@ -163,7 +163,7 @@
<record id="hr_payslip_run_action" model="ir.actions.act_window">
<field name="name">Payslips Batches</field>
<field name="res_model">hr.payslip.run</field>
<field name="view_mode">tree,kanban,form</field>
<field name="view_mode">list,kanban,form</field>
<field name="search_view_id" ref="hr_payslip_run_view_search" />
</record>
<menuitem
Expand Down
Loading

0 comments on commit 1d138f2

Please sign in to comment.