Skip to content

Commit

Permalink
[IMP] custom_saca_timesheet: pre-commit stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
oihane committed Jun 27, 2024
1 parent 42d45d5 commit e10e5b4
Show file tree
Hide file tree
Showing 8 changed files with 231 additions and 118 deletions.
4 changes: 2 additions & 2 deletions custom_saca_timesheet/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
"category": "Services/Timesheets",
"license": "AGPL-3",
"author": "AvanzOSC",
"website": "http://www.avanzosc.es",
"website": "https://github.com/avanzosc/hr-addons",
"depends": [
"hr_timesheet_activity_begin_end",
"custom_descarga",
"hr_timesheet_begin_end_usability"
"hr_timesheet_begin_end_usability",
],
"data": [
"data/project.xml",
Expand Down
10 changes: 4 additions & 6 deletions custom_saca_timesheet/data/project.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<odoo>
<data noupdate="1">
<record id="project_saca" model="project.project">
<field name="name">Gestión de SACAS</field>
</record>
</data>
<odoo noupdate="1">
<record id="project_saca" model="project.project">
<field name="name">Gestión de SACAS</field>
</record>
</odoo>
76 changes: 50 additions & 26 deletions custom_saca_timesheet/models/account_analytic_line.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Copyright 2022 Berezi Amubieta - AvanzOSC
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import api, fields, models
from datetime import timedelta

from odoo import api, fields, models


class AccountAnalyticLine(models.Model):
_inherit = "account.analytic.line"
Expand All @@ -11,19 +12,23 @@ class AccountAnalyticLine(models.Model):
sequence = fields.Integer(string="Sequence")
saca_line_id = fields.Many2one(
string="Saca Line",
comodel_name="saca.line")
comodel_name="saca.line",
)
saca_id = fields.Many2one(
string="Saca",
comodel_name="saca",
related="saca_line_id.saca_id",
store=True)
store=True,
)
classified = fields.Boolean(
string="Classified",
default=False)
default=False,
)
speed = fields.Float(
string="Speed",
compute="_compute_speed",
store=True)
store=True,
)

@api.depends("saca_line_id", "saca_line_id.download_unit", "unit_amount")
def _compute_speed(self):
Expand All @@ -36,7 +41,8 @@ def _compute_speed(self):
@api.onchange("time_start", "time_stop")
def onchange_time_start(self):
chofer = self.saca_line_id.timesheet_ids.filtered(
lambda c: c.task_id.name == "Chofer")
lambda c: c.task_id.name == "Chofer"
)
if self.time_stop > self.time_start:
self.date_end = self.date
if chofer and self.time_start < chofer.time_start:
Expand All @@ -48,30 +54,48 @@ def write(self, values):
result = super(AccountAnalyticLine, self).write(values)
for line in self:
chofer = self.env["account.analytic.line"].search(
[("saca_line_id", "=", line.saca_line_id.id),
("name", "=", u'{} {}'.format(
line.project_id.name, "Chofer"))], limit=1)
[
("saca_line_id", "=", line.saca_line_id.id),
("name", "=", "{} {}".format(line.project_id.name, "Chofer")),
],
limit=1,
)
matanza = line.env["account.analytic.line"].search(
[("saca_line_id", "=", line.saca_line_id.id),
("name", "=", u'{} {}'.format(
line.project_id.name, "Matanza"))], limit=1)
[
("saca_line_id", "=", line.saca_line_id.id),
("name", "=", "{} {}".format(line.project_id.name, "Matanza")),
],
limit=1,
)
espera = line.env["account.analytic.line"].search(
[("saca_line_id", "=", line.saca_line_id.id),
("name", "=", u'{} {}'.format(
line.project_id.name, "Espera"))], limit=1)
if ("time_start" in values and line.id == matanza.id) or (
"time_stop" in values and line.id == chofer.id) and (
chofer.time_stop) and matanza.time_start and espera:
[
("saca_line_id", "=", line.saca_line_id.id),
("name", "=", "{} {}".format(line.project_id.name, "Espera")),
],
limit=1,
)
if (
("time_start" in values and line.id == matanza.id)
or ("time_stop" in values and line.id == chofer.id)
and (chofer.time_stop)
and matanza.time_start
and espera
):
date_end = matanza.date
amount = matanza.time_start - chofer.time_stop
if matanza.time_start < chofer.time_stop:
amount = (timedelta(hours=matanza.time_start) + timedelta(
hours=24) - timedelta(hours=chofer.time_stop)
amount = (
timedelta(hours=matanza.time_start)
+ timedelta(hours=24)
- timedelta(hours=chofer.time_stop)
).seconds / 3600
espera.write({
"date": chofer.date_end,
"date_end": date_end,
"time_start": chofer.time_stop,
"time_stop": matanza.time_start,
"unit_amount": amount})
espera.write(
{
"date": chofer.date_end,
"date_end": date_end,
"time_start": chofer.time_stop,
"time_stop": matanza.time_start,
"unit_amount": amount,
}
)
return result
6 changes: 4 additions & 2 deletions custom_saca_timesheet/models/project_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ class ProjectTask(models.Model):

saca_line_id = fields.Many2one(
string="Saca Line",
comodel_name="saca.line")
comodel_name="saca.line",
)
saca_id = fields.Many2one(
string="Saca",
comodel_name="saca",
related="saca_line_id.saca_id",
store=True)
store=True,
)
159 changes: 105 additions & 54 deletions custom_saca_timesheet/models/saca_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,71 +10,122 @@ class SacaLine(models.Model):
timesheet_ids = fields.One2many(
string="Timesheet",
comodel_name="account.analytic.line",
inverse_name="saca_line_id")
inverse_name="saca_line_id",
)

def action_create_purchase(self):
super(SacaLine, self).action_create_purchase()
project = self.env.ref("custom_saca_timesheet.project_saca")
if not self.purchase_order_line_ids:
raise ValidationError(
_("There is no any purchase order line.")
)
raise ValidationError(_("There is no any purchase order line."))
if not self.timesheet_ids:
self.env["project.task"].create({
"project_id": project.id,
"name": "Carga",
"saca_line_id": self.id,
"timesheet_ids": [(0, 0, {
"sequence": 2,
self.env["project.task"].create(
{
"project_id": project.id,
"name": "Carga",
"saca_line_id": self.id,
"date": self.saca_id.date,
"date_end": self.saca_id.date,
"name": u'{} {}'.format(project.name, "Carga"),
"project_id": project.id})]})
self.env["project.task"].create({
"project_id": project.id,
"name": "Espera",
"saca_line_id": self.id,
"timesheet_ids": [(0, 0, {
"sequence": 3,
"timesheet_ids": [
(
0,
0,
{
"sequence": 2,
"saca_line_id": self.id,
"date": self.saca_id.date,
"date_end": self.saca_id.date,
"name": "{} {}".format(project.name, "Carga"),
"project_id": project.id,
},
)
],
}
)
self.env["project.task"].create(
{
"project_id": project.id,
"name": "Espera",
"saca_line_id": self.id,
"date": self.saca_id.date,
"date_end": self.saca_id.date,
"name": u'{} {}'.format(project.name, "Espera"),
"project_id": project.id})]})
self.env["project.task"].create({
"project_id": project.id,
"name": "Chofer",
"saca_line_id": self.id,
"timesheet_ids": [(0, 0, {
"sequence": 1,
"timesheet_ids": [
(
0,
0,
{
"sequence": 3,
"saca_line_id": self.id,
"date": self.saca_id.date,
"date_end": self.saca_id.date,
"name": "{} {}".format(project.name, "Espera"),
"project_id": project.id,
},
)
],
}
)
self.env["project.task"].create(
{
"project_id": project.id,
"name": "Chofer",
"saca_line_id": self.id,
"date": self.saca_id.date,
"date_end": self.saca_id.date,
"name": u'{} {}'.format(project.name, "Chofer"),
"project_id": project.id})]})
self.env["project.task"].create({
"project_id": project.id,
"name": "Matanza",
"saca_line_id": self.id,
"timesheet_ids": [(0, 0, {
"sequence": 4,
"timesheet_ids": [
(
0,
0,
{
"sequence": 1,
"saca_line_id": self.id,
"date": self.saca_id.date,
"date_end": self.saca_id.date,
"name": "{} {}".format(project.name, "Chofer"),
"project_id": project.id,
},
)
],
}
)
self.env["project.task"].create(
{
"project_id": project.id,
"name": "Matanza",
"saca_line_id": self.id,
"date": self.saca_id.date,
"date_end": self.saca_id.date,
"name": u'{} {}'.format(project.name, "Matanza"),
"project_id": project.id})]})
self.env["project.task"].create({
"project_id": project.id,
"name": "Matanza(Parte II)",
"saca_line_id": self.id,
"timesheet_ids": [(0, 0, {
"sequence": 5,
"timesheet_ids": [
(
0,
0,
{
"sequence": 4,
"saca_line_id": self.id,
"date": self.saca_id.date,
"date_end": self.saca_id.date,
"name": "{} {}".format(project.name, "Matanza"),
"project_id": project.id,
},
)
],
}
)
self.env["project.task"].create(
{
"project_id": project.id,
"name": "Matanza(Parte II)",
"saca_line_id": self.id,
"date": self.saca_id.date,
"date_end": self.saca_id.date,
"name": u'{} {}'.format(project.name, "Matanza(Parte II)"),
"project_id": project.id})]})
"timesheet_ids": [
(
0,
0,
{
"sequence": 5,
"saca_line_id": self.id,
"date": self.saca_id.date,
"date_end": self.saca_id.date,
"name": "{} {}".format(
project.name, "Matanza(Parte II)"
),
"project_id": project.id,
},
)
],
}
)
for line in self.timesheet_ids:
line.employee_id = False
line.user_id = False
26 changes: 18 additions & 8 deletions custom_saca_timesheet/views/account_analytic_line_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,36 @@
<odoo>
<record id="hr_timesheet_line_tree" model="ir.ui.view">
<field name="model">account.analytic.line</field>
<field name="inherit_id" ref="hr_timesheet.hr_timesheet_line_tree"/>
<field name="inherit_id" ref="hr_timesheet.hr_timesheet_line_tree" />
<field name="arch" type="xml">
<field name="task_id" position="after">
<field name="saca_id" optional="show"/>
<field name="saca_line_id" optional="show"/>
<field name="saca_id" optional="show" />
<field name="saca_line_id" optional="show" />
</field>
</field>
</record>

<record id="hr_timesheet_line_search" model="ir.ui.view">
<field name="model">account.analytic.line</field>
<field name="inherit_id" ref="hr_timesheet.hr_timesheet_line_search"/>
<field name="inherit_id" ref="hr_timesheet.hr_timesheet_line_search" />
<field name="arch" type="xml">
<field name="task_id" position="after">
<field name="saca_id" optional="show"/>
<field name="saca_line_id" optional="show"/>
<field name="saca_id" optional="show" />
<field name="saca_line_id" optional="show" />
</field>
<filter name="groupby_task" position="after">
<filter string="Saca" name="groupby_saca" domain="[]" context="{'group_by': 'saca_id'}"/>
<filter string="Saca Line" name="groupby_saca_line" domain="[]" context="{'group_by': 'saca_line_id'}"/>
<filter
string="Saca"
name="groupby_saca"
domain="[]"
context="{'group_by': 'saca_id'}"
/>
<filter
string="Saca Line"
name="groupby_saca_line"
domain="[]"
context="{'group_by': 'saca_line_id'}"
/>
</filter>
</field>
</record>
Expand Down
Loading

0 comments on commit e10e5b4

Please sign in to comment.