diff --git a/project_timesheet_matrix/__manifest__.py b/project_timesheet_matrix/__manifest__.py
index a492bbd..178e755 100644
--- a/project_timesheet_matrix/__manifest__.py
+++ b/project_timesheet_matrix/__manifest__.py
@@ -7,7 +7,7 @@
"license": "AGPL-3",
"category": "Project",
"depends": [
- 'web_widget_x2many_2d_matrix', 'project', 'analytic'
+ 'web_widget_x2many_2d_matrix', 'project', 'hr_timesheet', 'analytic'
],
"data": [
# 'security/ir.model.access.csv',
diff --git a/project_timesheet_matrix/models/project_project.py b/project_timesheet_matrix/models/project_project.py
index e59e97f..cd08533 100644
--- a/project_timesheet_matrix/models/project_project.py
+++ b/project_timesheet_matrix/models/project_project.py
@@ -6,7 +6,7 @@ class ProjectProject(models.Model):
@api.multi
def open_timesheets_matrix(self):
- wiz = self.env['project.timesheet.matrix.wiz'].create({})
+ wiz = self.env['project.timesheet.matrix.wiz'].with_context(project_id=self.id).create({})
return {
'name': 'Edit timesheets',
'type': 'ir.actions.act_window',
diff --git a/project_timesheet_matrix/views/project_timesheet_matrix_view.xml b/project_timesheet_matrix/views/project_timesheet_matrix_view.xml
index a70816d..1e5cda1 100644
--- a/project_timesheet_matrix/views/project_timesheet_matrix_view.xml
+++ b/project_timesheet_matrix/views/project_timesheet_matrix_view.xml
@@ -3,10 +3,14 @@
project.timesheet.matrix.view.form
project.project
-
+
-
- Timesheets
+
+
+
+ Timesheets
+
+
diff --git a/project_timesheet_matrix/wizard/project_timesheet_matrix_wiz.py b/project_timesheet_matrix/wizard/project_timesheet_matrix_wiz.py
index a59ea55..f736221 100644
--- a/project_timesheet_matrix/wizard/project_timesheet_matrix_wiz.py
+++ b/project_timesheet_matrix/wizard/project_timesheet_matrix_wiz.py
@@ -1,23 +1,42 @@
+import datetime
+
from odoo import fields, models
class ProjectTimesheetMatrixWizard(models.TransientModel):
_name = 'project.timesheet.matrix.wiz'
def _default_line_ids(self):
- recs = self.env['account.analytic.account'].search([])
- users = self.env['account.analytic.line'].search([]).mapped('user_id')
+ project = self.env["project.project"].browse(self.env.context.get("project_id"))
+ dates = [datetime.date.today() - datetime.timedelta(days=delta) for delta in range(0, 8)]
+ users = self.env["res.users"].search([("partner_id", "in", project.message_partner_ids.ids)])
- return [
- (0, 0, {
- 'name': "{}'s task on {}".format(usr.name, rec.name),
- 'account_id': rec.id,
- 'user_id': usr.id,
- 'unit_amount': 0,
- })
- if not rec.line_ids.filtered(lambda x:x.user_id == usr) else
- (4, rec.line_ids.filtered(lambda x:x.user_id == usr)[0].id)
- for rec in recs
- for usr in users
- ]
+ dates.sort()
+
+ orm_date_min = fields.Date.to_string(min(dates))
+ orm_date_max = fields.Date.to_string(max(dates))
+
+ analytic_lines = self.env["account.analytic.line"].search([
+ ("date", ">=", orm_date_min),
+ ("date", "<=", orm_date_max),
+ ("user_id", "in", users.ids),
+ ])
+
+ data = []
+
+ for date in dates:
+ for user in users.sorted("name"):
+ filtered_analytic_lines = analytic_lines.filtered(lambda line: line.user_id == user and line.date == fields.Date.to_string(date))
+ if filtered_analytic_lines:
+ data += [(4, line_id) for line_id in filtered_analytic_lines.ids]
+ else:
+ data.append((0, 0, {
+ "date": fields.Date.to_string(date),
+ "project_id": project.id,
+ "user_id": user.id,
+ "name": "Timesheet from Matrix",
+ "unit_amount": 0.0,
+ }))
+
+ return data
line_ids = fields.Many2many('account.analytic.line', default=_default_line_ids)
\ No newline at end of file
diff --git a/project_timesheet_matrix/wizard/project_timesheet_matrix_wiz.xml b/project_timesheet_matrix/wizard/project_timesheet_matrix_wiz.xml
index 579f99c..70a0722 100644
--- a/project_timesheet_matrix/wizard/project_timesheet_matrix_wiz.xml
+++ b/project_timesheet_matrix/wizard/project_timesheet_matrix_wiz.xml
@@ -7,11 +7,11 @@
form