-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] time spent on invoice (need refacto!)
- Loading branch information
1 parent
8755671
commit 3e238be
Showing
6 changed files
with
98 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
from . import contract_line | ||
from . import account_move_line |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Copyright 2016 Tecnativa - Carlos Dauden | ||
# Copyright 2018 ACSONE SA/NV. | ||
# Copyright 2020 Tecnativa - Pedro M. Baeza | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import fields, models | ||
|
||
|
||
class AccountMoveLine(models.Model): | ||
_inherit = "account.move.line" | ||
|
||
time_spent = fields.Float( | ||
string="Time Spent this Period", compute="_compute_time_spent" | ||
) | ||
|
||
def get_time_spent(self, analytic_distribution, start_date, end_date=None): | ||
total_time_spent = 0 | ||
for analytic_account, percentage in analytic_distribution.items(): | ||
analytic_account_id = int(analytic_account) | ||
analytic_account_lines = ( | ||
self.env["account.analytic.account"] | ||
.browse(analytic_account_id) | ||
.line_ids | ||
) | ||
timesheets = analytic_account_lines.filtered( | ||
# keep only timesheets | ||
# ensure the uom is the same as the one configure for the project | ||
# timesheets (hours or day) | ||
lambda x: (x.encoding_uom_id == x.project_id.timesheet_encode_uom_id) | ||
) | ||
if timesheets: | ||
time_spent_on_account = timesheets.filtered( | ||
lambda x: (x.date >= start_date) | ||
).mapped("unit_amount") | ||
total_time_spent_on_account = sum(time_spent_on_account) | ||
total_time_spent += total_time_spent_on_account * percentage / 100 | ||
return total_time_spent | ||
|
||
def _compute_time_spent(self): | ||
for line in self: | ||
if line.analytic_distribution and line.start_date: | ||
line.time_spent = line.get_time_spent( | ||
line.analytic_distribution, line.start_date | ||
) | ||
else: | ||
line.time_spent = False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
contract_timesheet_monitoring/views/account_invoice_report.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<!-- Copyright 2020 Tecnativa - Víctor Martínez | ||
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). --> | ||
<odoo> | ||
<template id="report_invoice_document" inherit_id="account.report_invoice_document"> | ||
<xpath | ||
expr="//table[@name='invoice_line_table']/thead/tr/th[@name='th_quantity']" | ||
position="after" | ||
> | ||
<th name="th_time_spent" class="text-right">Time Spent</th> | ||
</xpath> | ||
<xpath expr="//span[@t-field='line.quantity']" position="after"> | ||
<th | ||
name="td_time_spent" | ||
class="text-center" | ||
decoration-danger="line.time_spent > line.quantity" | ||
> | ||
<span | ||
t-field="line.time_spent" | ||
t-attf-class="#{'text-danger' if line.time_spent > line.quantity else 'text-success'}" | ||
/> | ||
</th> | ||
</xpath> | ||
|
||
|
||
</template> | ||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<odoo> | ||
<record id="account_move_form_view" model="ir.ui.view"> | ||
<field name="name">account.move.form.view</field> | ||
<field name="model">account.move</field> | ||
<field name="inherit_id" ref="account.view_move_form" /> | ||
<field name="arch" type="xml"> | ||
<field name="quantity" position="after"> | ||
<field name="time_spent" decoration-danger="time_spent > quantity" /> | ||
</field> | ||
</field> | ||
</record> | ||
</odoo> |