Fixs annulations

- Fix oublie de @staticmethod pour Settings.CANCEl_DURATION()
- Mise en cache de Settings.CANCEL_DURATION
- Fix sur cancel_operations : mauvais modèles et at
This commit is contained in:
Aurélien Delobelle 2016-09-03 13:50:40 +02:00
parent d12dfe2f56
commit a432230128
2 changed files with 11 additions and 4 deletions

View file

@ -633,11 +633,17 @@ class Settings(models.Model):
cache.set('OVERDRAFT_AMOUNT', overdraft_amount) cache.set('OVERDRAFT_AMOUNT', overdraft_amount)
return overdraft_amount return overdraft_amount
@staticmethod
def CANCEL_DURATION(): def CANCEL_DURATION():
cancel_duration = cache.get('CANCEL_DURATION')
if cancel_duration:
return cancel_duration
try: try:
return Settings.setting_inst("CANCEL_DURATION").value_duration cancel_duration = Settings.setting_inst("CANCEL_DURATION").value_duration
except Settings.DoesNotExist: except Settings.DoesNotExist:
return timedelta() cancel_duration = timedelta()
cache.set('CANCEL_DURATION', cancel_duration)
return cancel_duration
@staticmethod @staticmethod
def create_missing(): def create_missing():
@ -667,6 +673,7 @@ class Settings(models.Model):
def empty_cache(): def empty_cache():
cache.delete_many([ cache.delete_many([
'SUBVENTION_COF','OVERDRAFT_DURATION', 'OVERDRAFT_AMOUNT', 'SUBVENTION_COF','OVERDRAFT_DURATION', 'OVERDRAFT_AMOUNT',
'CANCEL_DURATION',
]) ])
class GenericTeamToken(models.Model): class GenericTeamToken(models.Model):

View file

@ -1075,10 +1075,10 @@ def kpsul_cancel_operations(request):
# Note : si InventoryArticle est maj par .save(), stock_error # Note : si InventoryArticle est maj par .save(), stock_error
# est recalculé automatiquement # est recalculé automatiquement
if ope.article and ope.article_nb: if ope.article and ope.article_nb:
last_stock = (ArticleInventory.objects last_stock = (InventoryArticle.objects
.select_related('inventory') .select_related('inventory')
.filter(article=ope.article) .filter(article=ope.article)
.order_by('at') .order_by('inventory__at')
.last()) .last())
if not last_stock or last_stock.inventory.at < ope.group.at: if not last_stock or last_stock.inventory.at < ope.group.at:
to_articles_stocks[ope.article] += ope.article_nb to_articles_stocks[ope.article] += ope.article_nb