Skip to content

Commit

Permalink
[MIG] payroll: Migration to 15.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mtelahun committed Oct 13, 2022
1 parent 247967f commit c236735
Show file tree
Hide file tree
Showing 20 changed files with 161 additions and 190 deletions.
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": "14.0.5.5.1",
"version": "15.0.1.0.0",
"category": "Human Resources",
"website": "https://github.com/OCA/payroll",
"sequence": 38,
Expand Down
22 changes: 10 additions & 12 deletions payroll/data/hr_payroll_data.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<data noupdate="1">
<!-- Decimal Precision -->
<record forcecreate="True" id="decimal_payroll" model="decimal.precision">
<field name="name">Payroll</field>
<field name="digits">2</field>
</record>
<record forcecreate="True" id="decimal_payroll_rate" model="decimal.precision">
<field name="name">Payroll Rate</field>
<field name="digits">4</field>
</record>
</data>
<odoo noupdate="1">
<!-- Decimal Precision -->
<record forcecreate="True" id="decimal_payroll" model="decimal.precision">
<field name="name">Payroll</field>
<field name="digits">2</field>
</record>
<record forcecreate="True" id="decimal_payroll_rate" model="decimal.precision">
<field name="name">Payroll Rate</field>
<field name="digits">4</field>
</record>
</odoo>
16 changes: 7 additions & 9 deletions payroll/data/hr_payroll_sequence.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<data noupdate="1">
<record id="seq_salary_slip" model="ir.sequence">
<field name="name">Salary Slip</field>
<field name="code">salary.slip</field>
<field name="prefix">SLIP/</field>
<field name="padding">3</field>
</record>
</data>
<odoo noupdate="1">
<record id="seq_salary_slip" model="ir.sequence">
<field name="name">Salary Slip</field>
<field name="code">salary.slip</field>
<field name="prefix">SLIP/</field>
<field name="padding">3</field>
</record>
</odoo>
1 change: 0 additions & 1 deletion payroll/models/hr_employee.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class HrEmployee(models.Model):
)
payslip_count = fields.Integer(
compute="_compute_payslip_count",
string="Payslip Count",
groups="payroll.group_payroll_user",
)

Expand Down
34 changes: 15 additions & 19 deletions payroll/models/hr_payslip.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,13 @@ class HrPayslip(models.Model):
states={"draft": [("readonly", False)]},
)
date_from = fields.Date(
string="Date From",
readonly=True,
required=True,
default=lambda self: fields.Date.to_string(date.today().replace(day=1)),
states={"draft": [("readonly", False)]},
tracking=True,
)
date_to = fields.Date(
string="Date To",
readonly=True,
required=True,
default=lambda self: fields.Date.to_string(
Expand Down Expand Up @@ -149,10 +147,8 @@ class HrPayslip(models.Model):
dynamic_filtered_payslip_lines = fields.One2many(
"hr.payslip.line",
compute="_compute_dynamic_filtered_payslip_lines",
string="Dynamic Filtered Payslip Lines",
)
credit_note = fields.Boolean(
string="Credit Note",
readonly=True,
states={"draft": [("readonly", False)]},
help="Indicates this payslip has a refund of another",
Expand All @@ -168,16 +164,14 @@ class HrPayslip(models.Model):
payslip_count = fields.Integer(
compute="_compute_payslip_count", string="Payslip Computation Details"
)
hide_child_lines = fields.Boolean(string="Hide Child Lines", default=False)
compute_date = fields.Date("Compute Date")
hide_child_lines = fields.Boolean(default=False)
compute_date = fields.Date()
refunded_id = fields.Many2one(
"hr.payslip", string="Refunded Payslip", readonly=True
)
allow_cancel_payslips = fields.Boolean(
"Allow Cancel Payslips", compute="_compute_allow_cancel_payslips"
)
allow_cancel_payslips = fields.Boolean(compute="_compute_allow_cancel_payslips")
prevent_compute_on_confirm = fields.Boolean(
"Prevent Compute on Confirm", compute="_compute_prevent_compute_on_confirm"
compute="_compute_prevent_compute_on_confirm"
)

def _compute_prevent_compute_on_confirm(self):
Expand Down Expand Up @@ -780,15 +774,17 @@ def onchange_employee(self):

def _compute_name(self):
for record in self:
record.name = _("Salary Slip of %s for %s") % (
record.employee_id.name,
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",
)
),
record.name = _("Salary Slip of %(name)s for %(date)s") % (
{
"name": record.employee_id.name,
"date": 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",
)
),
}
)

@api.onchange("contract_id")
Expand Down
1 change: 0 additions & 1 deletion payroll/models/hr_payslip_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class HrPayslipLine(models.Model):
quantity = fields.Float(digits="Payroll", default=1.0)
total = fields.Float(
compute="_compute_total",
string="Total",
digits="Payroll",
store=True,
)
Expand Down
1 change: 0 additions & 1 deletion payroll/models/hr_payslip_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ class HrPayslipRun(models.Model):
+ relativedelta(months=+1, day=1, days=-1),
)
credit_note = fields.Boolean(
string="Credit Note",
readonly=True,
states={"draft": [("readonly", False)]},
help="If its checked, indicates that all payslips generated from here "
Expand Down
7 changes: 4 additions & 3 deletions payroll/models/hr_rule_parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class HrSalaryRuleParameterValue(models.Model):
"hr.rule.parameter", required=True, ondelete="cascade"
)
code = fields.Char(related="rule_parameter_id.code", store=True, readonly=True)
date_from = fields.Date(string="Date From", required=True)
date_from = fields.Date(required=True)
parameter_value = fields.Text(help="Python Code")
country_id = fields.Many2one(related="rule_parameter_id.country_id")
company_id = fields.Many2one(related="rule_parameter_id.company_id")
Expand All @@ -33,7 +33,7 @@ class HrSalaryRuleParameter(models.Model):

name = fields.Char(required=True)
code = fields.Char(required=True)
description = fields.Text("Description")
description = fields.Text()
country_id = fields.Many2one(
"res.country",
string="Country",
Expand Down Expand Up @@ -62,7 +62,8 @@ def _get_parameter_from_code(self, code, date=None):
return ast.literal_eval(rule_parameter.parameter_value)
else:
raise UserError(
_("No rule parameter with code '%s' was found for %s ") % (code, date)
_("No rule parameter with code '%(code)s' was found for %(date)d ")
% ({"code": code, "date": date})
)

_sql_constraints = [
Expand Down
168 changes: 83 additions & 85 deletions payroll/security/hr_payroll_security.xml
Original file line number Diff line number Diff line change
@@ -1,87 +1,85 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<data noupdate="1">
<record model="ir.module.category" id="module_category_payroll">
<field name="name">Payroll</field>
<field name="description">Manage employee payroll</field>
<field name="sequence">16</field>
</record>
<record id="group_payroll_user" model="res.groups">
<field name="name">Officer</field>
<field name="category_id" ref="module_category_payroll" />
<field
name="implied_ids"
eval="[(4, ref('hr.group_hr_user')), (4, ref('hr_contract.group_hr_contract_manager'))]"
/>
</record>
<record id="group_payroll_manager" model="res.groups">
<field name="name">Manager</field>
<field name="category_id" ref="module_category_payroll" />
<field name="implied_ids" eval="[(4, ref('payroll.group_payroll_user'))]" />
<field
name="users"
eval="[(4, ref('base.user_root')), (4, ref('base.user_admin'))]"
/>
</record>
<record id="base.default_user" model="res.users">
<field name="groups_id" eval="[(4,ref('payroll.group_payroll_manager'))]" />
</record>
<record id="hr_payroll_rule_officer" model="ir.rule">
<field name="name">Officer and subordinates Payslip</field>
<field name="model_id" ref="model_hr_payslip" />
<field name="domain_force">
['|','|', ('employee_id.user_id', '=', user.id),
('employee_id.department_id', '=', False),
('employee_id.department_id.manager_id.user_id', '=', user.id)]
</field>
<field name="groups" eval="[(4, ref('payroll.group_payroll_user'))]" />
</record>
<record id="hr_payslip_rule_manager" model="ir.rule">
<field name="name">All Payslip</field>
<field name="model_id" ref="model_hr_payslip" />
<field name="domain_force">[(1,'=',1)]</field>
<field name="groups" eval="[(4, ref('payroll.group_payroll_manager'))]" />
</record>
<!-- Company-restricted Records -->
<record model="ir.rule" id="hr_payslip_rule_company">
<field name="name">Payslip: multi-company</field>
<field name="model_id" ref="model_hr_payslip" />
<field name="global" eval="True" />
<field name="domain_force">
['|', ('company_id', '=', False), ('company_id', 'in', company_ids)]
</field>
</record>
<record model="ir.rule" id="hr_payroll_structure_rule_company">
<field name="name">Payroll Structure: multi-company</field>
<field name="model_id" ref="model_hr_payroll_structure" />
<field name="global" eval="True" />
<field name="domain_force">
['|', ('company_id', '=', False), ('company_id', 'in', company_ids)]
</field>
</record>
<record model="ir.rule" id="hr_salary_rule_company">
<field name="name">Salary Rule: multi-company</field>
<field name="model_id" ref="model_hr_salary_rule" />
<field name="global" eval="True" />
<field name="domain_force">
['|', ('company_id', '=', False), ('company_id', 'in', company_ids)]
</field>
</record>
<record model="ir.rule" id="hr_salary_category_rule_company">
<field name="name">Salary Rule Category: multi-company</field>
<field name="model_id" ref="model_hr_salary_rule_category" />
<field name="global" eval="True" />
<field name="domain_force">
['|', ('company_id', '=', False), ('company_id', 'in', company_ids)]
</field>
</record>
<record model="ir.rule" id="hr_contribution_register_rule_company">
<field name="name">Contribution Register: multi-company</field>
<field name="model_id" ref="model_hr_contribution_register" />
<field name="global" eval="True" />
<field name="domain_force">
['|', ('company_id', '=', False), ('company_id', 'in', company_ids)]
</field>
</record>
</data>
<odoo noupdate="1">
<record model="ir.module.category" id="module_category_payroll">
<field name="name">Payroll</field>
<field name="description">Manage employee payroll</field>
<field name="sequence">16</field>
</record>
<record id="group_payroll_user" model="res.groups">
<field name="name">Officer</field>
<field name="category_id" ref="module_category_payroll" />
<field
name="implied_ids"
eval="[(4, ref('hr.group_hr_user')), (4, ref('hr_contract.group_hr_contract_manager'))]"
/>
</record>
<record id="group_payroll_manager" model="res.groups">
<field name="name">Manager</field>
<field name="category_id" ref="module_category_payroll" />
<field name="implied_ids" eval="[(4, ref('payroll.group_payroll_user'))]" />
<field
name="users"
eval="[(4, ref('base.user_root')), (4, ref('base.user_admin'))]"
/>
</record>
<record id="base.default_user" model="res.users">
<field name="groups_id" eval="[(4,ref('payroll.group_payroll_manager'))]" />
</record>
<record id="hr_payroll_rule_officer" model="ir.rule">
<field name="name">Officer and subordinates Payslip</field>
<field name="model_id" ref="model_hr_payslip" />
<field name="domain_force">
['|','|', ('employee_id.user_id', '=', user.id),
('employee_id.department_id', '=', False),
('employee_id.department_id.manager_id.user_id', '=', user.id)]
</field>
<field name="groups" eval="[(4, ref('payroll.group_payroll_user'))]" />
</record>
<record id="hr_payslip_rule_manager" model="ir.rule">
<field name="name">All Payslip</field>
<field name="model_id" ref="model_hr_payslip" />
<field name="domain_force">[(1,'=',1)]</field>
<field name="groups" eval="[(4, ref('payroll.group_payroll_manager'))]" />
</record>
<!-- Company-restricted Records -->
<record model="ir.rule" id="hr_payslip_rule_company">
<field name="name">Payslip: multi-company</field>
<field name="model_id" ref="model_hr_payslip" />
<field name="global" eval="True" />
<field name="domain_force">
['|', ('company_id', '=', False), ('company_id', 'in', company_ids)]
</field>
</record>
<record model="ir.rule" id="hr_payroll_structure_rule_company">
<field name="name">Payroll Structure: multi-company</field>
<field name="model_id" ref="model_hr_payroll_structure" />
<field name="global" eval="True" />
<field name="domain_force">
['|', ('company_id', '=', False), ('company_id', 'in', company_ids)]
</field>
</record>
<record model="ir.rule" id="hr_salary_rule_company">
<field name="name">Salary Rule: multi-company</field>
<field name="model_id" ref="model_hr_salary_rule" />
<field name="global" eval="True" />
<field name="domain_force">
['|', ('company_id', '=', False), ('company_id', 'in', company_ids)]
</field>
</record>
<record model="ir.rule" id="hr_salary_category_rule_company">
<field name="name">Salary Rule Category: multi-company</field>
<field name="model_id" ref="model_hr_salary_rule_category" />
<field name="global" eval="True" />
<field name="domain_force">
['|', ('company_id', '=', False), ('company_id', 'in', company_ids)]
</field>
</record>
<record model="ir.rule" id="hr_contribution_register_rule_company">
<field name="name">Contribution Register: multi-company</field>
<field name="model_id" ref="model_hr_contribution_register" />
<field name="global" eval="True" />
<field name="domain_force">
['|', ('company_id', '=', False), ('company_id', 'in', company_ids)]
</field>
</record>
</odoo>
20 changes: 10 additions & 10 deletions payroll/tests/test_hr_payroll_cancel.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,16 @@ def _create_payslip(self):
[("payslip_id", "=", self.hr_payslip.id)]
)
payslip_input.write({"amount": 5.0})
context = {
"lang": "en_US",
"tz": False,
"active_model": "hr.payslip",
"department_id": False,
"active_ids": [self.payslip_action_id],
"section_id": False,
"active_id": self.payslip_action_id,
}
self.hr_payslip.with_context(context).compute_sheet()
self.hr_payslip.with_context(
{},
lang="en_US",
tz=False,
active_model="hr.payslip",
department_id=False,
active_ids=[self.payslip_action_id],
section_id=False,
active_id=self.payslip_action_id,
).compute_sheet()
return self.hr_payslip

def test_action_payslip_cancel(self):
Expand Down
5 changes: 3 additions & 2 deletions payroll/tests/test_hr_payslip_change_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ def setUp(self):
def test_change_state(self):
hr_payslip = self._create_payslip()
tested_model = self.tested_model
context = {"active_ids": [hr_payslip.id]}
action = tested_model.with_context(context).create({"state": "verify"})
action = tested_model.with_context(active_ids=[hr_payslip.id]).create(
{"state": "verify"}
)
# By default, a payslip is on draft state
action.change_state_confirm()
# trying to set it to wrong states
Expand Down
Loading

0 comments on commit c236735

Please sign in to comment.