Skip to content
Extraits de code Groupes Projets
Valider ba190bb6 rédigé par Rémi - Le Filament's avatar Rémi - Le Filament
Parcourir les fichiers

Fix coding according to standards

parent 4411afaf
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -201,30 +201,3 @@ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY C
If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
\ No newline at end of file
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If your software can interact with users remotely through a computer network, you should also make sure that it provides a way for users to get its source. For example, if your program is a web application, its interface could display a "Source" link that leads users to an archive of the code. There are many ways you could offer source, and different solutions will be better for different programs; see section 13 for the specific requirements.
You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU AGPL, see <https://www.gnu.org/licenses/>.
\ No newline at end of file
# -*- coding: utf-8 -*-
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
import models
\ No newline at end of file
from . import models
# -*- coding: utf-8 -*-
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
'name': 'Le Filament - Cash Flow project',
'summary': """
Cash Flow project Le Filament""",
'version': '10.0.1.0',
'version': '10.0.1.0.0',
'license': 'AGPL-3',
'description': """
......
# -*- coding: utf-8 -*-
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
import project
\ No newline at end of file
from . import project
......@@ -3,10 +3,9 @@
# © 2017 Le Filament (<http://www.le-filament.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from datetime import datetime, date
import time
from odoo import tools
from odoo import models, fields, api, osv
from datetime import datetime
from odoo import models, fields, api
class FilamentProjetCashFlow(models.Model):
_inherit = 'project.project'
......@@ -16,22 +15,27 @@ class FilamentProjetCashFlow(models.Model):
lf_advance = fields.Float('Advanced cash', compute='_advance')
lf_balance = fields.Float('Current balance', compute='_balance')
## Time to first invoice
# Time to first invoice
@api.one
def _delay(self):
account_id = self.analytic_account_id.id
prospection_tasks = self.env['project.task'].search([('name','=ilike','Prospection'+'%'),('project_id','=',self.id)]).ids
prospection_tasks = self.env['project.task'].search(
[('name', '=ilike', 'Prospection'+'%'),
('project_id', '=', self.id)]).ids
if not prospection_tasks:
self.env.cr.execute("""
SELECT date
FROM account_analytic_line
where account_id=%s and project_id is not null order by date
WHERE account_id=%s AND project_id IS NOT NULL
ORDER BY date
;""", (account_id, ))
else:
self.env.cr.execute("""
SELECT date
FROM account_analytic_line
where account_id=%s and (task_id not in %s or task_id is null) and project_id is not null order by date
WHERE account_id=%s AND (task_id not IN %s OR task_id IS NULL)
AND project_id IS NOT NULL
ORDER BY date
;""", (account_id, tuple(prospection_tasks), ))
d_cost = self.env.cr.fetchall()
......@@ -39,39 +43,65 @@ class FilamentProjetCashFlow(models.Model):
self.env.cr.execute("""
SELECT date
FROM account_analytic_line
where account_id=%s and project_id is null and ref is null order by date limit 1
WHERE account_id=%s AND project_id IS NULL AND ref IS NULL
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][0], "%Y-%m-%d").date()).days
self.lf_delay = (
datetime.strptime(d_invoice[0], "%Y-%m-%d").date()
- datetime.strptime(d_cost[0][0], "%Y-%m-%d").date()
).days
else:
self.lf_delay = (datetime.strptime(d_cost[-1][0], "%Y-%m-%d").date() - datetime.strptime(d_cost[0][0], "%Y-%m-%d").date()).days
self.lf_delay = (
datetime.strptime(d_cost[-1][0], "%Y-%m-%d").date()
- datetime.strptime(d_cost[0][0], "%Y-%m-%d").date()
).days
else:
self.lf_delay = 0
## Total Days
# Total Days
@api.one
def _total_days(self):
account_id = self.analytic_account_id.id
prospection_tasks = self.env['project.task'].search([('name','=ilike','Prospection'+'%'),('project_id','=',self.id)]).ids
prospection_tasks = self.env['project.task'].search(
[('name', '=ilike', 'Prospection'+'%'),
('project_id', '=', self.id)]
).ids
if not prospection_tasks:
self.env.cr.execute("""
SELECT
date(d_last) - date(d_first) as datediff
from
(select date FROM account_analytic_line where account_id=%s and project_id is not null order by date limit 1) as d_first,
(select date FROM account_analytic_line where account_id=%s and project_id is not null order by date desc limit 1) as d_last
SELECT date(d_last) - date(d_first) AS datediff
FROM
(SELECT date
FROM account_analytic_line
WHERE account_id=%s AND project_id IS NOT NULL
ORDER BY date LIMIT 1) AS d_first,
(SELECT date
FROM account_analytic_line
WHERE account_id=%s AND project_id IS NOT NULL
ORDER BY date DESC LIMIT 1) AS d_last
;""", (account_id, account_id, ))
else:
self.env.cr.execute("""
SELECT
date(d_last) - date(d_first) as datediff
from
(select date FROM account_analytic_line where account_id=%s and (task_id not in %s or task_id is null) and project_id is not null order by date limit 1) as d_first,
(select date FROM account_analytic_line where account_id=%s and (task_id not in %s or task_id is null) and project_id is not null order by date desc limit 1) as d_last
;""", (account_id, tuple(prospection_tasks), account_id, tuple(prospection_tasks), ) )
self.env.cr.execute(
"""
SELECT date(d_last) - date(d_first) AS datediff
FROM
(SELECT date FROM account_analytic_line
WHERE account_id=%s
AND (task_id not IN %s OR task_id IS NULL)
AND project_id IS NOT NULL
ORDER BY date LIMIT 1) AS d_first,
(SELECT date FROM account_analytic_line
WHERE account_id=%s
AND (task_id not IN %s OR task_id IS NULL)
AND project_id IS NOT NULL
ORDER BY date DESC LIMIT 1) AS d_last
;""",
(account_id, tuple(prospection_tasks),
account_id, tuple(prospection_tasks), )
)
lf_total_days = self._cr.fetchone()
......@@ -80,57 +110,87 @@ class FilamentProjetCashFlow(models.Model):
else:
self.lf_total_days = 0
## Balance
# Balance
@api.one
def _balance(self):
account_id = self.analytic_account_id.id
prospection_tasks = self.env['project.task'].search([('name','=ilike','Prospection'+'%'),('project_id','=',self.id)]).ids
prospection_tasks = self.env['project.task'].search(
[('name', '=ilike', 'Prospection'+'%'),
('project_id', '=', self.id)]).ids
if not prospection_tasks:
self.env.cr.execute("""
SELECT sum(amount) as Total
SELECT SUM(amount) AS Total
FROM account_analytic_line
WHERE account_id=%s
;""", (account_id, ))
self.lf_balance = self._cr.fetchone()[0]
else:
self.env.cr.execute("""
SELECT sum(amount) as Total
SELECT SUM(amount) AS Total
FROM account_analytic_line
WHERE account_id=%s and (task_id not in %s or task_id is null)
WHERE account_id=%s AND (task_id not IN %s OR task_id IS NULL)
;""", (account_id, tuple(prospection_tasks), ))
self.lf_balance = self._cr.fetchone()[0]
## Advance cash
# Advance cash
@api.one
def _advance(self):
account_id = self.analytic_account_id.id
prospection_tasks = self.env['project.task'].search([('name','=ilike','Prospection'+'%'),('project_id','=',self.id)]).ids
prospection_tasks = self.env['project.task'].search(
[('name', '=ilike', 'Prospection'+'%'),
('project_id', '=', self.id)]).ids
if not prospection_tasks:
self.env.cr.execute("""
SELECT sum(amount) as Total
self.env.cr.execute(
"""
SELECT SUM(amount) AS Total
FROM account_analytic_line
WHERE account_id=%s AND date <
(CASE WHEN
(SELECT date FROM account_analytic_line
WHERE account_id=%s
AND project_id IS NULL
AND ref IS NULL
ORDER BY date LIMIT 1) IS NOT NULL
THEN
(SELECT date FROM account_analytic_line
WHERE account_id=%s
and date < (case when
(select date FROM account_analytic_line where account_id=%s and project_id is null and ref is null order by date limit 1) IS NOT NULL then
(select date FROM account_analytic_line where account_id=%s and project_id is null and ref is null order by date limit 1) else current_date end
);""", (account_id, account_id, account_id, ) )
AND project_id IS NULL
AND ref IS NULL
ORDER BY date LIMIT 1)
ELSE current_date
END);
""",
(account_id, account_id, account_id, ))
else:
self.env.cr.execute("""
SELECT sum(amount) as Total
self.env.cr.execute(
"""
SELECT SUM(amount) AS Total
FROM account_analytic_line
WHERE account_id=%s AND date <
(CASE WHEN
(SELECT date FROM account_analytic_line
WHERE account_id=%s
AND project_id IS NULL
AND ref is NULL
ORDER BY date LIMIT 1) IS NOT NULL
THEN
(SELECT date FROM account_analytic_line
WHERE account_id=%s
and date < (case when
(select date FROM account_analytic_line where account_id=%s and project_id is null and ref is null order by date limit 1) IS NOT NULL then
(select date FROM account_analytic_line where account_id=%s and project_id is null and ref is null order by date limit 1) else current_date end
) and (task_id not in %s or task_id is null);""", (account_id, account_id, account_id, tuple(prospection_tasks), ) )
AND project_id IS NULL
AND ref IS NULL
ORDER BY date LIMIT 1)
ELSE current_date
END)
AND (task_id NOT IN %s OR task_id IS NULL);
""",
(account_id, account_id, account_id,
tuple(prospection_tasks), ))
self.lf_advance = self._cr.fetchone()[0]
####################################################
### Actions ###
# Actions #
####################################################
def open_cash_flow(self):
return {
'type': 'ir.actions.client',
......@@ -144,52 +204,75 @@ class FilamentProjetCashFlow(models.Model):
}
####################################################
### Widget Function ###
# Widget Function #
####################################################
@api.model
def cash_flow(self, account_id, project_id):
account = self.env['account.analytic.account'].search([('id', '=', account_id)])
account = self.env['account.analytic.account'].search(
[('id', '=', account_id)])
project = self.env['project.project'].search([('id', '=', project_id)])
## Analytic account name
# Analytic account name
nom = account.name
## Cash Flow Request
prospection_tasks = self.env['project.task'].search([('name','=ilike','Prospection'+'%'),('project_id','=',project_id)]).ids
# Cash Flow Request
prospection_tasks = self.env['project.task'].search(
[('name', '=ilike', 'Prospection'+'%'),
('project_id', '=', project_id)]).ids
if not prospection_tasks:
self.env.cr.execute("""
SELECT date, sum(sum(amount)) over (order by date) as Total,
sum(sum(case when project_id is not null then amount else 0 end)) over (order by date) as Timesheet,
sum(sum(case when project_id is null and ref is not null then amount else 0 end)) over (order by date) as Fournisseurs,
sum(sum(case when project_id is null and ref is null then amount else 0 end)) over (order by date) as Clients
self.env.cr.execute(
"""
SELECT date,
SUM(SUM(amount)) OVER (ORDER BY date) AS Total,
SUM(SUM(CASE WHEN project_id IS NOT NULL
THEN amount ELSE 0 END))
OVER (ORDER BY date) AS Timesheet,
SUM(SUM(CASE WHEN project_id IS NULL AND ref IS NOT NULL
THEN amount ELSE 0 END))
OVER (ORDER BY date) AS Fournisseurs,
SUM(SUM(CASE WHEN project_id IS NULL AND ref IS NULL
THEN amount ELSE 0 END))
OVER (ORDER BY date) AS Clients
FROM account_analytic_line
WHERE account_id=%s
group by date;
GROUP BY date;
""", (account_id, ))
else:
self.env.cr.execute("""
self.env.cr.execute(
"""
SELECT date,
sum(sum(case when (task_id not in %s or task_id is null) then amount else 0 end)) over (order by date) as Total,
sum(sum(case when project_id is not null and (task_id not in %s or task_id is null) then amount else 0 end)) over (order by date) as Timesheet,
sum(sum(case when project_id is null and ref is not null then amount else 0 end)) over (order by date) as Fournisseurs,
sum(sum(case when project_id is null and ref is null then amount else 0 end)) over (order by date) as Clients
SUM(SUM(CASE WHEN (task_id NOT IN %s OR task_id IS NULL)
THEN amount ELSE 0 END))
OVER (ORDER BY date) AS Total,
SUM(SUM(CASE WHEN project_id IS NOT NULL
AND (task_id not in %s or task_id IS NULL)
THEN amount ELSE 0 END))
OVER (ORDER BY date) AS Timesheet,
SUM(SUM(CASE WHEN project_id IS NULL AND ref IS NOT NULL
THEN amount ELSE 0 END))
OVER (ORDER BY date) AS Fournisseurs,
SUM(SUM(CASE WHEN project_id IS NULL AND ref IS NULL
THEN amount ELSE 0 END))
OVER (ORDER BY date) AS Clients
FROM account_analytic_line
WHERE account_id=%s
group by date;
""", (tuple(prospection_tasks), tuple(prospection_tasks), account_id, ) )
GROUP BY date;
""",
(tuple(prospection_tasks), tuple(prospection_tasks),
account_id, ))
cash_flow = self._cr.dictfetchall()
## Time to first invoice
# Time to first invoice
delay = project.lf_delay
## Total Days
# Total Days
total_days = project.lf_total_days
## Balance
# Balance
balance = project.lf_balance
## Advance cash
# Advance cash
advance = project.lf_advance
return {
......@@ -200,4 +283,3 @@ class FilamentProjetCashFlow(models.Model):
'advance': advance,
'total_days': total_days,
}
// # © 2017 Le Filament (<http://www.le-filament.com>)
// # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
// © 2017 Le Filament (<http://www.le-filament.com>)
// License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
odoo.define('lefilament_cash_flow.cashFlow', function(require) {
'use strict';
......
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">
<t t-name="CashFlow">
<div class="card">
<table class="table">
......@@ -24,6 +23,4 @@
<canvas id="cash_flow" width="auto" height="100"></canvas>
</div>
</t>
</templates>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2017 Le Filament (<https://www.le-filament.com>)
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
<odoo>
<data>
<template id="lefilament_tdb_assets_backend" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript" src="/lefilament_cash_flow/static/src/lib/chart.js"></script>
<script type="text/javascript" src="/lefilament_cash_flow/static/src/js/cash_flow.js"></script>
</xpath>
</template>
</data>
</odoo>
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2017 Le Filament (<https://www.le-filament.com>)
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
<odoo>
<data>
<!-- Project Form -->
<record id="view_form_lefilament_cashflow_form_inherited" model="ir.ui.view">
<field name="name">Le Filament Projets Cash Flow</field>
......@@ -29,6 +30,5 @@
</xpath>
</field>
</record>
</data>
</odoo>
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter