Skip to content

Commit 3fe49e0

Browse files
[MIG] hr_timesheet_sheet: Move sheet.line TransientModels to wizards folder
1 parent 634a4ee commit 3fe49e0

4 files changed

Lines changed: 103 additions & 96 deletions

File tree

hr_timesheet_sheet/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22

33
from . import models
44
from . import report
5+
from . import wizards

hr_timesheet_sheet/models/hr_timesheet_sheet.py

Lines changed: 0 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
# Copyright 2018-2019 Onestein (<https://www.onestein.eu>)
44
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
55

6-
import logging
76
import re
87
from collections import namedtuple
98
from datetime import datetime, time
@@ -16,8 +15,6 @@
1615
from odoo.exceptions import UserError, ValidationError
1716
from odoo.fields import Domain
1817

19-
_logger = logging.getLogger(__name__)
20-
2118
empty_name = "/"
2219

2320

@@ -841,96 +838,3 @@ def _track_subtype(self, init_values):
841838
elif "state" in init_values and record.state == "done":
842839
return self.env.ref("hr_timesheet_sheet.mt_timesheet_approved")
843840
return super()._track_subtype(init_values)
844-
845-
846-
class AbstractSheetLine(models.AbstractModel):
847-
_name = "hr_timesheet.sheet.line.abstract"
848-
_description = "Abstract Timesheet Sheet Line"
849-
850-
sheet_id = fields.Many2one(comodel_name="hr_timesheet.sheet", ondelete="cascade")
851-
date = fields.Date()
852-
project_id = fields.Many2one(comodel_name="project.project", string="Project")
853-
task_id = fields.Many2one(comodel_name="project.task", string="Task")
854-
unit_amount = fields.Float(string="Quantity", default=0.0)
855-
company_id = fields.Many2one(comodel_name="res.company", string="Company")
856-
employee_id = fields.Many2one(comodel_name="hr.employee", string="Employee")
857-
858-
def get_unique_id(self):
859-
"""Hook for extensions"""
860-
self.ensure_one()
861-
return {"project_id": self.project_id, "task_id": self.task_id}
862-
863-
864-
class SheetLine(models.TransientModel):
865-
_name = "hr_timesheet.sheet.line"
866-
_inherit = "hr_timesheet.sheet.line.abstract"
867-
_description = "Timesheet Sheet Line"
868-
869-
value_x = fields.Char(string="Date Name")
870-
value_y = fields.Char(string="Project Name")
871-
new_line_id = fields.Integer(default=0)
872-
873-
@api.onchange("unit_amount")
874-
def onchange_unit_amount(self):
875-
"""This method is called when filling a cell of the matrix."""
876-
self.ensure_one()
877-
sheet = self._get_sheet()
878-
if not sheet:
879-
return {
880-
"warning": {
881-
"title": self.env._("Warning"),
882-
"message": self.env._("Save the Timesheet Sheet first."),
883-
}
884-
}
885-
sheet.add_new_line(self)
886-
887-
@api.model
888-
def _get_sheet(self):
889-
sheet = (self._origin or self).sheet_id
890-
if not sheet:
891-
model = self.env.context.get("params", {}).get("model", "")
892-
obj_id = self.env.context.get("params", {}).get("id")
893-
if model == "hr_timesheet.sheet" and isinstance(obj_id, int):
894-
sheet = self.env["hr_timesheet.sheet"].browse(obj_id)
895-
return sheet
896-
897-
898-
class SheetNewAnalyticLine(models.TransientModel):
899-
_name = "hr_timesheet.sheet.new.analytic.line"
900-
_inherit = "hr_timesheet.sheet.line.abstract"
901-
_description = "Timesheet Sheet New Analytic Line"
902-
903-
@api.model
904-
def _is_similar_analytic_line(self, aal):
905-
"""Hook for extensions"""
906-
return (
907-
aal.date == self.date
908-
and aal.project_id.id == self.project_id.id
909-
and aal.task_id.id == self.task_id.id
910-
)
911-
912-
@api.model
913-
def _update_analytic_lines(self):
914-
sheet = self.sheet_id
915-
timesheets = sheet.timesheet_ids.filtered(
916-
lambda aal: self._is_similar_analytic_line(aal)
917-
)
918-
new_ts = timesheets.filtered(lambda t: t.name == empty_name)
919-
amount = sum(t.unit_amount for t in timesheets)
920-
diff_amount = self.unit_amount - amount
921-
if len(new_ts) > 1:
922-
new_ts = new_ts.merge_timesheets()
923-
sheet._sheet_write("timesheet_ids", sheet.timesheet_ids.exists())
924-
if not diff_amount:
925-
return
926-
if new_ts:
927-
unit_amount = new_ts.unit_amount + diff_amount
928-
if unit_amount:
929-
new_ts.write({"unit_amount": unit_amount})
930-
else:
931-
new_ts.unlink()
932-
sheet._sheet_write("timesheet_ids", sheet.timesheet_ids.exists())
933-
else:
934-
new_ts_values = sheet._prepare_new_line(self)
935-
new_ts_values.update({"name": empty_name, "unit_amount": diff_amount})
936-
self.env["account.analytic.line"]._sheet_create(new_ts_values)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import hr_timesheet_sheet_lines
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# Copyright 2018-2020 ForgeFlow, S.L.
2+
# Copyright 2018-2020 Brainbean Apps (https://brainbeanapps.com)
3+
# Copyright 2018-2019 Onestein (<https://www.onestein.eu>)
4+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
5+
6+
from odoo import api, fields, models
7+
8+
empty_name = "/"
9+
10+
11+
class AbstractSheetLine(models.AbstractModel):
12+
_name = "hr_timesheet.sheet.line.abstract"
13+
_description = "Abstract Timesheet Sheet Line"
14+
15+
sheet_id = fields.Many2one(comodel_name="hr_timesheet.sheet", ondelete="cascade")
16+
date = fields.Date()
17+
project_id = fields.Many2one(comodel_name="project.project", string="Project")
18+
task_id = fields.Many2one(comodel_name="project.task", string="Task")
19+
unit_amount = fields.Float(string="Quantity", default=0.0)
20+
company_id = fields.Many2one(comodel_name="res.company", string="Company")
21+
employee_id = fields.Many2one(comodel_name="hr.employee", string="Employee")
22+
23+
def get_unique_id(self):
24+
"""Hook for extensions"""
25+
self.ensure_one()
26+
return {"project_id": self.project_id, "task_id": self.task_id}
27+
28+
29+
class SheetLine(models.TransientModel):
30+
_name = "hr_timesheet.sheet.line"
31+
_inherit = "hr_timesheet.sheet.line.abstract"
32+
_description = "Timesheet Sheet Line"
33+
34+
value_x = fields.Char(string="Date Name")
35+
value_y = fields.Char(string="Project Name")
36+
new_line_id = fields.Integer(default=0)
37+
38+
@api.onchange("unit_amount")
39+
def onchange_unit_amount(self):
40+
"""This method is called when filling a cell of the matrix."""
41+
self.ensure_one()
42+
sheet = self._get_sheet()
43+
if not sheet:
44+
return {
45+
"warning": {
46+
"title": self.env._("Warning"),
47+
"message": self.env._("Save the Timesheet Sheet first."),
48+
}
49+
}
50+
sheet.add_new_line(self)
51+
52+
@api.model
53+
def _get_sheet(self):
54+
sheet = (self._origin or self).sheet_id
55+
if not sheet:
56+
model = self.env.context.get("params", {}).get("model", "")
57+
obj_id = self.env.context.get("params", {}).get("id")
58+
if model == "hr_timesheet.sheet" and isinstance(obj_id, int):
59+
sheet = self.env["hr_timesheet.sheet"].browse(obj_id)
60+
return sheet
61+
62+
63+
class SheetNewAnalyticLine(models.TransientModel):
64+
_name = "hr_timesheet.sheet.new.analytic.line"
65+
_inherit = "hr_timesheet.sheet.line.abstract"
66+
_description = "Timesheet Sheet New Analytic Line"
67+
68+
@api.model
69+
def _is_similar_analytic_line(self, aal):
70+
"""Hook for extensions"""
71+
return (
72+
aal.date == self.date
73+
and aal.project_id.id == self.project_id.id
74+
and aal.task_id.id == self.task_id.id
75+
)
76+
77+
@api.model
78+
def _update_analytic_lines(self):
79+
sheet = self.sheet_id
80+
timesheets = sheet.timesheet_ids.filtered(
81+
lambda aal: self._is_similar_analytic_line(aal)
82+
)
83+
new_ts = timesheets.filtered(lambda t: t.name == empty_name)
84+
amount = sum(t.unit_amount for t in timesheets)
85+
diff_amount = self.unit_amount - amount
86+
if len(new_ts) > 1:
87+
new_ts = new_ts.merge_timesheets()
88+
sheet._sheet_write("timesheet_ids", sheet.timesheet_ids.exists())
89+
if not diff_amount:
90+
return
91+
if new_ts:
92+
unit_amount = new_ts.unit_amount + diff_amount
93+
if unit_amount:
94+
new_ts.write({"unit_amount": unit_amount})
95+
else:
96+
new_ts.unlink()
97+
sheet._sheet_write("timesheet_ids", sheet.timesheet_ids.exists())
98+
else:
99+
new_ts_values = sheet._prepare_new_line(self)
100+
new_ts_values.update({"name": empty_name, "unit_amount": diff_amount})
101+
self.env["account.analytic.line"]._sheet_create(new_ts_values)

0 commit comments

Comments
 (0)