Skip to content
GitLab
Explorer
Connexion
Navigation principale
Rechercher ou aller à…
Projet
L
lefilament_tdb
Gestion
Activité
Membres
Labels
Programmation
Tickets
Tableaux des tickets
Jalons
Code
Requêtes de fusion
Dépôt
Branches
Validations
Étiquettes
Graphe du dépôt
Comparer les révisions
Analyse
Données d'analyse des chaînes de valeur
Analyse des contributeurs
Données d'analyse du dépôt
Aide
Aide
Support
Documentation de GitLab
Comparer les forfaits GitLab
Forum de la communauté GitLab
Contribuer à GitLab
Donner votre avis
Raccourcis clavier
?
Extraits de code
Groupes
Projets
Afficher davantage de fils d'Ariane
Le Filament
lefilament_tdb
Validations
eb0e7eba
Valider
eb0e7eba
rédigé
6 janv. 2022
par
Benjamin - Le Filament
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
[refact] retrieve_datas_dashboard to avoid SQL
parent
99002596
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Modifications
1
Afficher les modifications d'espaces
En ligne
Côte à côte
Affichage de
1 fichier modifié
models/lefilament_tdb.py
+67
-144
67 ajouts, 144 suppressions
models/lefilament_tdb.py
avec
67 ajouts
et
144 suppressions
models/lefilament_tdb.py
+
67
−
144
Voir le fichier @
eb0e7eba
...
@@ -171,150 +171,73 @@ class LeFilamentTdb(models.Model):
...
@@ -171,150 +171,73 @@ class LeFilamentTdb(models.Model):
)
)
fiscal_year_next
=
"'"
+
Date
.
to_string
(
fiscal_date
)
+
"'"
fiscal_year_next
=
"'"
+
Date
.
to_string
(
fiscal_date
)
+
"'"
# Prepare values
res
=
{}
res
=
{
res
[
'
fiscal_year
'
]
=
fiscal_year
"
facture
"
:
0
,
res
[
'
fiscal_year_next
'
]
=
fiscal_year_next
"
commandes
"
:
0
,
res
[
'
target
'
]
=
self
.
env
.
user
.
company_id
.
ca_target
"
pipe
"
:
0
,
"
pipe_win
"
:
0
,
res
[
'
facture
'
]
=
sum
(
self
.
env
[
'
account.move
'
].
search
([
"
pipe_to_win
"
:
0
,
(
'
move_type
'
,
'
in
'
,
(
'
out_invoice
'
,
'
out_refund
'
)),
"
pipe_n1
"
:
0
,
(
'
state
'
,
'
=
'
,
'
posted
'
),
"
tresorerie
"
:
0
,
(
'
invoice_date
'
,
'
>
'
,
fiscal_year
),
"
entree
"
:
0
,
(
'
invoice_date
'
,
'
<=
'
,
fiscal_year_next
)
"
sortie
"
:
0
,
]).
mapped
(
'
amount_untaxed_signed
'
))
"
variation
"
:
0
,
"
target
"
:
0
,
res
[
'
commandes
'
]
=
sum
(
self
.
env
[
'
sale.order.line
'
].
search
([
"
cca
"
:
0
,
(
'
invoice_status
'
,
'
=
'
,
'
to invoice
'
),
"
capital
"
:
0
,
]).
mapped
(
'
untaxed_amount_to_invoice
'
))
"
date_maj
"
:
0
,
"
a_encaisser
"
:
0
,
res
[
'
pipe
'
]
=
sum
(
self
.
env
[
'
crm.lead
'
].
search
([
"
a_payer
"
:
0
,
'
|
'
,
"
fiscal_year
"
:
fiscal_year
,
(
'
date_deadline
'
,
'
<=
'
,
fiscal_year_next
),
"
fiscal_year_next
"
:
fiscal_year_next
,
(
'
date_deadline
'
,
'
=
'
,
False
),
}
]).
mapped
(
lambda
l
:
l
.
expected_revenue
*
l
.
probability
/
100
))
res
[
'
pipe_n1
'
]
=
sum
(
self
.
env
[
'
crm.lead
'
].
search
([
self
.
_cr
.
execute
(
(
'
date_deadline
'
,
'
>
'
,
fiscal_year_next
),
"""
]).
mapped
(
lambda
l
:
l
.
expected_revenue
*
l
.
probability
/
100
))
SELECT
res
[
'
pipe_win
'
]
=
sum
(
self
.
env
[
'
crm.lead
'
].
search
([
(SELECT COUNT(*)
(
'
probability
'
,
'
=
'
,
100
),
FROM account_move
'
|
'
,
) AS id,
(
'
date_deadline
'
,
'
<=
'
,
fiscal_year_next
),
(SELECT SUM(amount_untaxed_signed)
(
'
date_deadline
'
,
'
=
'
,
False
),
FROM account_move
]).
mapped
(
lambda
l
:
l
.
expected_revenue
*
l
.
probability
/
100
))
WHERE state!=
'
draft
'
res
[
'
pipe_to_win
'
]
=
sum
(
self
.
env
[
'
crm.lead
'
].
search
([
AND (move_type=
'
out_invoice
'
OR move_type=
'
out_refund
'
)
(
'
probability
'
,
'
!=
'
,
100
),
AND date > %s AND date <= %s
'
|
'
,
) AS facture,
(
'
date_deadline
'
,
'
<=
'
,
fiscal_year_next
),
(SELECT SUM(amount_residual_signed)
(
'
date_deadline
'
,
'
=
'
,
False
),
FROM account_move
]).
mapped
(
lambda
l
:
l
.
expected_revenue
*
l
.
probability
/
100
))
WHERE state!=
'
draft
'
AND move_type=
'
out_invoice
'
) AS a_encaisser,
res
[
'
a_encaisser
'
]
=
sum
(
self
.
env
[
'
account.move
'
].
search
([
(SELECT SUM(amount_residual_signed)
(
'
move_type
'
,
'
in
'
,
(
'
out_invoice
'
,
'
out_refund
'
)),
FROM account_move
(
'
state
'
,
'
=
'
,
'
posted
'
),
WHERE state!=
'
draft
'
AND move_type=
'
in_invoice
'
(
'
invoice_date
'
,
'
>
'
,
fiscal_year
),
) AS a_payer,
(
'
invoice_date
'
,
'
<=
'
,
fiscal_year_next
)
(SELECT SUM(expected_revenue * probability / 100)
]).
mapped
(
'
amount_residual_signed
'
))
FROM crm_lead
res
[
'
a_payer
'
]
=
sum
(
self
.
env
[
'
account.move
'
].
search
([
WHERE active=True
(
'
move_type
'
,
'
in
'
,
(
'
in_invoice
'
,
'
in_refund
'
)),
AND (date_deadline <= %s OR date_deadline is NULL)
(
'
state
'
,
'
=
'
,
'
posted
'
),
) AS pipe,
(
'
invoice_date
'
,
'
>
'
,
fiscal_year
),
(SELECT SUM(expected_revenue * probability / 100)
(
'
invoice_date
'
,
'
<=
'
,
fiscal_year_next
)
FROM crm_lead WHERE active=True AND date_deadline > %s
]).
mapped
(
'
amount_residual_signed
'
))
) AS pipe_n1,
(SELECT SUM(expected_revenue * probability / 100)
res
[
'
date_maj
'
]
=
self
.
env
[
'
account.bank.statement
'
].
search
([
FROM crm_lead
(
'
active
'
,
'
in
'
,
(
True
,
False
))],
WHERE active=True
order
=
'
date desc
'
,
AND probability = 100
limit
=
1
AND (date_deadline <= %s OR date_deadline is NULL)
).
date
) AS pipe_win,
res
[
'
tresorerie
'
]
=
sum
(
self
.
env
[
'
account.bank.statement.line
'
].
search
([]).
mapped
(
'
amount
'
))
(SELECT SUM(expected_revenue * probability / 100)
res
[
'
entree
'
]
=
sum
(
self
.
env
[
'
account.bank.statement.line
'
].
search
([
FROM crm_lead
(
'
amount
'
,
'
>
'
,
0
),
WHERE active=True
(
'
date
'
,
'
>
'
,
fiscal_year
),
AND probability != 100
]).
mapped
(
'
amount
'
))
AND (date_deadline < %s OR date_deadline is NULL)
res
[
'
sortie
'
]
=
sum
(
self
.
env
[
'
account.bank.statement.line
'
].
search
([
) AS pipe_to_win,
(
'
amount
'
,
'
<
'
,
0
),
(SELECT date
(
'
date
'
,
'
>
'
,
fiscal_year
),
FROM account_bank_statement
]).
mapped
(
'
amount
'
))
ORDER BY ID DESC LIMIT 1
res
[
'
variation
'
]
=
sum
(
self
.
env
[
'
account.bank.statement.line
'
].
search
([
) AS date_maj,
(
'
date
'
,
'
>
'
,
fiscal_year
),
(SELECT SUM(amount)
]).
mapped
(
'
amount
'
))
FROM account_bank_statement_line
) AS tresorerie,
(SELECT SUM(amount)
FROM account_bank_statement_line
WHERE amount > 0 AND date > %s
) AS entree,
(SELECT SUM(amount)
FROM account_bank_statement_line
WHERE amount < 0 AND date > %s
) AS sortie,
(SELECT SUM(amount)
FROM account_bank_statement_line
WHERE date > %s
) AS variation,
(SELECT SUM(e.total_amount)
FROM hr_expense_sheet es, hr_expense e
WHERE es.id = e.sheet_id
AND e.payment_mode =
'
own_account
'
AND es.state !=
'
done
'
) AS cca,
(SELECT SUM(price_subtotal - qty_invoiced * price_unit)
FROM sale_order_line
WHERE invoice_status =
'
to invoice
'
) AS commandes;
"""
%
(
fiscal_year
,
fiscal_year_next
,
fiscal_year_next
,
fiscal_year_next
,
fiscal_year_next
,
fiscal_year_next
,
fiscal_year
,
fiscal_year
,
fiscal_year
,
)
)
datas
=
self
.
_cr
.
dictfetchall
()
self
.
_cr
.
execute
(
"
SELECT ca_target FROM res_company;
"
)
ca_target
=
self
.
_cr
.
dictfetchall
()
self
.
_cr
.
execute
(
"
SELECT sum(capital) AS capital FROM hr_employee;
"
)
capital
=
self
.
_cr
.
dictfetchall
()
if
datas
[
0
][
"
facture
"
]:
res
[
"
facture
"
]
+=
datas
[
0
][
"
facture
"
]
if
datas
[
0
][
"
a_encaisser
"
]:
res
[
"
a_encaisser
"
]
+=
datas
[
0
][
"
a_encaisser
"
]
if
datas
[
0
][
"
a_payer
"
]:
res
[
"
a_payer
"
]
+=
datas
[
0
][
"
a_payer
"
]
if
datas
[
0
][
"
pipe
"
]:
res
[
"
pipe
"
]
+=
datas
[
0
][
"
pipe
"
]
if
datas
[
0
][
"
pipe_win
"
]:
res
[
"
pipe_win
"
]
+=
datas
[
0
][
"
pipe_win
"
]
if
datas
[
0
][
"
pipe_to_win
"
]:
res
[
"
pipe_to_win
"
]
+=
datas
[
0
][
"
pipe_to_win
"
]
if
datas
[
0
][
"
pipe_n1
"
]:
res
[
"
pipe_n1
"
]
+=
datas
[
0
][
"
pipe_n1
"
]
if
datas
[
0
][
"
tresorerie
"
]:
res
[
"
tresorerie
"
]
+=
datas
[
0
][
"
tresorerie
"
]
if
datas
[
0
][
"
date_maj
"
]:
res
[
"
date_maj
"
]
=
datas
[
0
][
"
date_maj
"
]
if
datas
[
0
][
"
entree
"
]:
res
[
"
entree
"
]
+=
datas
[
0
][
"
entree
"
]
if
datas
[
0
][
"
sortie
"
]:
res
[
"
sortie
"
]
+=
datas
[
0
][
"
sortie
"
]
if
datas
[
0
][
"
variation
"
]:
res
[
"
variation
"
]
+=
datas
[
0
][
"
variation
"
]
if
datas
[
0
][
"
commandes
"
]:
res
[
"
commandes
"
]
+=
datas
[
0
][
"
commandes
"
]
if
datas
[
0
][
"
cca
"
]:
res
[
"
cca
"
]
+=
datas
[
0
][
"
cca
"
]
if
ca_target
[
0
][
"
ca_target
"
]:
res
[
"
target
"
]
+=
ca_target
[
0
][
"
ca_target
"
]
if
capital
[
0
][
"
capital
"
]:
res
[
"
capital
"
]
+=
capital
[
0
][
"
capital
"
]
return
res
return
res
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
Aperçu
0%
Chargement en cours
Veuillez réessayer
ou
joindre un nouveau fichier
.
Annuler
You are about to add
0
people
to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Enregistrer le commentaire
Annuler
Veuillez vous
inscrire
ou vous
se connecter
pour commenter