Compare commits
4 Commits
596a39b83a
...
23df800a39
Author | SHA1 | Date | |
---|---|---|---|
23df800a39 | |||
cdf8a42dd1 | |||
e2b3bf6fd7 | |||
da3086d6fd |
@ -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',
|
||||||
|
@ -4,10 +4,9 @@ from odoo import models, fields, api
|
|||||||
class ProjectProject(models.Model):
|
class ProjectProject(models.Model):
|
||||||
_inherit = "project.project"
|
_inherit = "project.project"
|
||||||
|
|
||||||
@api.model
|
@api.multi
|
||||||
def open_timesheets_matrix(self):
|
def open_timesheets_matrix(self):
|
||||||
import pdb; pdb.set_trace()
|
wiz = self.env['project.timesheet.matrix.wiz'].with_context(project_id=self.id).create({})
|
||||||
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',
|
||||||
|
@ -3,17 +3,15 @@
|
|||||||
<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="//div[hasclass('o_kanban_card_manage_section')]" position="inside">
|
<xpath expr="//a[@groups='hr_timesheet.group_hr_timesheet_user']" position="replace">
|
||||||
<div>
|
<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">
|
||||||
<!-- <a name="open_timesheets_matrix" type="object">Timesheet</a> -->
|
<div>
|
||||||
<button name="open_timesheets_matrix" type="object" string="Workers" class="oe_stat_button" icon="fa-edit" />
|
<span class="o_label">Timesheets</span>
|
||||||
</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>
|
@ -1,24 +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):
|
||||||
import pdb; pdb.set_trace()
|
project = self.env["project.project"].browse(self.env.context.get("project_id"))
|
||||||
recs = self.env['account.analytic.account'].search([])
|
dates = [datetime.date.today() - datetime.timedelta(days=delta) for delta in range(0, 8)]
|
||||||
users = self.env['account.analytic.line'].search([]).mapped('user_id')
|
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)
|
@ -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>
|
||||||
|
Loading…
Reference in New Issue
Block a user