Compare commits
4 Commits
596a39b83a
...
23df800a39
Author | SHA1 | Date | |
---|---|---|---|
23df800a39 | |||
cdf8a42dd1 | |||
e2b3bf6fd7 | |||
da3086d6fd |
@ -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',
|
||||
|
@ -4,10 +4,9 @@ from odoo import models, fields, api
|
||||
class ProjectProject(models.Model):
|
||||
_inherit = "project.project"
|
||||
|
||||
@api.model
|
||||
@api.multi
|
||||
def open_timesheets_matrix(self):
|
||||
import pdb; pdb.set_trace()
|
||||
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',
|
||||
|
@ -3,17 +3,15 @@
|
||||
<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="project.view_project_kanban"/>
|
||||
<field name="inherit_id" ref="hr_timesheet.view_project_kanban_inherited"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//div[hasclass('o_kanban_card_manage_section')]" position="inside">
|
||||
<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>
|
||||
<!-- <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" />
|
||||
<span class="o_label">Timesheets</span>
|
||||
</div>
|
||||
</a>
|
||||
</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>
|
@ -1,24 +1,42 @@
|
||||
import datetime
|
||||
|
||||
from odoo import fields, models
|
||||
|
||||
class ProjectTimesheetMatrixWizard(models.TransientModel):
|
||||
_name = 'project.timesheet.matrix.wiz'
|
||||
|
||||
def _default_line_ids(self):
|
||||
import pdb; pdb.set_trace()
|
||||
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)
|
@ -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="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>
|
||||
<field name="account_id"/>
|
||||
<field name="date" widget="date"/>
|
||||
<field name="user_id"/>
|
||||
<field name="unit_amount"/>
|
||||
<field name="unit_amount" widget="float_time"/>
|
||||
</tree>
|
||||
</field>
|
||||
</form>
|
||||
|
Loading…
Reference in New Issue
Block a user