Skip to content

Commit

Permalink
[MIG] hr_payroll_period: Migration to 18.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dreispt committed Jan 27, 2025
1 parent 7ded9ad commit a2e952b
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 71 deletions.
2 changes: 1 addition & 1 deletion hr_payroll_period/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

{
"name": "HR Payroll Period",
"version": "16.0.1.0.0",
"version": "18.0.1.0.0",
"license": "AGPL-3",
"category": "Payroll",
"summary": "Add payroll periods",
Expand Down
16 changes: 6 additions & 10 deletions hr_payroll_period/data/ir_cron.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo noupdate="1">
<record id="ir_cron_hr_payroll_period" model="ir.cron">
<field name='name'>Create Next Fiscal Year</field>
<field name='interval_number'>1</field>
<field name='interval_type'>months</field>
<field name="numbercall">-1</field>
<field name="doall" eval="False" />
<field name="active" eval="False" />
<field name="code">model.cron_create_next_fiscal_year()</field>
<field name="state">code</field>
<field name="user_id" ref="base.user_root" />
<field name="name">Create Next Fiscal Year</field>
<field name="model_id" ref="model_hr_fiscalyear" />
<field name="state">code</field>
<field name="code">model.cron_create_next_fiscal_year()</field>
<field name="interval_number">1</field>
<field name="interval_type">months</field>
<field name="active" eval="False" />
</record>
</odoo>
31 changes: 10 additions & 21 deletions hr_payroll_period/models/hr_payslip.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,16 @@ class HrPayslip(models.Model):
_inherit = "hr.payslip"

hr_period_id = fields.Many2one("hr.period", string="Period")
date_payment = fields.Date("Date of Payment")
date_payment = fields.Date(
"Date of Payment",
related="payslip_run_id.date_payment",
store=True,
readonly=False,
)
date_from = fields.Date(
related="payslip_run_id.date_start", store=True, readonly=False
)
date_to = fields.Date(related="payslip_run_id.date_end", store=True, readonly=False)

@api.constrains("hr_period_id", "company_id")
def _check_period_company(self):
Expand Down Expand Up @@ -52,23 +61,3 @@ def onchange_contract_period(self):
)
if period:
self.hr_period_id = period.id if period else False

@api.onchange("hr_period_id")
def onchange_hr_period_id(self):
if self.hr_period_id:
# dates must be updated together to prevent constraint
self.date_from = self.hr_period_id.date_start
self.date_to = self.hr_period_id.date_end
self.date_payment = self.hr_period_id.date_payment

@api.model
def create(self, vals):
if vals.get("payslip_run_id"):
payslip_run = self.env["hr.payslip.run"].browse(vals["payslip_run_id"])
self.env["hr.employee"].browse(vals["employee_id"])
period = payslip_run.hr_period_id
vals["date_payment"] = payslip_run.date_payment
vals["hr_period_id"] = period.id
elif vals.get("date_to") and not vals.get("date_payment"):
vals["date_payment"] = vals["date_to"]
return super().create(vals)
36 changes: 14 additions & 22 deletions hr_payroll_period/models/hr_payslip_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
from odoo import _, api, fields, models
from odoo.exceptions import UserError

from .hr_fiscal_year import get_schedules


class HrPayslipRun(models.Model):
_inherit = "hr.payslip.run"
Expand All @@ -15,8 +13,20 @@ class HrPayslipRun(models.Model):
default=lambda obj: obj.env["ir.sequence"].next_by_code("hr.payslip.run"),
)
hr_period_id = fields.Many2one("hr.period", string="Period")
date_payment = fields.Date("Date of Payment")
schedule_pay = fields.Selection(get_schedules)
date_payment = fields.Date(
"Date of Payment",
related="hr_period_id.date_payment",
store=True,
)
date_from = fields.Date(
related="hr_period_id.date_start", store=True, readonly=False
)
date_to = fields.Date(related="hr_period_id.date_end", store=True, readonly=False)
schedule_pay = fields.Selection(
related="hr_period_id.schedule_pay",
store=True,
readonly=False,
)

@api.constrains("hr_period_id", "company_id")
def _check_period_company(self):
Expand Down Expand Up @@ -64,24 +74,6 @@ def onchange_company_id(self):
)
self.hr_period_id = (period.id if period else False,)

@api.onchange("hr_period_id")
def onchange_period_id(self):
period = self.hr_period_id
if period:
self.date_start = period.date_start
self.date_end = period.date_end
self.date_payment = period.date_payment
self.schedule_pay = period.schedule_pay

@api.model
def create(self, vals):
"""
Keep compatibility between modules
"""
if vals.get("date_end") and not vals.get("date_payment"):
vals.update({"date_payment": vals["date_end"]})
return super().create(vals)

def get_payslip_employees_wizard(self):
"""Replace the static action used to call the wizard"""
self.ensure_one()
Expand Down
10 changes: 5 additions & 5 deletions hr_payroll_period/views/date_range_type_view.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="view_date_range_type_hr_tree" model="ir.ui.view">
<field name="name">date.range.type.hr.tree</field>
<field name="name">date.range.type.hr.list</field>
<field name="model">date.range.type</field>
<field name="arch" type="xml">
<tree>
<list>
<field name="name" />
<field name="allow_overlap" />
<field
Expand All @@ -15,7 +15,7 @@
<field name="hr_fiscal_year" />
<field name="hr_period" />
<field name="active" />
</tree>
</list>
</field>
</record>
<record id="view_date_range_type_hr_form_view" model="ir.ui.view">
Expand All @@ -42,11 +42,11 @@
<field name="name">Period Types</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">date.range.type</field>
<field name="view_mode">tree,form</field>
<field name="view_mode">list,form</field>
<field
name="view_ids"
eval="[(5, 0, 0),
(0, 0, {'view_mode': 'tree', 'view_id': ref('view_date_range_type_hr_tree')}),
(0, 0, {'view_mode': 'list', 'view_id': ref('view_date_range_type_hr_tree')}),
(0, 0, {'view_mode': 'form', 'view_id': ref('view_date_range_type_hr_form_view')})]"
/>
<field
Expand Down
8 changes: 4 additions & 4 deletions hr_payroll_period/views/hr_fiscalyear_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,18 +100,18 @@
</record>
<!-- Tree -->
<record id="view_hr_fiscalyear_tree" model="ir.ui.view">
<field name="name">hr.fiscalyear.tree</field>
<field name="name">hr.fiscalyear.list</field>
<field name="model">hr.fiscalyear</field>
<field name="arch" type="xml">
<tree
<list
decoration-info="state == 'draft'"
decoration-muted="state == 'done'"
name="Fiscalyear"
>
<field name="name" />
<field name="company_id" groups="base.group_multi_company" />
<field name="state" />
</tree>
</list>
</field>
</record>
<!-- Search -->
Expand Down Expand Up @@ -155,7 +155,7 @@
<record id="action_hr_fiscalyear" model="ir.actions.act_window">
<field name="name">Payroll Fiscal Years</field>
<field name="res_model">hr.fiscalyear</field>
<field name="view_mode">tree,form</field>
<field name="view_mode">list,form</field>
<field name="domain">[('type_id.hr_fiscal_year','=',True)]</field>
</record>
<!-- Menu -->
Expand Down
6 changes: 3 additions & 3 deletions hr_payroll_period/views/hr_payslip_run_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
name="hr_period_id"
domain="[
('state', '=', 'open'),
('company_id', '=', company_i)
('company_id', '=', company_id)
]"
reaonly="state == 'close'"
readonly="state == 'close'"
/>
<field name="schedule_pay" readonly="state == 'close'" />
<field name="date_payment" required="1" readonly="state == 'close'" />
Expand Down Expand Up @@ -59,7 +59,7 @@
</record>
<!-- Tree -->
<record id="hr_payslip_run_tree" model="ir.ui.view">
<field name="name">hr.payslip.run.period.tree</field>
<field name="name">hr.payslip.run.period.list</field>
<field name="model">hr.payslip.run</field>
<field name="inherit_id" ref="payroll.hr_payslip_run_view_tree" />
<field name="arch" type="xml">
Expand Down
2 changes: 1 addition & 1 deletion hr_payroll_period/views/hr_payslip_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
</record>
<!-- Tree -->
<record id="view_hr_payslip_tree" model="ir.ui.view">
<field name="name">hr.payslip.period.tree</field>
<field name="name">hr.payslip.period.list</field>
<field name="model">hr.payslip</field>
<field name="inherit_id" ref="payroll.hr_payslip_view_tree" />
<field name="arch" type="xml">
Expand Down
8 changes: 4 additions & 4 deletions hr_payroll_period/views/hr_period_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@
</record>
<!-- Tree -->
<record id="view_hr_period_tree" model="ir.ui.view">
<field name="name">hr.period.tree</field>
<field name="name">hr.period.list</field>
<field name="model">hr.period</field>
<field name="arch" type="xml">
<tree
<list
decoration-info="state == 'open'"
decoration-muted="state == 'done'"
name="Payroll Period"
Expand All @@ -81,7 +81,7 @@
<field name="date_payment" />
<field name="company_id" groups="base.group_multi_company" />
<field name="state" />
</tree>
</list>
</field>
</record>
<!-- Search -->
Expand Down Expand Up @@ -114,7 +114,7 @@
<record id="action_hr_period" model="ir.actions.act_window">
<field name="name">Payroll Periods</field>
<field name="res_model">hr.period</field>
<field name="view_mode">tree,form</field>
<field name="view_mode">list,form</field>
<field name="domain">[('type_id.hr_period', '=', True)]</field>
<field
name="context"
Expand Down

0 comments on commit a2e952b

Please sign in to comment.