Skip to content

Commit

Permalink
[MIG] hr_payroll_period: migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dreispt committed Jan 26, 2025
1 parent fe44b9d commit a2df588
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 138 deletions.
2 changes: 1 addition & 1 deletion hr_payroll_period/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"license": "AGPL-3",
"category": "Payroll",
"summary": "Add payroll periods",
"author": "Savoir-faire Linux, " "Odoo Community Association (OCA)",
"author": "Savoir-faire Linux, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/payroll",
"depends": [
"payroll",
Expand Down
22 changes: 4 additions & 18 deletions hr_payroll_period/models/hr_fiscal_year.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,7 @@ def _default_type(self, company_id=False):
)
return period_type

period_ids = fields.One2many(
"hr.period", "fiscalyear_id", "Periods", states={"draft": [("readonly", False)]}
)
period_ids = fields.One2many("hr.period", "fiscalyear_id", "Periods")
state = fields.Selection(
[
("draft", "Draft"),
Expand All @@ -95,7 +93,6 @@ def _default_type(self, company_id=False):
schedule_pay = fields.Selection(
get_schedules,
required=True,
states={"draft": [("readonly", False)]},
default="monthly",
)
type_id = fields.Many2one(
Expand All @@ -112,7 +109,6 @@ def _default_type(self, company_id=False):
("6", "Saturday"),
],
"Weekday of Payment",
states={"draft": [("readonly", False)]},
)
payment_week = fields.Selection(
[
Expand All @@ -121,11 +117,8 @@ def _default_type(self, company_id=False):
("2", "Second Following Week"),
],
"Week of Payment",
states={"draft": [("readonly", False)]},
)
payment_day = fields.Selection(
get_payment_days, "Day of Payment", states={"draft": [("readonly", False)]}
)
payment_day = fields.Selection(get_payment_days, "Day of Payment")

def _count_range_no(self):
days_range = (
Expand All @@ -146,10 +139,7 @@ def onchange_schedule(self):
schedule_name = next(
(s[1] for s in get_schedules(self) if s[0] == self.schedule_pay), False
)
self.name = "%(year)s - %(schedule)s" % {
"year": year,
"schedule": schedule_name,
}
self.name = f"{year} - {schedule_name}"

def get_generator_vals(self):
self.ensure_one()
Expand Down Expand Up @@ -338,11 +328,7 @@ def cron_create_next_fiscal_year(self):

fiscal_year = self.create(
{
"name": "%(year)s - %(schedule)s"
% {
"year": next_year,
"schedule": schedule_name,
},
"name": f"{next_year} - {schedule_name}",
"date_start": fiscal_year_start,
"date_end": fiscal_year_end,
"schedule_pay": schedule_pay,
Expand Down
13 changes: 3 additions & 10 deletions hr_payroll_period/models/hr_payslip.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,8 @@
class HrPayslip(models.Model):
_inherit = "hr.payslip"

hr_period_id = fields.Many2one(
"hr.period",
string="Period",
readonly=True,
states={"draft": [("readonly", False)]},
)
date_payment = fields.Date(
"Date of Payment", readonly=True, states={"draft": [("readonly", False)]}
)
hr_period_id = fields.Many2one("hr.period", string="Period")
date_payment = fields.Date("Date of Payment")

@api.constrains("hr_period_id", "company_id")
def _check_period_company(self):
Expand Down Expand Up @@ -78,4 +71,4 @@ def create(self, vals):
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(HrPayslip, self).create(vals)
return super().create(vals)
27 changes: 6 additions & 21 deletions hr_payroll_period/models/hr_payslip_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,11 @@ class HrPayslipRun(models.Model):
_inherit = "hr.payslip.run"

name = fields.Char(
required=True,
readonly=True,
states={"draft": [("readonly", False)]},
default=lambda obj: obj.env["ir.sequence"].next_by_code("hr.payslip.run"),
)
company_id = fields.Many2one(
"res.company",
"Company",
states={"close": [("readonly", True)]},
default=lambda obj: obj.env.company,
)
hr_period_id = fields.Many2one(
"hr.period", string="Period", states={"close": [("readonly", True)]}
)
date_payment = fields.Date(
"Date of Payment", states={"close": [("readonly", True)]}
)
schedule_pay = fields.Selection(
get_schedules, states={"close": [("readonly", True)]}
)
hr_period_id = fields.Many2one("hr.period", string="Period")
date_payment = fields.Date("Date of Payment")
schedule_pay = fields.Selection(get_schedules)

@api.constrains("hr_period_id", "company_id")
def _check_period_company(self):
Expand Down Expand Up @@ -95,7 +80,7 @@ def create(self, vals):
"""
if vals.get("date_end") and not vals.get("date_payment"):
vals.update({"date_payment": vals["date_end"]})
return super(HrPayslipRun, self).create(vals)
return super().create(vals)

def get_payslip_employees_wizard(self):
"""Replace the static action used to call the wizard"""
Expand Down Expand Up @@ -134,12 +119,12 @@ def close_payslip_run(self):
% run.name
)
self.update_periods()
return super(HrPayslipRun, self).close_payslip_run()
return super().close_payslip_run()

def draft_payslip_run(self):
for run in self:
run.hr_period_id.button_re_open()
return super(HrPayslipRun, self).draft_payslip_run()
return super().draft_payslip_run()

def update_periods(self):
self.ensure_one()
Expand Down
12 changes: 3 additions & 9 deletions hr_payroll_period/models/hr_period.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,13 @@ def _default_type(self, company_id=False):
)
return period_type

name = fields.Char(required=True, states={"draft": [("readonly", False)]})
number = fields.Integer(required=True, states={"draft": [("readonly", False)]})
date_payment = fields.Date(
"Date of Payment", required=True, states={"draft": [("readonly", False)]}
)
name = fields.Char(required=True)
number = fields.Integer(required=True)
date_payment = fields.Date("Date of Payment", required=True)
fiscalyear_id = fields.Many2one(
"hr.fiscalyear",
"Fiscal Year",
required=True,
states={"draft": [("readonly", False)]},
ondelete="cascade",
)
state = fields.Selection(
Expand All @@ -48,13 +45,10 @@ def _default_type(self, company_id=False):
string="Company",
store=True,
related="fiscalyear_id.company_id",
readonly=True,
states={"draft": [("readonly", False)]},
)
schedule_pay = fields.Selection(
get_schedules,
required=True,
states={"draft": [("readonly", False)]},
default="monthly",
)
payslip_ids = fields.One2many(
Expand Down
2 changes: 1 addition & 1 deletion hr_payroll_period/tests/test_hr_fiscalyear.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

class TestHrFiscalyear(common.TransactionCase):
def setUp(self):
super(TestHrFiscalyear, self).setUp()
super().setUp()
self.user_model = self.env["res.users"]
self.company_model = self.env["res.company"]
self.payslip_model = self.env["hr.payslip"]
Expand Down
2 changes: 1 addition & 1 deletion hr_payroll_period/tests/test_payslip.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class PayslipCase(test_hr_fiscalyear.TestHrFiscalyear):
def setUp(self):
result = super(PayslipCase, self).setUp()
result = super().setUp()
self.payslip_obj = self.env["hr.payslip"]
self.run_obj = self.env["hr.payslip.run"]
self.wzd_obj = self.env["hr.payslip.employees"]
Expand Down
36 changes: 19 additions & 17 deletions hr_payroll_period/views/hr_fiscalyear_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@
string="Create Periods"
type="object"
class="btn-primary"
states="draft"
invisible="state != 'draft'"
/>
<button
name="button_set_to_draft"
string="Set To Draft"
type="object"
states="open"
invisible="state != 'open'"
/>
<button
name="button_confirm"
string="Confirm"
type="object"
class="btn-primary"
states="draft"
invisible="state != 'open'"
/>
<field name="state" widget="statusbar" nolabel="1" />
</header>
Expand All @@ -38,7 +38,7 @@
</div>
<group>
<group>
<field name="schedule_pay" />
<field name="schedule_pay" readonly="state != 'draft'" />
<label for="date_start" string="Period" />
<div>
<field
Expand Down Expand Up @@ -69,29 +69,31 @@
<group>
<field
name="payment_day"
attrs="{
'invisible': [('schedule_pay', 'in', ['weekly', 'bi-weekly'])],
'required': [('schedule_pay', 'not in', ['weekly', 'bi-weekly'])],
}"
invisible="schedule_pay in ['weekly', 'bi-weekly']"
required="schedule_pay not in ['weekly', 'bi-weekly']"
readonly="state != 'draft'"
/>
<newline />
<field
name="payment_weekday"
attrs="{
'invisible': [('schedule_pay', 'not in', ['weekly', 'bi-weekly'])],
'required': [('schedule_pay', 'in', ['weekly', 'bi-weekly'])],
}"
invisible="schedule_pay not in ['weekly', 'bi-weekly']"
required="schedule_pay in ['weekly', 'bi-weekly']"
readonly="state != 'draft'"
/>
<field
name="payment_week"
attrs="{
'invisible': [('schedule_pay', 'not in', ['weekly', 'bi-weekly'])],
'required': [('schedule_pay', 'in', ['weekly', 'bi-weekly'])],
}"
invisible="schedule_pay not in ['weekly', 'bi-weekly']"
required="schedule_pay in ['weekly', 'bi-weekly']"
readonly="state != 'draft'"
/>
</group>
</group>
<field colspan="4" name="period_ids" nolabel="1" />
<field
colspan="4"
name="period_ids"
nolabel="1"
readonly="state != 'draft'"
/>
</sheet>
</form>
</field>
Expand Down
64 changes: 17 additions & 47 deletions hr_payroll_period/views/hr_payslip_run_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,17 @@
<field name="inherit_id" ref="payroll.hr_payslip_run_view_form" />
<field name="priority">100</field>
<field name="arch" type="xml">
<field name="struct_id" position="before">
<field
name="company_id"
groups="base.group_multi_company"
required="1"
/>
<field
name="company_id"
groups="!base.group_multi_company"
required="1"
invisible="1"
/>
</field>
<label for="date_start" position="before">
<field
name="hr_period_id"
domain="[
('state', '=', 'open'),
('company_id', '=', company_i)
]"
groups="!base.group_multi_company"
/>
<field
name="hr_period_id"
domain="[
('state', '=', 'open'),
('company_id', '=', company_id)
]"
groups="base.group_multi_company"
reaonly="state == 'close'"
/>
<field name="schedule_pay" />
<field name="date_payment" required="1" />
<field name="schedule_pay" readonly="state == 'close'" />
<field name="date_payment" required="1" readonly="state == 'close'" />
</label>
<button
name="%(payroll.action_hr_payslip_by_employees)d"
Expand All @@ -46,7 +26,7 @@
<button
name="get_payslip_employees_wizard"
type="object"
states="draft"
invisible="state != 'draft'"
string="Generate Payslips"
class="btn-primary"
/>
Expand All @@ -60,30 +40,21 @@
<field name="inherit_id" ref="payroll.hr_payslip_run_view_search" />
<field name="arch" type="xml">
<field name="name" position="after">
<field name="company_id" />
<field name="date_payment" />
<field name="schedule_pay" />
</field>
<search position="inside">
<group string="Group By...">
<filter
string="Company"
name="company_id"
groups="base.group_multi_company"
context="{'group_by':'company_id'}"
/>
<filter
string="Scheduled Pay"
name="schedule_pay"
context="{'group_by':'schedule_pay'}"
/>
<filter
string="Payment Date"
name="date_payment"
context="{'group_by':'date_payment'}"
/>
</group>
</search>
<group name="group_by" position="inside">
<filter
string="Scheduled Pay"
name="schedule_pay"
context="{'group_by':'schedule_pay'}"
/>
<filter
string="Payment Date"
name="date_payment"
context="{'group_by':'date_payment'}"
/>
</group>
</field>
</record>
<!-- Tree -->
Expand All @@ -95,7 +66,6 @@
<field name="date_end" position="after">
<field name="date_payment" />
<field name="schedule_pay" />
<field name="company_id" groups="base.group_multi_company" />
</field>
</field>
</record>
Expand Down
Loading

0 comments on commit a2df588

Please sign in to comment.