[IMP] PoC is operationnal

This commit is contained in:
Benjamin Lechalupe 2019-06-12 19:50:21 +02:00
parent cdf8a42dd1
commit 23df800a39
5 changed files with 45 additions and 22 deletions

View File

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

View File

@ -6,7 +6,7 @@ class ProjectProject(models.Model):
@api.multi @api.multi
def open_timesheets_matrix(self): 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 { return {
'name': 'Edit timesheets', 'name': 'Edit timesheets',
'type': 'ir.actions.act_window', 'type': 'ir.actions.act_window',

View File

@ -3,10 +3,14 @@
<record id="project_timesheet_matrix_view_form" model="ir.ui.view"> <record id="project_timesheet_matrix_view_form" model="ir.ui.view">
<field name="name">project.timesheet.matrix.view.form</field> <field name="name">project.timesheet.matrix.view.form</field>
<field name="model">project.project</field> <field name="model">project.project</field>
<field name="inherit_id" ref="project.view_project_kanban"/> <field name="inherit_id" ref="hr_timesheet.view_project_kanban_inherited"/>
<field name="arch" type="xml"> <field name="arch" type="xml">
<xpath expr="//a[hasclass('o_project_kanban_box')]" position="after"> <xpath expr="//a[@groups='hr_timesheet.group_hr_timesheet_user']" position="replace">
<a class="o_project_kanban_box" name="open_timesheets_matrix" type="object">Timesheets</a> <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> </xpath>
</field> </field>
</record> </record>

View File

@ -1,23 +1,42 @@
import datetime
from odoo import fields, models from odoo import fields, models
class ProjectTimesheetMatrixWizard(models.TransientModel): class ProjectTimesheetMatrixWizard(models.TransientModel):
_name = 'project.timesheet.matrix.wiz' _name = 'project.timesheet.matrix.wiz'
def _default_line_ids(self): def _default_line_ids(self):
recs = self.env['account.analytic.account'].search([]) project = self.env["project.project"].browse(self.env.context.get("project_id"))
users = self.env['account.analytic.line'].search([]).mapped('user_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 [ dates.sort()
(0, 0, {
'name': "{}'s task on {}".format(usr.name, rec.name), orm_date_min = fields.Date.to_string(min(dates))
'account_id': rec.id, orm_date_max = fields.Date.to_string(max(dates))
'user_id': usr.id,
'unit_amount': 0, analytic_lines = self.env["account.analytic.line"].search([
}) ("date", ">=", orm_date_min),
if not rec.line_ids.filtered(lambda x:x.user_id == usr) else ("date", "<=", orm_date_max),
(4, rec.line_ids.filtered(lambda x:x.user_id == usr)[0].id) ("user_id", "in", users.ids),
for rec in recs ])
for usr in users
] 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) line_ids = fields.Many2many('account.analytic.line', default=_default_line_ids)

View File

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