Skip to content
GitLab
Explorer
Connexion
Navigation principale
Rechercher ou aller à…
Projet
C
cgscop_cotisation_cg
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
Confédération Générale des SCOP
cgscop_cotisation_cg
Validations
39b7150a
Valider
39b7150a
rédigé
8 févr. 2023
par
Benjamin - Le Filament
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
[add] queue job batch management
parent
de2e86fc
Branches
Branches contenant la validation
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Modifications
2
Afficher les modifications d'espaces
En ligne
Côte à côte
Affichage de
2 fichiers modifiés
models/scop_cotisation_cg.py
+55
-1
55 ajouts, 1 suppression
models/scop_cotisation_cg.py
views/scop_cotisation_cg.xml
+10
-0
10 ajouts, 0 suppression
views/scop_cotisation_cg.xml
avec
65 ajouts
et
1 suppression
models/scop_cotisation_cg.py
+
55
−
1
Voir le fichier @
39b7150a
...
...
@@ -78,6 +78,15 @@ class ScopCotisation(models.Model):
graph_values
=
fields
.
Text
(
compute
=
"
_compute_graph_values
"
)
batch_id
=
fields
.
Many2one
(
comodel_name
=
"
queue.job.batch
"
,
name
=
"
Files d
'
attente en cours
"
)
batch_ids_str
=
fields
.
Char
()
batch_count
=
fields
.
Integer
(
compute
=
"
_compute_batch_count
"
)
# ------------------------------------------------------
# Contraintes SQL
# ------------------------------------------------------
...
...
@@ -191,6 +200,13 @@ class ScopCotisation(models.Model):
elif
cotiz
.
state
!=
"
ongoing
"
:
cotiz
.
state
=
"
ongoing
"
def
_compute_batch_count
(
self
):
for
base
in
self
:
if
not
base
.
batch_ids_str
:
base
.
batch_count
=
0
else
:
base
.
batch_count
=
len
(
base
.
batch_ids_str
.
split
(
"
,
"
))
# ------------------------------------------------------
# Button functions
# ------------------------------------------------------
...
...
@@ -286,6 +302,17 @@ class ScopCotisation(models.Model):
Create contribution for members
:params member_ids: list of member ids
"""
# Vérifie que des tâches ne sont pas en cours
self
.
ensure_one
()
queue_ids
=
self
.
env
[
"
queue.job
"
].
search
([
(
"
job_batch_id
"
,
"
in
"
,
[
int
(
x
)
for
x
in
self
.
batch_ids_str
.
split
(
"
,
"
)]),
(
"
state
"
,
"
not in
"
,
[
"
done
"
,
"
cancelled
"
,
"
failed
"
])
])
if
queue_ids
:
raise
exceptions
.
UserError
(
_
(
"
Des tâches de création sont encore en cours.
"
))
member_to_invoice
=
self
.
env
[
"
res.partner
"
].
browse
(
member_ids
)
# Job queue
batch_name
=
(
...
...
@@ -294,9 +321,22 @@ class ScopCotisation(models.Model):
+
self
.
year
)
batch
=
self
.
env
[
"
queue.job.batch
"
].
get_new_batch
(
batch_name
)
# Stocke le dernier batch en cours
self
.
batch_id
=
batch
# Stocke la liste des batchs au format texte
if
not
self
.
batch_ids_str
:
self
.
batch_ids_str
=
str
(
batch
.
id
)
else
:
self
.
batch_ids_str
+=
"
, %s
"
%
(
str
(
batch
.
id
),)
# Ajoute les bordereaux au batch
for
member
in
member_to_invoice
:
liasse_id
=
self
.
get_liasse
(
member
)
self
.
with_context
(
job_batch
=
batch
).
with_delay
().
create_bordereau
(
description
=
"
Cotisation %s - Adhérent n°%s - %s
"
%
(
self
.
year
,
member
.
member_number
,
member
.
name
)
self
.
with_context
(
job_batch
=
batch
).
with_delay
(
max_retries
=
3
,
description
=
description
).
create_bordereau
(
member
=
member
,
liasse
=
liasse_id
,
nb_quarter
=
"
4
"
,
date
=
False
)
batch
.
enqueue
()
...
...
@@ -758,6 +798,20 @@ class ScopCotisation(models.Model):
"
flags
"
:
{
"
mode
"
:
"
readonly
"
,
"
default_buttons
"
:
False
},
}
def
show_batch
(
self
):
self
.
ensure_one
()
batch_ids
=
self
.
env
[
"
queue.job.batch
"
].
browse
(
[
int
(
x
)
for
x
in
self
.
batch_ids_str
.
split
(
"
,
"
)]
)
return
{
"
name
"
:
"
Files d
'
attente
"
,
"
type
"
:
"
ir.actions.act_window
"
,
"
view_type
"
:
"
form
"
,
"
view_mode
"
:
"
tree,form
"
,
"
res_model
"
:
"
queue.job.batch
"
,
"
domain
"
:
[(
"
id
"
,
"
in
"
,
batch_ids
.
ids
)],
}
# ------------------------------------------------------
# Global functions
# ------------------------------------------------------
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
views/scop_cotisation_cg.xml
+
10
−
0
Voir le fichier @
39b7150a
...
...
@@ -62,6 +62,16 @@
<field
name=
"state"
widget=
"statusbar"
clickable=
"False"
/>
</header>
<sheet>
<div
class=
"oe_button_box"
name=
"contribution_button_box"
>
<button
name=
"show_batch"
type=
"object"
class=
"oe_stat_button"
icon=
"fa-list"
attrs=
"{'invisible': [('batch_count', '=', 0)]}"
>
<field
string=
"Files d'attente"
name=
"batch_count"
widget=
"statinfo"
/>
</button>
</div>
<h1><field
name=
"name"
/></h1>
<group>
<group
name=
"contribution"
string=
"Cotisations"
>
...
...
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