Compare commits

..

No commits in common. "23df800a39ace38697d611b3f82fbaf43b5dfd34" and "596a39b83a5e3ba28d20ba02a34451653338d595" have entirely different histories.

5 changed files with 31 additions and 46 deletions

View File

@ -7,7 +7,7 @@
"license": "AGPL-3",
"category": "Project",
"depends": [
'web_widget_x2many_2d_matrix', 'project', 'hr_timesheet', 'analytic'
'web_widget_x2many_2d_matrix', 'project', 'analytic'
],
"data": [
# 'security/ir.model.access.csv',

View File

@ -4,9 +4,10 @@ from odoo import models, fields, api
class ProjectProject(models.Model):
_inherit = "project.project"
@api.multi
@api.model
def open_timesheets_matrix(self):
wiz = self.env['project.timesheet.matrix.wiz'].with_context(project_id=self.id).create({})
import pdb; pdb.set_trace()
wiz = self.env['project.timesheet.matrix.wiz'].create({})
return {
'name': 'Edit timesheets',
'type': 'ir.actions.act_window',

View File

@ -3,15 +3,17 @@
<record id="project_timesheet_matrix_view_form" model="ir.ui.view">
<field name="name">project.timesheet.matrix.view.form</field>
<field name="model">project.project</field>
<field name="inherit_id" ref="hr_timesheet.view_project_kanban_inherited"/>
<field name="inherit_id" ref="project.view_project_kanban"/>
<field name="arch" type="xml">
<xpath expr="//a[@groups='hr_timesheet.group_hr_timesheet_user']" position="replace">
<a t-if="record.allow_timesheets.raw_value" class="o_project_kanban_box" name="open_timesheets_matrix" type="object" groups="hr_timesheet.group_hr_timesheet_user">
<div>
<span class="o_label">Timesheets</span>
</div>
</a>
<xpath expr="//div[hasclass('o_kanban_card_manage_section')]" position="inside">
<div>
<!-- <a name="open_timesheets_matrix" type="object">Timesheet</a> -->
<button name="open_timesheets_matrix" type="object" string="Workers" class="oe_stat_button" icon="fa-edit" />
</div>
</xpath>
<!-- <field name="task_count" position="after">
<button name="open_project_timesheet_matrix" type="object" string="Timesheet Workers" class="oe_stat_button" icon="fa-edit" />
</field> -->
</field>
</record>
</odoo>

View File

@ -1,42 +1,24 @@
import datetime
from odoo import fields, models
class ProjectTimesheetMatrixWizard(models.TransientModel):
_name = 'project.timesheet.matrix.wiz'
def _default_line_ids(self):
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)])
import pdb; pdb.set_trace()
recs = self.env['account.analytic.account'].search([])
users = self.env['account.analytic.line'].search([]).mapped('user_id')
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
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
]
line_ids = fields.Many2many('account.analytic.line', default=_default_line_ids)

View File

@ -7,11 +7,11 @@
<field name="type">form</field>
<field name="arch" type="xml">
<form>
<field name="line_ids" widget="x2many_2d_matrix" field_x_axis="date" field_y_axis="user_id" field_value="unit_amount">
<field name="line_ids" widget="x2many_2d_matrix" field_x_axis="account_id" field_y_axis="user_id" field_value="unit_amount">
<tree>
<field name="date" widget="date"/>
<field name="account_id"/>
<field name="user_id"/>
<field name="unit_amount" widget="float_time"/>
<field name="unit_amount"/>
</tree>
</field>
</form>