Skip to content
Snippets Groups Projects
Commit f910bd7b authored by Benjamin's avatar Benjamin
Browse files

fix erreurs requetes _delay et _total_days

parent 18a9bf5a
Branches
No related tags found
No related merge requests found
......@@ -86,14 +86,27 @@ class FilamentProjet(models.Model):
@api.one
def _delay(self):
account_id = self.analytic_account_id.id
self._cr.execute("""
SELECT
date(d_invoice) - date(d_cost) as datediff
from
(select date FROM account_analytic_line where account_id=%s and amount < 0 order by date limit 1) as d_cost,
(select date FROM account_analytic_line where account_id=%s and amount > 0 order by date limit 1) as d_invoice
;""", (account_id, account_id ) )
self.lf_delay = self._cr.fetchone()[0]
self.env.cr.execute("""
SELECT date
FROM account_analytic_line
where account_id=%s and amount < 0 order by date limit 1
;""", (account_id, ) )
d_cost = self.env.cr.fetchone()
self.env.cr.execute("""
SELECT date
FROM account_analytic_line
where account_id=%s and amount > 0 order by date limit 1
;""", (account_id, ) )
d_invoice = self.env.cr.fetchone()
if d_cost:
if d_invoice:
self.lf_delay = (datetime.strptime(d_invoice[0], "%Y-%m-%d").date() - datetime.strptime(d_cost[0], "%Y-%m-%d").date()).days
else:
self.lf_delay = (datetime.now().date() - datetime.strptime(d_cost[0], "%Y-%m-%d").date()).days
else:
self.lf_delay = 0
## Total Days
@api.one
......@@ -106,7 +119,12 @@ class FilamentProjet(models.Model):
(select date FROM account_analytic_line where account_id=%s order by date limit 1) as d_first,
(select date FROM account_analytic_line where account_id=%s order by date desc limit 1) as d_last
;""", (account_id, account_id, ) )
self.lf_total_days = self._cr.fetchone()[0]
lf_total_days = self._cr.fetchone()
if lf_total_days:
self.lf_total_days = lf_total_days[0]
else:
self.lf_total_days = 0
## Balance
@api.one
......@@ -127,10 +145,10 @@ class FilamentProjet(models.Model):
self.env.cr.execute("""
SELECT sum(amount) as Total
FROM account_analytic_line
WHERE account_id=31
WHERE account_id=%s
and date < (case when
(select date FROM account_analytic_line where account_id=31 and amount > 0 order by date limit 1) IS NOT NULL then
(select date FROM account_analytic_line where account_id=31 and amount > 0 order by date limit 1) else current_date end
(select date FROM account_analytic_line where account_id=%s and amount > 0 order by date limit 1) IS NOT NULL then
(select date FROM account_analytic_line where account_id=%s and amount > 0 order by date limit 1) else current_date end
);""", (account_id, account_id, account_id, ) )
self.lf_advance = self._cr.fetchone()[0]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment