Skip to content

Commit

Permalink
[FIX] use contract date rather than invoice date
Browse files Browse the repository at this point in the history
Invoice date might not the date of the invoiced period, because invoice are not validated and sent on the first day of the period.
  • Loading branch information
victor-champonnois committed Oct 25, 2024
1 parent 3be5b91 commit 60a6d74
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ def get_time_spent_for_period(self, start_date, end_date=None):
analytic_account_lines = self.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.product_uom_id.measure_type == "time")
)
if timesheets:
Expand Down
17 changes: 10 additions & 7 deletions contract_timesheet_monitoring/models/contract_line.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from odoo import api, fields, models
from odoo.exceptions import UserError


class ContractLine(models.Model):
Expand All @@ -14,18 +15,20 @@ class ContractLine(models.Model):
)
date_of_last_invoice = fields.Date(compute="_get_date_of_last_invoice")

def _get_date_of_last_invoice(self):
invoices = self.contract_id._get_related_invoices().filtered(lambda x: (x.state != "draft"))
if any(invoices.mapped("date_invoice")):
return max(invoices.mapped("date_invoice"))
else:
return False
def _get_period_start_date(self):
if self.recurring_invoicing_type == 'post-paid':
start_date = self.recurring_next_dat
else:
start_date = self.recurring_next_date - self.get_relative_delta(
self.recurring_rule_type, self.recurring_interval
)
return start_date

@api.depends("analytic_account_id.line_ids")
def _compute_time_spent(self):
for line in self:
if line.analytic_account_id:
period_start_date = line._get_date_of_last_invoice()
period_start_date = line._get_period_start_date()
line.time_spent = line.analytic_account_id.get_time_spent_for_period(
period_start_date
)
Expand Down

0 comments on commit 60a6d74

Please sign in to comment.