Revision 3adbfafa snf-astakos-app/astakos/quotaholder/callpoint.py
b/snf-astakos-app/astakos/quotaholder/callpoint.py | ||
---|---|---|
35 | 35 |
QuotaholderError, |
36 | 36 |
CorruptedError, InvalidDataError, |
37 | 37 |
NoQuantityError, NoCapacityError, |
38 |
ExportLimitError, ImportLimitError, |
|
39 | 38 |
DuplicateError) |
40 | 39 |
|
41 | 40 |
from astakos.quotaholder.utils.newname import newname |
... | ... | |
62 | 61 |
except Policy.DoesNotExist: |
63 | 62 |
continue |
64 | 63 |
|
65 |
append((policy, p.quantity, p.capacity, |
|
66 |
p.import_limit, p.export_limit)) |
|
64 |
append((policy, p.quantity, p.capacity)) |
|
67 | 65 |
|
68 | 66 |
return limits |
69 | 67 |
|
70 | 68 |
def set_limits(self, context=None, set_limits=()): |
71 | 69 |
|
72 |
for (policy, quantity, capacity, |
|
73 |
import_limit, export_limit) in set_limits: |
|
70 |
for (policy, quantity, capacity) in set_limits: |
|
74 | 71 |
|
75 | 72 |
try: |
76 | 73 |
policy = db_get_policy(policy=policy, for_update=True) |
... | ... | |
78 | 75 |
Policy.objects.create(policy=policy, |
79 | 76 |
quantity=quantity, |
80 | 77 |
capacity=capacity, |
81 |
import_limit=import_limit, |
|
82 |
export_limit=export_limit) |
|
78 |
) |
|
83 | 79 |
else: |
84 | 80 |
policy.quantity = quantity |
85 | 81 |
policy.capacity = capacity |
86 |
policy.export_limit = export_limit |
|
87 |
policy.import_limit = import_limit |
|
88 | 82 |
policy.save() |
89 | 83 |
|
90 | 84 |
return () |
... | ... | |
287 | 281 |
p = h.policy |
288 | 282 |
|
289 | 283 |
append((h.holder, h.resource, p.quantity, p.capacity, |
290 |
p.import_limit, p.export_limit, |
|
291 | 284 |
h.imported, h.exported, |
292 | 285 |
h.returned, h.released, |
293 | 286 |
h.flags)) |
... | ... | |
300 | 293 |
|
301 | 294 |
q_holdings = Q() |
302 | 295 |
holders = [] |
303 |
for (holder, resource, _, _, _, _, _) in set_quota:
|
|
296 |
for (holder, resource, _, _, _) in set_quota: |
|
304 | 297 |
holders.append(holder) |
305 | 298 |
|
306 | 299 |
hs = Holding.objects.filter(holder__in=holders).select_for_update() |
... | ... | |
312 | 305 |
|
313 | 306 |
for (holder, resource, |
314 | 307 |
quantity, capacity, |
315 |
import_limit, export_limit, flags) in set_quota:
|
|
308 |
flags) in set_quota: |
|
316 | 309 |
|
317 | 310 |
policy = newname('policy_') |
318 | 311 |
newp = Policy(policy=policy, |
319 | 312 |
quantity=quantity, |
320 | 313 |
capacity=capacity, |
321 |
import_limit=import_limit, |
|
322 |
export_limit=export_limit) |
|
314 |
) |
|
323 | 315 |
|
324 | 316 |
try: |
325 | 317 |
h = holdings[(holder, resource)] |
... | ... | |
353 | 345 |
sources = sub_quota + add_quota |
354 | 346 |
q_holdings = Q() |
355 | 347 |
holders = [] |
356 |
for (holder, resource, _, _, _, _) in sources:
|
|
348 |
for (holder, resource, _, _) in sources: |
|
357 | 349 |
holders.append(holder) |
358 | 350 |
|
359 | 351 |
hs = Holding.objects.filter(holder__in=holders).select_for_update() |
... | ... | |
369 | 361 |
for removing, source in [(True, sub_quota), (False, add_quota)]: |
370 | 362 |
for (holder, resource, |
371 | 363 |
quantity, capacity, |
372 |
import_limit, export_limit) in source:
|
|
364 |
) in source: |
|
373 | 365 |
|
374 | 366 |
try: |
375 | 367 |
h = holdings[(holder, resource)] |
... | ... | |
393 | 385 |
invert=removing) |
394 | 386 |
newp.capacity = _add(p.capacity if p else 0, capacity, |
395 | 387 |
invert=removing) |
396 |
newp.import_limit = _add(p.import_limit if p else 0, |
|
397 |
import_limit, invert=removing) |
|
398 |
newp.export_limit = _add(p.export_limit if p else 0, |
|
399 |
export_limit, invert=removing) |
|
400 |
|
|
401 |
new_values = [newp.capacity, |
|
402 |
newp.import_limit, newp.export_limit] |
|
403 |
if any(map(_isneg, new_values)): |
|
388 |
|
|
389 |
if _isneg(newp.capacity): |
|
404 | 390 |
append((holder, resource)) |
405 | 391 |
continue |
406 | 392 |
|
... | ... | |
466 | 452 |
hp = h.policy |
467 | 453 |
|
468 | 454 |
if not release: |
469 |
current = h.exporting |
|
470 |
limit = hp.export_limit |
|
471 |
if current + quantity > limit: |
|
472 |
m = ("Export limit reached for %s.%s" % (holder, resource)) |
|
473 |
raise ExportLimitError(m, |
|
474 |
source=holder, |
|
475 |
target=target, |
|
476 |
resource=resource, |
|
477 |
requested=quantity, |
|
478 |
current=current, |
|
479 |
limit=limit) |
|
480 |
|
|
481 | 455 |
limit = hp.quantity + h.imported - h.releasing |
482 | 456 |
unavailable = h.exporting - h.returned |
483 | 457 |
available = limit - unavailable |
... | ... | |
525 | 499 |
tp = th.policy |
526 | 500 |
|
527 | 501 |
if not release: |
528 |
limit = tp.import_limit |
|
529 |
current = th.importing |
|
530 |
if current + quantity > limit: |
|
531 |
m = ("Import limit reached for %s.%s" % (target, resource)) |
|
532 |
raise ImportLimitError(m, |
|
533 |
source=holder, |
|
534 |
target=target, |
|
535 |
resource=resource, |
|
536 |
requested=quantity, |
|
537 |
current=current, |
|
538 |
limit=limit) |
|
539 |
|
|
540 | 502 |
limit = tp.quantity + tp.capacity |
541 | 503 |
current = (+ th.importing + th.returning + tp.quantity |
542 | 504 |
- th.exported - th.released) |
... | ... | |
600 | 562 |
'resource': provision.resource, |
601 | 563 |
'source_quantity': s_policy.quantity, |
602 | 564 |
'source_capacity': s_policy.capacity, |
603 |
'source_import_limit': s_policy.import_limit, |
|
604 |
'source_export_limit': s_policy.export_limit, |
|
605 | 565 |
'source_imported': s_holding.imported, |
606 | 566 |
'source_exported': s_holding.exported, |
607 | 567 |
'source_returned': s_holding.returned, |
608 | 568 |
'source_released': s_holding.released, |
609 | 569 |
'target_quantity': t_policy.quantity, |
610 | 570 |
'target_capacity': t_policy.capacity, |
611 |
'target_import_limit': t_policy.import_limit, |
|
612 |
'target_export_limit': t_policy.export_limit, |
|
613 | 571 |
'target_imported': t_holding.imported, |
614 | 572 |
'target_exported': t_holding.exported, |
615 | 573 |
'target_returned': t_holding.returned, |
Also available in: Unified diff