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 14, 2022
1 parent ac65160 commit aaac623
Show file tree
Hide file tree
Showing 27 changed files with 214 additions and 240 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/demo/hr_payroll_demo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ ref('hr_salary_rule_convanceallowance1'),ref('hr_salary_rule_professionaltax1'),
<field name="company_id" ref="base.main_company" />
<field eval="1" name="active" />
<field name="name">Roger Scott</field>
<field name="work_location">Building 1, Second Floor</field>
<field name="work_phone">+3282823500</field>
<field
name="image_1920"
Expand Down
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
42 changes: 19 additions & 23 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 @@ -364,7 +358,7 @@ def _compute_leave_days(self, contract, day_from, day_to):
{
"name": holiday.holiday_status_id.name or _("Global Leaves"),
"sequence": 5,
"code": holiday.holiday_status_id.code or "GLOBAL",
"code": holiday.holiday_status_id.name or "GLOBAL",
"number_of_days": 0.0,
"number_of_hours": 0.0,
"contract_id": contract.id,
Expand Down Expand Up @@ -393,7 +387,7 @@ def _compute_worked_days(self, contract, day_from, day_to):
of the payslip. This returns the FULL work days expected for the resource
calendar selected for the employee (it don't substract leaves by default).
"""
work_data = contract.employee_id._get_work_days_data(
work_data = contract.employee_id._get_work_days_data_batch(
day_from,
day_to,
calendar=contract.resource_calendar_id,
Expand All @@ -403,8 +397,8 @@ def _compute_worked_days(self, contract, day_from, day_to):
"name": _("Normal Working Days paid at 100%"),
"sequence": 1,
"code": "WORK100",
"number_of_days": work_data["days"],
"number_of_hours": work_data["hours"],
"number_of_days": work_data[contract.employee_id.id]["days"],
"number_of_hours": work_data[contract.employee_id.id]["hours"],
"contract_id": contract.id,
}

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
5 changes: 2 additions & 3 deletions 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 All @@ -62,8 +61,8 @@ def _compute_parent_line_id(self):
)
if parent_line and len(parent_line) > 1:
raise UserError(
_("Recursion error. Only one line should be parent of %s")
% line.parent_rule_id.name
_("Recursion error. Only one line should be parent of %(name)s")
% {"name": line.parent_rule_id.name}
)
line.parent_line_id = (
parent_line[0].id if len(parent_line) == 1 else False
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
40 changes: 20 additions & 20 deletions payroll/models/hr_salary_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,11 @@ def _compute_rule_fix(self, localdict):
"rate": 100.0,
"amount": self.amount_fix,
}
except Exception:
except Exception as ex:
raise UserError(
_("Wrong quantity defined for salary rule %s (%s).")
% (self.name, self.code)
)
_("Wrong quantity defined for salary rule %(name)s (%(code)s).")
% {"name": self.name, "code": self.code}
) from ex

def _compute_rule_percentage(self, localdict):
try:
Expand All @@ -220,14 +220,14 @@ def _compute_rule_percentage(self, localdict):
"rate": self.amount_percentage,
"amount": float(safe_eval(self.amount_percentage_base, localdict)),
}
except Exception:
except Exception as ex:
raise UserError(
_(
"Wrong percentage base or quantity defined for salary "
"rule %s (%s)."
"rule %(name)s (%(code)s)."
)
% (self.name, self.code)
)
% {"name": self.name, "code": self.code}
) from ex

def _compute_rule_code(self, localdict):
try:
Expand All @@ -237,14 +237,14 @@ def _compute_rule_code(self, localdict):
raise UserError(
_(
"""
Wrong python code defined for salary rule %s (%s).
Wrong python code defined for salary rule %(name)s (%(code)s).
Here is the error received:
%s
%(err)s
"""
)
% (self.name, self.code, repr(ex))
)
% {"name": self.name, "code": self.code, "err": repr(ex)}
) from ex

def _get_rule_dict(self, localdict):
name = localdict.get("result_name") or self.name
Expand Down Expand Up @@ -276,11 +276,11 @@ def _satisfy_condition_range(self, localdict):
return (
self.condition_range_min <= result <= self.condition_range_max or False
)
except Exception:
except Exception as ex:
raise UserError(
_("Wrong range condition defined for salary rule %s (%s).")
% (self.name, self.code)
)
_("Wrong range condition defined for salary rule %(name)s (%(code)s).")
% {"name": self.name, "code": self.code}
) from ex

def _satisfy_condition_python(self, localdict):
try:
Expand All @@ -290,11 +290,11 @@ def _satisfy_condition_python(self, localdict):
raise UserError(
_(
"""
Wrong python condition defined for salary rule %s (%s).
Wrong python condition defined for salary rule %(name)s (%(code)s).
Here is the error received:
%s
%(err)s
"""
)
% (self.name, self.code, repr(ex))
)
% {"name": self.name, "code": self.code, "err": repr(ex)}
) from ex
Loading

0 comments on commit aaac623

Please sign in to comment.