Skip to content
Extraits de code Groupes Projets
Valider 68e0e4ec rédigé par Juliana's avatar Juliana
Parcourir les fichiers

[FIX]Add queue job for creation invoice

parent 4832e5a2
Branches
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -172,32 +172,10 @@ class AccOperation(models.Model):
return power_tab_by_prod
def create_account(self, date_month, account_periodicity):
"""
Fonction permettant de générer les factures à une date donné.
Création des factures + Création des lignes de facture associées.
:param date_month: date à laquelle on lance la facture
account_periodicity: périodicité (1 pour mois, 3 pour trimestre,
6 pour semestre, 12 pour année)
:return:
"""
def process_create_account(
self, acc_injection_id, acc_delivery_id, date_start, date_end, power_total
):
account_list = []
date_end = date_utils.end_of(date_month, "month")
if account_periodicity == "1":
date_start = date_utils.start_of(date_month, "month")
else:
date_start = date_end - relativedelta(months=int(account_periodicity) - 1)
date_start = date_utils.start_of(date_start, "month")
for acc_injection_id in self.acc_injection_ids:
if acc_injection_id.is_account_auto_activate:
for acc_delivery_id in self.acc_delivery_ids:
power_total = self.calc_power_by_cons_by_prod(
acc_injection_id, acc_delivery_id, date_start, date_end
)
if power_total > 0:
Account = self.env["acc.account"]
acc_account = Account.create(
......@@ -344,11 +322,63 @@ class AccOperation(models.Model):
}
)
account_list.append(acc_account)
return True
def create_account(self, date_month, account_periodicity):
"""
Fonction permettant de générer les factures à une date donné.
Création des factures + Création des lignes de facture associées.
:param date_month: date à laquelle on lance la facture
account_periodicity: périodicité (1 pour mois, 3 pour trimestre,
6 pour semestre, 12 pour année)
:return:
"""
date_end = date_utils.end_of(date_month, "month")
if account_periodicity == "1":
date_start = date_utils.start_of(date_month, "month")
else:
date_start = date_end - relativedelta(months=int(account_periodicity) - 1)
date_start = date_utils.start_of(date_start, "month")
for acc_injection_id in self.acc_injection_ids:
if acc_injection_id.is_account_auto_activate:
for acc_delivery_id in self.acc_delivery_ids:
power_total = self.calc_power_by_cons_by_prod(
acc_injection_id, acc_delivery_id, date_start, date_end
)
if power_total > 0:
# Création du lot
batch_name = (
"Factures du "
+ str(date_start)
+ " au "
+ str(date_end)
+ " - Opération :"
+ str(self.name)
+ " - Prod :"
+ str(acc_injection_id.name)
+ " - Conso :"
+ str(acc_delivery_id.name)
)
batch = self.env["queue.job.batch"].get_new_batch(batch_name)
self.with_context(
job_batch=batch
).with_delay().process_create_account(
acc_injection_id,
acc_delivery_id,
date_start,
date_end,
power_total,
)
# lancement de la file d'attente
batch.enqueue()
action = self.env["ir.actions.actions"]._for_xml_id(
"acc_account.action_acc_account"
)
action["domain"] = [("id", "in", account_list)]
action["domain"] = [("acc_operation_id", "=", self.id)]
return action
def calc_power_by_cons_by_prod(
......
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