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", "license": "AGPL-3",
"category": "Project", "category": "Project",
"depends": [ "depends": [
'web_widget_x2many_2d_matrix', 'project', 'hr_timesheet', 'analytic' 'web_widget_x2many_2d_matrix', 'project', 'analytic'
], ],
"data": [ "data": [
# 'security/ir.model.access.csv', # 'security/ir.model.access.csv',

View File

@ -4,9 +4,10 @@ from odoo import models, fields, api
class ProjectProject(models.Model): class ProjectProject(models.Model):
_inherit = "project.project" _inherit = "project.project"
@api.multi @api.model
def open_timesheets_matrix(self): 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 { return {
'name': 'Edit timesheets', 'name': 'Edit timesheets',
'type': 'ir.actions.act_window', 'type': 'ir.actions.act_window',

View File

@ -3,15 +3,17 @@
<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="hr_timesheet.view_project_kanban_inherited"/> <field name="inherit_id" ref="project.view_project_kanban"/>
<field name="arch" type="xml"> <field name="arch" type="xml">
<xpath expr="//a[@groups='hr_timesheet.group_hr_timesheet_user']" position="replace"> <xpath expr="//div[hasclass('o_kanban_card_manage_section')]" position="inside">
<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> <div>
<span class="o_label">Timesheets</span> <!-- <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> </div>
</a>
</xpath> </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> </field>
</record> </record>
</odoo> </odoo>

View File

@ -1,42 +1,24 @@
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):
project = self.env["project.project"].browse(self.env.context.get("project_id")) import pdb; pdb.set_trace()
dates = [datetime.date.today() - datetime.timedelta(days=delta) for delta in range(0, 8)] recs = self.env['account.analytic.account'].search([])
users = self.env["res.users"].search([("partner_id", "in", project.message_partner_ids.ids)]) users = self.env['account.analytic.line'].search([]).mapped('user_id')
dates.sort() return [
(0, 0, {
orm_date_min = fields.Date.to_string(min(dates)) 'name': "{}'s task on {}".format(usr.name, rec.name),
orm_date_max = fields.Date.to_string(max(dates)) 'account_id': rec.id,
'user_id': usr.id,
analytic_lines = self.env["account.analytic.line"].search([ 'unit_amount': 0,
("date", ">=", orm_date_min), })
("date", "<=", orm_date_max), if not rec.line_ids.filtered(lambda x:x.user_id == usr) else
("user_id", "in", users.ids), (4, rec.line_ids.filtered(lambda x:x.user_id == usr)[0].id)
]) 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="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> <tree>
<field name="date" widget="date"/> <field name="account_id"/>
<field name="user_id"/> <field name="user_id"/>
<field name="unit_amount" widget="float_time"/> <field name="unit_amount"/>
</tree> </tree>
</field> </field>
</form> </form>