diff --git a/wizard/scop_cotisation_aura_wizard.py b/wizard/scop_cotisation_aura_wizard.py index e9026ef220c90a6568c3ba538e8182d017460898..a208235db45c3367b3f79ae5dd193453c7d8424b 100644 --- a/wizard/scop_cotisation_aura_wizard.py +++ b/wizard/scop_cotisation_aura_wizard.py @@ -85,20 +85,23 @@ class ScopCotisationWizard(models.TransientModel): message_id = self.env['message.wizard'].create( {'message': message}) - # Création de la task - cotiz_aura_task = self.env['scop.cotisation.task'].create({ - 'year': self.year, - 'cotiz_to_create': len(members_to_invoice), - 'message': "En cours de création", - 'status': 'in_process' - }) - cotiz_aura_task.env.cr.commit() - # Lancement du calcul en arrière plan - threaded_cotiz = threading.Thread( - target=self.cotisation_aura_id.process_cotiz_generate, - args=(members_to_invoice, cotiz_aura_task, - self.nb_quarter_aura, self.date)) - threaded_cotiz.start() + # Job queue + batch_name = (fields.Datetime.to_string(fields.Datetime.now()) + + " Cotisations nouveaux adhérents " + str(self.year)) + batch = self.env['queue.job.batch'].get_new_batch(batch_name) + for member in members_to_invoice: + liasse = self.cotisation_aura_id.get_liasse(member) + amount_aura = self.cotisation_aura_id.round_to_closest_multiple( + self.cotisation_aura_id.get_cotiz_aura(member, liasse), 4) + + # Mise en file d'attente de la création du bordereau + self.cotisation_aura_id.with_context( + job_batch=batch).with_delay().create_contribution_aura( + partner=member, amount=amount_aura, + nb_quarter_aura=4, liasse=liasse, date=False) + + # Lancement de la file d'attente + batch.enqueue() else: message = ("<p class='text-center'>Tous les appels de cotisations " "pour les nouveaux adhérents connus ont déjà été "