mirror of
https://gitlab.crans.org/bde/nk20
synced 2025-06-21 01:48:21 +02:00
Merge branch 'atomicity' into 'beta'
Atomicité See merge request bde/nk20!122
This commit is contained in:
@ -5,7 +5,7 @@ from datetime import date
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.db import models
|
||||
from django.db import models, transaction
|
||||
from django.db.models import Q
|
||||
from django.template.loader import render_to_string
|
||||
from django.utils import timezone
|
||||
@ -76,6 +76,7 @@ class Invoice(models.Model):
|
||||
verbose_name=_("tex source"),
|
||||
)
|
||||
|
||||
@transaction.atomic
|
||||
def save(self, *args, **kwargs):
|
||||
"""
|
||||
When an invoice is generated, we store the tex source.
|
||||
@ -228,6 +229,7 @@ class Remittance(models.Model):
|
||||
"""
|
||||
return sum(transaction.total for transaction in self.transactions.all())
|
||||
|
||||
@transaction.atomic
|
||||
def save(self, force_insert=False, force_update=False, using=None, update_fields=None):
|
||||
# Check if all transactions have the right type.
|
||||
if self.transactions.exists() and self.transactions.filter(~Q(source=self.remittance_type.note)).exists():
|
||||
@ -306,10 +308,10 @@ class SogeCredit(models.Model):
|
||||
if self.valid:
|
||||
self.credit_transaction.valid = False
|
||||
self.credit_transaction.save()
|
||||
for transaction in self.transactions.all():
|
||||
transaction.valid = False
|
||||
transaction._force_save = True
|
||||
transaction.save()
|
||||
for tr in self.transactions.all():
|
||||
tr.valid = False
|
||||
tr._force_save = True
|
||||
tr.save()
|
||||
|
||||
def validate(self, force=False):
|
||||
if self.valid and not force:
|
||||
@ -324,12 +326,13 @@ class SogeCredit(models.Model):
|
||||
self.credit_transaction.save()
|
||||
self.save()
|
||||
|
||||
for transaction in self.transactions.all():
|
||||
transaction.valid = True
|
||||
transaction._force_save = True
|
||||
transaction.created_at = timezone.now()
|
||||
transaction.save()
|
||||
for tr in self.transactions.all():
|
||||
tr.valid = True
|
||||
tr._force_save = True
|
||||
tr.created_at = timezone.now()
|
||||
tr.save()
|
||||
|
||||
@transaction.atomic
|
||||
def save(self, *args, **kwargs):
|
||||
if not self.credit_transaction:
|
||||
self.credit_transaction = SpecialTransaction.objects.create(
|
||||
@ -362,11 +365,11 @@ class SogeCredit(models.Model):
|
||||
"Please ask her/him to credit the note before invalidating this credit."))
|
||||
|
||||
self.invalidate()
|
||||
for transaction in self.transactions.all():
|
||||
transaction._force_save = True
|
||||
transaction.valid = True
|
||||
transaction.created_at = timezone.now()
|
||||
transaction.save()
|
||||
for tr in self.transactions.all():
|
||||
tr._force_save = True
|
||||
tr.valid = True
|
||||
tr.created_at = timezone.now()
|
||||
tr.save()
|
||||
self.credit_transaction.valid = False
|
||||
self.credit_transaction.reason += " (invalide)"
|
||||
self.credit_transaction.save()
|
||||
|
Reference in New Issue
Block a user