Skip to content

Commit

Permalink
[17.0][MIG] payroll: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
FernandoRomera committed Dec 21, 2023
1 parent 7a96ef4 commit 07def57
Show file tree
Hide file tree
Showing 20 changed files with 75 additions and 72 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": "16.0.1.1.0",
"version": "17.0.1.0.0",
"category": "Payroll",
"website": "https://github.com/OCA/payroll",
"sequence": 38,
Expand Down
2 changes: 1 addition & 1 deletion payroll/models/base_browsable.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
_logger = logging.getLogger(__name__)


class BaseBrowsableObject(object):
class BaseBrowsableObject:
def __init__(self, vals_dict):
self.__dict__["base_fields"] = ["base_fields", "dict"]
self.dict = vals_dict
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 @@ -66,7 +66,7 @@ def _check_parent_id(self):
def copy(self, default=None):
self.ensure_one()
default = dict(default or {}, code=_("%s (copy)") % self.code)
return super(HrPayrollStructure, self).copy(default)
return super().copy(default)

def get_all_rules(self):
"""
Expand Down
2 changes: 1 addition & 1 deletion payroll/models/hr_payslip.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ def unlink(self):
raise UserError(
_("You cannot delete a payslip which is not draft or cancelled")
)
return super(HrPayslip, self).unlink()
return super().unlink()

def compute_sheet(self):
for payslip in self:
Expand Down
9 changes: 5 additions & 4 deletions payroll/models/hr_payslip_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ def _compute_parent_line_id(self):
for line in self:
if line.parent_rule_id:
parent_line = line.slip_id.line_ids.filtered(
lambda l: l.salary_rule_id == line.parent_rule_id
and l.contract_id == line.contract_id
and l.slip_id == line.slip_id
lambda record, line=line: record.salary_rule_id
== line.parent_rule_id
and record.contract_id == line.contract_id
and record.slip_id == line.slip_id
)
if parent_line and len(parent_line) > 1:
raise UserError(
Expand Down Expand Up @@ -92,4 +93,4 @@ def create(self, vals_list):
raise UserError(
_("You must set a contract to create a payslip line.")
)
return super(HrPayslipLine, self).create(vals_list)
return super().create(vals_list)
4 changes: 2 additions & 2 deletions payroll/models/hr_salary_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def _compute_rule(self, localdict):
:rtype: {"name": string, "quantity": float, "rate": float, "amount": float}
"""
self.ensure_one()
method = "_compute_rule_{}".format(self.amount_select)
method = f"_compute_rule_{self.amount_select}"
return api.call_kw(self, method, [self.ids, localdict], {})

def _compute_rule_fix(self, localdict):
Expand Down Expand Up @@ -285,7 +285,7 @@ def _satisfy_condition(self, localdict):
given contract. Return False otherwise.
"""
self.ensure_one()
method = "_satisfy_condition_{}".format(self.condition_select)
method = f"_satisfy_condition_{self.condition_select}"
if self.parent_rule_id:
current_result = api.call_kw(self, method, [self.ids, localdict], {})
parent_result = self.parent_rule_id._satisfy_condition(localdict)
Expand Down
3 changes: 3 additions & 0 deletions payroll/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
2 changes: 1 addition & 1 deletion payroll/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class TestPayslipBase(TransactionCase):
def setUp(self):
super(TestPayslipBase, self).setUp()
super().setUp()

self.CalendarAttendance = self.env["resource.calendar.attendance"]
self.Contract = self.env["hr.contract"]
Expand Down
2 changes: 0 additions & 2 deletions payroll/tests/test_browsable_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ def setUp(self):
super().setUp()

def test_init(self):

obj = BrowsableObject(self.richard_emp.id, {"test": 1}, self.env)

self.assertEqual(obj.test, 1, "Simple initialization")
Expand Down Expand Up @@ -51,7 +50,6 @@ def test_init(self):
)

def test_update_attribute(self):

obj = BrowsableObject(
self.richard_emp.id,
{
Expand Down
2 changes: 1 addition & 1 deletion payroll/tests/test_hr_payroll_cancel.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class TestHrPayrollCancel(common.TransactionCase):
def setUp(self):
super(TestHrPayrollCancel, self).setUp()
super().setUp()
# Set system parameter
self.env["ir.config_parameter"].sudo().set_param(
"payroll.allow_cancel_payslips", True
Expand Down
2 changes: 1 addition & 1 deletion payroll/tests/test_hr_payslip_change_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class TestHrPayslipChangeState(TestHrPayrollCancel):
def setUp(self):
super(TestHrPayslipChangeState, self).setUp()
super().setUp()
self.tested_model = self.env["hr.payslip.change.state"]

def test_change_state(self):
Expand Down
3 changes: 0 additions & 3 deletions payroll/tests/test_hr_payslip_worked_days.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ def setUp(self):
)

def _common_contract_leave_setup(self):

self.richard_emp.resource_id.calendar_id = self.full_calendar
self.richard_emp.contract_ids.resource_calendar_id = self.full_calendar

Expand All @@ -74,7 +73,6 @@ def _common_contract_leave_setup(self):
)

def test_worked_days_negative(self):

self._common_contract_leave_setup()

# Set system parameter
Expand Down Expand Up @@ -107,7 +105,6 @@ def test_worked_days_negative(self):
)

def test_leaves_positive(self):

self._common_contract_leave_setup()

# Set system parameter
Expand Down
28 changes: 17 additions & 11 deletions payroll/tests/test_hr_salary_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ def setUp(self):
)

def test_python_code_return_values(self):

self.test_rule.amount_python_compute = (
"result_rate = 0\n" "result_qty = 0\n" "result = 0\n"
)
Expand All @@ -67,15 +66,14 @@ def test_python_code_return_values(self):
payslip.onchange_employee()
payslip.compute_sheet()

line = payslip.line_ids.filtered(lambda l: l.code == "TEST")
line = payslip.line_ids.filtered(lambda record: record.code == "TEST")
self.assertEqual(len(line), 1, "I found the Test line")
self.assertEqual(line.amount, 0.0, "The amount is zero")
self.assertEqual(line.rate, 0.0, "The rate is zero")
self.assertEqual(line.quantity, 0.0, "The quantity is zero")
self.assertEqual(line.code, "TEST", "The code is 'TEST'")

def test_python_code_result_not_set(self):

self.test_rule.amount_python_compute = "result = 2"

# Open contracts
Expand All @@ -90,7 +88,7 @@ def test_python_code_result_not_set(self):
payslip.onchange_employee()
payslip.compute_sheet()

line = payslip.line_ids.filtered(lambda l: l.code == "TEST")
line = payslip.line_ids.filtered(lambda record: record.code == "TEST")
self.assertEqual(len(line), 1, "I found the Test line")
self.assertEqual(line.amount, 2.0, "The amount is zero")
self.assertEqual(line.rate, 100.0, "The rate is zero")
Expand All @@ -110,7 +108,7 @@ def test_parent_child_order(self):
payslip.compute_sheet()

# Check child test rule calculated without being in the structure
line = payslip.line_ids.filtered(lambda l: l.code == "CHILD_TEST")
line = payslip.line_ids.filtered(lambda record: record.code == "CHILD_TEST")
self.assertEqual(len(line), 1, "Child line founded")

# Change sequence of child rule to calculate before of the parent rule
Expand All @@ -122,7 +120,7 @@ def test_parent_child_order(self):
payslip.compute_sheet()

# Child rule should be computed
line = payslip.line_ids.filtered(lambda l: l.code == "CHILD_TEST")
line = payslip.line_ids.filtered(lambda record: record.code == "CHILD_TEST")
self.assertEqual(len(line), 1, "Child line founded")

# Change the parent rule condition to return False
Expand All @@ -135,8 +133,12 @@ def test_parent_child_order(self):
payslip.compute_sheet()

# Parent and child rule should not be calculated even if child rule condition is true
parent_line = payslip.line_ids.filtered(lambda l: l.code == "PARENT_TEST")
child_line = payslip.line_ids.filtered(lambda l: l.code == "CHILD_TEST")
parent_line = payslip.line_ids.filtered(
lambda record: record.code == "PARENT_TEST"
)
child_line = payslip.line_ids.filtered(
lambda record: record.code == "CHILD_TEST"
)
self.assertEqual(len(parent_line), 0, "No parent line found")
self.assertEqual(len(child_line), 0, "No child line found")

Expand Down Expand Up @@ -188,9 +190,13 @@ def test_rule_and_category_with_and_without_code(self):
}
)
payslip.compute_sheet()
line = payslip.line_ids.filtered(lambda l: l.code == "rule_test_code")
line = payslip.line_ids.filtered(lambda record: record.code == "rule_test_code")
self.assertEqual(line.total, 7000, "5000 categories.BASIC + 2000 HRA = 7000")
line = payslip.line_ids.filtered(lambda l: l.name == "rule without code")
line = payslip.line_ids.filtered(
lambda record: record.name == "rule without code"
)
self.assertEqual(len(line), 1, "Line found: rule without code")
line = payslip.line_ids.filtered(lambda l: l.name == "rule without category")
line = payslip.line_ids.filtered(
lambda record: record.name == "rule without category"
)
self.assertEqual(len(line), 1, "Line found: rule without category")
22 changes: 5 additions & 17 deletions payroll/tests/test_payslip_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ def test_00_payslip_flow(self):

# Check child rules shown in table by default
child_line = richard_payslip.dynamic_filtered_payslip_lines.filtered(
lambda l: l.code == "NET_CHILD"
lambda record: record.code == "NET_CHILD"
)
self.assertEqual(
len(child_line), 1, "Child line found when flag desactivated (default)"
)

# Check parent line id value is correct
parent_line = richard_payslip.dynamic_filtered_payslip_lines.filtered(
lambda l: l.code == "NET"
lambda record: record.code == "NET"
)
self.assertEqual(
child_line.parent_line_id.code,
Expand All @@ -82,7 +82,7 @@ def test_00_payslip_flow(self):

# Check child rules not shown in table after flag changed
child_line = richard_payslip.dynamic_filtered_payslip_lines.filtered(
lambda l: l.code == "NET_CHILD"
lambda record: record.code == "NET_CHILD"
)
self.assertEqual(
len(child_line), 0, "The child line is not found when flag activated"
Expand All @@ -93,7 +93,7 @@ def test_00_payslip_flow(self):
work100 = richard_payslip.worked_days_line_ids.filtered(
lambda x: x.code == "WORK100"
)
line = richard_payslip.line_ids.filtered(lambda l: l.code == "NET")
line = richard_payslip.line_ids.filtered(lambda record: record.code == "NET")
self.assertEqual(len(line), 1, "I found the 'NET' line")
self.assertEqual(
line[0].amount,
Expand Down Expand Up @@ -169,7 +169,6 @@ def test_00_payslip_flow(self):
)

def test_contract_qty(self):

# I set the test rule to detect contract count
self.test_rule.amount_python_compute = (
"result = payroll.contracts and payroll.contracts.count or -1.0"
Expand All @@ -184,14 +183,13 @@ def test_contract_qty(self):
richard_payslip.onchange_employee()
richard_payslip.compute_sheet()

line = richard_payslip.line_ids.filtered(lambda l: l.code == "TEST")
line = richard_payslip.line_ids.filtered(lambda record: record.code == "TEST")
self.assertEqual(len(line), 1, "I found the Test line")
self.assertEqual(
line[0].amount, 1.0, "The calculated dictionary value 'contracts.qty' is 1"
)

def test_compute_multiple_payslips(self):

self.apply_contract_cron()
payslips = self.Payslip.create(
[
Expand All @@ -211,7 +209,6 @@ def test_compute_multiple_payslips(self):
)

def test_get_contracts_singleton(self):

payslip = self.Payslip.create({"employee_id": self.sally.id})
contracts = payslip._get_employee_contracts()
self.assertFalse(contracts, "No currently open contracts for the employee")
Expand Down Expand Up @@ -240,7 +237,6 @@ def test_get_contracts_singleton(self):
)

def test_get_contracts_multiple(self):

self.sally.contract_ids[0].date_end = Date.today().strftime("%Y-%m-15")
self.Contract.create(
{
Expand All @@ -267,7 +263,6 @@ def test_get_contracts_multiple(self):
)

def test_compute_sheet_no_valid_contract(self):

frm = Form(self.Payslip)
frm.employee_id = self.richard_emp
payslip = frm.save()
Expand Down Expand Up @@ -300,7 +295,6 @@ def _get_sales_rules(self):
return sales_rules

def test_use_different_structure(self):

developer_rules = self._get_developer_rules()

self.apply_contract_cron()
Expand All @@ -320,7 +314,6 @@ def test_use_different_structure(self):
)

def test_get_salary_rules_singleton(self):

developer_rules = self._get_developer_rules()

self.apply_contract_cron()
Expand All @@ -339,7 +332,6 @@ def test_get_salary_rules_singleton(self):
)

def test_get_salary_rules_multi(self):

sales_allowance = self.SalaryRule.create(
{
"name": "Sales Allowance",
Expand Down Expand Up @@ -390,7 +382,6 @@ def test_get_payslip_line_singleton(self):
)

def test_get_payslip_line_multi(self):

self.apply_contract_cron()
payslips = self.Payslip.create(
[
Expand All @@ -411,7 +402,6 @@ def test_get_payslip_line_multi(self):
)

def test_onchange_struct_id_singleton(self):

new_struct = self.PayrollStructure.create(
{
"name": "Simple Structure",
Expand Down Expand Up @@ -448,7 +438,6 @@ def test_onchange_struct_id_singleton(self):
)

def test_onchange_struct_id_multi(self):

new_struct = self.PayrollStructure.create(
{
"name": "Simple Structure",
Expand Down Expand Up @@ -543,7 +532,6 @@ def test_onchange_dates_multi(self):
)

def test_onchange_employee(self):

self.apply_contract_cron()
payslip = self.Payslip.create({"employee_id": self.sally.id})
payslip.name = "Random name Foo"
Expand Down
2 changes: 1 addition & 1 deletion payroll/views/hr_payroll_structure_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
<field name="name" />
<field
name="code"
attrs="{'required': [('require_code','=',True)]}"
required="require_code"
/>
<field name="parent_id" />
<field
Expand Down
Loading

0 comments on commit 07def57

Please sign in to comment.