Skip to content

Commit

Permalink
[MIG] hr_timesheet_sheet: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Vijaiy-Selvaraj committed Oct 18, 2024
1 parent 8982ac9 commit 62855c4
Show file tree
Hide file tree
Showing 14 changed files with 123 additions and 192 deletions.
4 changes: 4 additions & 0 deletions hr_timesheet_sheet/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ Contributors

- Dennis Sluijk <[email protected]>
- Sunanda Chhatbar <[email protected]>
- `Sodexis <https://www.sodexis.com>`__

- SodexisTeam <[email protected]>
- Sowrirajan <[email protected]>

Maintainers
-----------
Expand Down
2 changes: 1 addition & 1 deletion hr_timesheet_sheet/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

{
"name": "HR Timesheet Sheet",
"version": "16.0.1.1.4",
"version": "17.0.1.0.0",
"category": "Human Resources",
"sequence": 80,
"summary": "Timesheet Sheets, Activities",
Expand Down
8 changes: 4 additions & 4 deletions hr_timesheet_sheet/models/account_analytic_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ class AccountAnalyticAccount(models.Model):
def _check_timesheet_sheet_company_id(self):
for rec in self.sudo():
sheets = rec.line_ids.mapped("sheet_id").filtered(
lambda s: s.company_id and s.company_id != rec.company_id
lambda s, rec=rec: s.company_id and s.company_id != rec.company_id
)
if sheets:
raise ValidationError(
_(
"You cannot change the company, "
"as this %(rec_name)s (%(rec_display_name)s) "
"is assigned to %(current_name)s (%(current_display_name)s).",
"You cannot change the company, as this "
"%(rec_name)s (%(rec_display_name)s) is assigned "
"to %(current_name)s (%(current_display_name)s).",
rec_name=rec._name,
rec_display_name=rec.display_name,
current_name=sheets[0]._name,
Expand Down
4 changes: 2 additions & 2 deletions hr_timesheet_sheet/models/account_analytic_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,5 +135,5 @@ def merge_timesheets(self):
self[1:].unlink()
return self[0]

def _check_can_update_timesheet(self):
return super()._check_can_update_timesheet() or not self.filtered("sheet_id")
def _check_can_write(self, values):
return super()._check_can_write(values) or not self.filtered("sheet_id")
6 changes: 3 additions & 3 deletions hr_timesheet_sheet/models/hr_department.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ def _check_company_id(self):
):
raise ValidationError(
_(
"You cannot change the company, "
"as this %(rec_name)s (%(rec_display_name)s) "
"is assigned to %(current_name)s (%(current_display_name)s).",
"You cannot change the company, as this"
" %(rec_name)s (%(rec_display_name)s) is assigned"
" to %(current_name)s (%(current_display_name)s).",
rec_name=rec._name,
rec_display_name=rec.display_name,
current_name=field._name,
Expand Down
6 changes: 3 additions & 3 deletions hr_timesheet_sheet/models/hr_employee.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ def _check_company_id(self):
):
raise ValidationError(
_(
"You cannot change the company, "
"as this %(rec_name)s (%(rec_display_name)s) "
"is assigned to %(current_name)s (%(current_display_name)s).",
"You cannot change the company, as this"
" %(rec_name)s (%(rec_display_name)s) is assigned"
" to %(current_name)s (%(current_display_name)s).",
rec_name=rec._name,
rec_display_name=rec.display_name,
current_name=field._name,
Expand Down
49 changes: 17 additions & 32 deletions hr_timesheet_sheet/models/hr_timesheet_sheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,52 +62,39 @@ def _default_department_id(self):
string="Employee",
default=lambda self: self._default_employee(),
required=True,
readonly=True,
states={"new": [("readonly", False)]},
)
user_id = fields.Many2one(
comodel_name="res.users",
related="employee_id.user_id",
string="User",
store=True,
readonly=True,
)
date_start = fields.Date(
string="Date From",
default=lambda self: self._default_date_start(),
required=True,
index=True,
readonly=True,
states={"new": [("readonly", False)]},
)
date_end = fields.Date(
string="Date To",
default=lambda self: self._default_date_end(),
required=True,
index=True,
readonly=True,
states={"new": [("readonly", False)]},
)
timesheet_ids = fields.One2many(
comodel_name="account.analytic.line",
inverse_name="sheet_id",
string="Timesheets",
readonly=True,
states={"new": [("readonly", False)], "draft": [("readonly", False)]},
)
line_ids = fields.One2many(
comodel_name="hr_timesheet.sheet.line",
compute="_compute_line_ids",
string="Timesheet Sheet Lines",
readonly=True,
states={"new": [("readonly", False)], "draft": [("readonly", False)]},
)
new_line_ids = fields.One2many(
comodel_name="hr_timesheet.sheet.new.analytic.line",
inverse_name="sheet_id",
string="Temporary Timesheets",
readonly=True,
states={"new": [("readonly", False)], "draft": [("readonly", False)]},
)
state = fields.Selection(
[
Expand All @@ -120,31 +107,26 @@ def _default_department_id(self):
tracking=True,
string="Status",
required=True,
readonly=True,
index=True,
)
company_id = fields.Many2one(
comodel_name="res.company",
string="Company",
default=lambda self: self.env.company,
required=True,
readonly=True,
)
review_policy = fields.Selection(
selection=lambda self: self._selection_review_policy(),
default=lambda self: self._default_review_policy(),
required=True,
readonly=True,
)
department_id = fields.Many2one(
comodel_name="hr.department",
string="Department",
default=lambda self: self._default_department_id(),
readonly=True,
states={"new": [("readonly", False)]},
)
reviewer_id = fields.Many2one(
comodel_name="hr.employee", string="Reviewer", readonly=True, tracking=True
comodel_name="hr.employee", string="Reviewer", tracking=True
)
add_line_project_id = fields.Many2one(
comodel_name="project.project",
Expand Down Expand Up @@ -175,6 +157,8 @@ def _default_department_id(self):
def _compute_name(self):
locale = self.env.context.get("lang") or self.env.user.lang or "en_US"
for sheet in self:
if not sheet.date_start or not sheet.date_end:
raise UserError(_("Please enter start and end date"))
if sheet.date_start == sheet.date_end:
sheet.name = babel.dates.format_skeleton(
skeleton="MMMEd",
Expand Down Expand Up @@ -244,7 +228,7 @@ def _check_start_end_dates(self):
def _get_complete_name_components(self):
"""Hook for extensions"""
self.ensure_one()
return [self.employee_id.name_get()[0][1]]
return [self.employee_id.display_name]

def _get_overlapping_sheet_domain(self):
"""Hook for extensions"""
Expand Down Expand Up @@ -357,7 +341,7 @@ def _get_timesheet_sheet_company(self):
@api.onchange("employee_id")
def _onchange_employee_id(self):
if self.employee_id:
company = self._get_timesheet_sheet_company()
company = self.sudo()._get_timesheet_sheet_company()
self.company_id = company
self.review_policy = company.timesheet_sheet_review_policy
self.department_id = self.employee_id.department_id
Expand Down Expand Up @@ -407,8 +391,8 @@ def _get_matrix_sortby(self, key):
res = []
for attribute in key:
if hasattr(attribute, "name_get"):
name = attribute.name_get()
value = name[0][1] if name else ""
name = attribute.display_name
value = name if name else ""
else:
value = attribute
res.append(value)
Expand Down Expand Up @@ -445,8 +429,9 @@ def _onchange_scope(self):

@api.onchange("date_start", "date_end")
def _onchange_dates(self):
if self.date_start > self.date_end:
self.date_end = self.date_start
if self.date_start and self.date_end:
if self.date_start > self.date_end:
self.date_end = self.date_start

@api.onchange("timesheet_ids")
def _onchange_timesheets(self):
Expand Down Expand Up @@ -516,9 +501,9 @@ def unlink(self):
raise UserError(
_(
"You cannot delete a timesheet sheet which is already"
" submitted or confirmed: %s"
" submitted or confirmed: %s",
sheet.complete_name,
)
% (sheet.complete_name,)
)
return super().unlink()

Expand Down Expand Up @@ -623,9 +608,9 @@ def _get_dates(self):
def _get_line_name(self, project_id, task_id=None, **kwargs):
self.ensure_one()
if task_id:
return f"{project_id.name_get()[0][1]} - {task_id.name_get()[0][1]}"
return f"{project_id.display_name} - {task_id.display_name}"

return project_id.name_get()[0][1]
return project_id.display_name

def _get_new_line_unique_id(self):
"""Hook for extensions"""
Expand Down Expand Up @@ -710,7 +695,7 @@ def _is_line_of_row(self, aal, row):
def delete_empty_lines(self, delete_empty_rows=False):
self.ensure_one()
for name in list(set(self.line_ids.mapped("value_y"))):
rows = self.line_ids.filtered(lambda l: l.value_y == name)
rows = self.line_ids.filtered(lambda line, name=name: line.value_y == name)
if not rows:
continue
row = fields.first(rows)
Expand All @@ -721,7 +706,7 @@ def delete_empty_lines(self, delete_empty_rows=False):
if not check:
continue
row_lines = self.timesheet_ids.filtered(
lambda aal: self._is_line_of_row(aal, row)
lambda aal, row=row: self._is_line_of_row(aal, row)
)
row_lines.filtered(
lambda t: t.name == empty_name
Expand Down Expand Up @@ -775,7 +760,7 @@ def add_new_line(self, line):
self.ensure_one()
new_line_model = self.env["hr_timesheet.sheet.new.analytic.line"]
new_line = self.new_line_ids.filtered(
lambda l: self._is_compatible_new_line(l, line)
lambda lin: self._is_compatible_new_line(lin, line)
)
if new_line:
new_line.write({"unit_amount": line.unit_amount})
Expand Down
3 changes: 3 additions & 0 deletions hr_timesheet_sheet/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@
- Alexey Pelykh \<<[email protected]>\>
- Dennis Sluijk \<<[email protected]>\>
- Sunanda Chhatbar \<<[email protected]>\>
- [Sodexis](https://www.sodexis.com)
- SodexisTeam \<<[email protected]>\>
- Sowrirajan \<<[email protected]>\>
5 changes: 5 additions & 0 deletions hr_timesheet_sheet/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,11 @@ <h2><a class="toc-backref" href="#toc-entry-8">Contributors</a></h2>
</li>
<li>Dennis Sluijk &lt;<a class="reference external" href="mailto:d.sluijk&#64;onestein.nl">d.sluijk&#64;onestein.nl</a>&gt;</li>
<li>Sunanda Chhatbar &lt;<a class="reference external" href="mailto:sunanda.chhatbar&#64;initos.com">sunanda.chhatbar&#64;initos.com</a>&gt;</li>
<li><a class="reference external" href="https://www.sodexis.com">Sodexis</a><ul>
<li>SodexisTeam &lt;<a class="reference external" href="mailto:dev&#64;sodexis.com">dev&#64;sodexis.com</a>&gt;</li>
<li>Sowrirajan &lt;<a class="reference external" href="mailto:sowrirajan&#64;sodexis.com">sowrirajan&#64;sodexis.com</a>&gt;</li>
</ul>
</li>
</ul>
</div>
<div class="section" id="maintainers">
Expand Down
30 changes: 12 additions & 18 deletions hr_timesheet_sheet/tests/test_hr_timesheet_sheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ def test_2(self):
line_form.unit_amount = 1.0
self.assertEqual(len(sheet.new_line_ids), 1)
line2 = fields.first(
sheet.line_ids.filtered(lambda l: l.date != timesheet.date)
sheet.line_ids.filtered(lambda line: line.date != timesheet.date)
)
self.assertEqual(line2.unit_amount, 1.0)
self.assertEqual(len(sheet.timesheet_ids), 2)
Expand Down Expand Up @@ -475,7 +475,7 @@ def test_4(self):
self.assertEqual(timesheet_1_or_2.unit_amount, 1.0)
self.assertEqual(timesheet_3.unit_amount, 0.0)

line = sheet.line_ids.filtered(lambda l: l.unit_amount != 0.0)
line = sheet.line_ids.filtered(lambda line: line.unit_amount != 0.0)
self.assertEqual(len(line), 1)
self.assertEqual(line.unit_amount, 1.0)

Expand Down Expand Up @@ -528,7 +528,7 @@ def test_5(self):
pass # trigger edit and save
self.assertEqual(len(sheet.line_ids), 7)
self.assertEqual(len(sheet.timesheet_ids), 2)
line = sheet.line_ids.filtered(lambda l: l.unit_amount != 0.0)
line = sheet.line_ids.filtered(lambda line: line.unit_amount != 0.0)
self.assertEqual(line.unit_amount, 4.0)

timesheet_2.name = empty_name
Expand Down Expand Up @@ -624,7 +624,7 @@ def test_6(self):
pass # trigger edit and save
self.assertEqual(len(sheet.line_ids), 7)
self.assertEqual(len(sheet.timesheet_ids), 5)
line = sheet.line_ids.filtered(lambda l: l.unit_amount != 0.0)
line = sheet.line_ids.filtered(lambda line: line.unit_amount != 0.0)
self.assertEqual(line.unit_amount, 10.0)

timesheet_2.name = empty_name
Expand Down Expand Up @@ -654,7 +654,7 @@ def test_6(self):
line_form.unit_amount = 3.0
self.assertEqual(len(sheet.new_line_ids), 1)
self.assertEqual(len(sheet.timesheet_ids), 4)
line = sheet.line_ids.filtered(lambda l: l.unit_amount != 0.0)
line = sheet.line_ids.filtered(lambda line: line.unit_amount != 0.0)
self.assertEqual(line.unit_amount, 3.0)

timesheet_3_4_and_5 = self.aal_model.search(
Expand All @@ -678,7 +678,7 @@ def test_6(self):
with Form(sheet.with_user(self.user)):
pass # trigger edit and save
self.assertEqual(len(sheet.timesheet_ids), 4)
line = sheet.line_ids.filtered(lambda l: l.unit_amount != 0.0)
line = sheet.line_ids.filtered(lambda line: line.unit_amount != 0.0)
self.assertEqual(len(line), 1)
self.assertEqual(line.unit_amount, 5.0)

Expand Down Expand Up @@ -715,13 +715,6 @@ def test_no_overlap(self):

def test_8(self):
"""Multicompany test"""
employee_2 = self.employee_model.create(
{
"name": "Test User 2",
"user_id": self.user_2.id,
"company_id": self.user_2.company_id.id,
}
)
department_2 = self.department_model.create(
{"name": "Department test 2", "company_id": self.user_2.company_id.id}
)
Expand All @@ -740,8 +733,6 @@ def test_8(self):
with Form(sheet.with_user(self.user)) as sheet_form:
with self.assertRaises(AssertionError):
sheet_form.company_id = self.user_2.company_id.id
with self.assertRaises(AssertionError):
sheet_form.employee_id = employee_2
with self.assertRaises(AssertionError):
sheet_form.department_id = department_2
sheet_form.add_line_project_id = project_3
Expand Down Expand Up @@ -868,7 +859,7 @@ def test_12_creating_sheet(self):
self.assertEqual(len(sheet.timesheet_ids), 1)
self.assertEqual(len(sheet.line_ids), 7)

line = sheet.line_ids.filtered(lambda l: l.unit_amount)
line = sheet.line_ids.filtered(lambda line: line.unit_amount)
self.assertEqual(len(line), 1)
self.assertEqual(line.unit_amount, 2.0)

Expand Down Expand Up @@ -1019,14 +1010,17 @@ def test_sheet_range_daily(self):

def test_employee_no_user(self):
sheet_form = Form(self.sheet_model.with_user(self.user))
# testing create
with self.assertRaises(UserError):
sheet_form.employee_id = self.employee_no_user
sheet_form.save()

# testing write
sheet = Form(self.sheet_model.with_user(self.user)).save()
with Form(sheet.with_user(self.user)) as sheet_form:
with self.assertRaises(AssertionError):
with self.assertRaises(UserError):
with Form(sheet.with_user(self.user)) as sheet_form:
sheet_form.employee_id = self.employee_no_user
sheet_form.save()

def test_workflow(self):
sheet = Form(self.sheet_model.with_user(self.user)).save()
Expand Down
5 changes: 1 addition & 4 deletions hr_timesheet_sheet/views/account_analytic_line_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@
<field name="inherit_id" ref="hr_timesheet.hr_timesheet_line_form" />
<field name="arch" type="xml">
<field name="date" position="after">
<field
name="sheet_id"
attrs="{'invisible': [('sheet_id', '=', False)]}"
/>
<field name="sheet_id" invisible="not sheet_id" />
</field>
</field>
</record>
Expand Down
Loading

1 comment on commit 62855c4

@valentinthirion
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, there is an issue for this here: #720

Please sign in to comment.