/
data_helper.py
62 lines (54 loc) · 1.82 KB
/
data_helper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env python
# -*- encoding: utf-8
# vim: ai ts=4 sts=4 et sw=4 nu
# maintainer: Fad
from __future__ import (
unicode_literals, absolute_import, division, print_function)
from datetime import datetime
from models import Report, Product, Store, Payment
from configuration import Config
def warning_of_prod():
""""""
list_w = []
for store in Store.all():
for prod in Product.all():
report = last_report_store_prod(store.name, prod.name)
try:
if report.remaining < Config.nb_warning:
list_w.append(report)
except AttributeError:
pass
return list_w
def check_befor_update_data(reports):
print("check_befor_update_data")
for report in reports:
list_error = []
if report.last_report:
remaining = report.last_report.remaining
else:
remaining = 0
for rpt in report.next_rpts():
if rpt.type_ == Report.E:
remaining += rpt.qty
if rpt.type_ == Report.S:
remaining -= rpt.qty
if remaining < 0:
return rpt, remaining
break
return None, ""
def check_befor_update_payment(pay):
balance = pay.balance
lt = []
for rpt in pay.next_rpts():
previous_balance = int(rpt.last_balance_payment())
if rpt.type_ == Payment.CREDIT:
balance = previous_balance + int(rpt.credit)
lt.append(
"{} = last {} + {}".format(balance, previous_balance, rpt.credit))
if rpt.type_ == Payment.DEBIT:
balance = previous_balance - int(rpt.debit)
lt.append(
"{} = last {} - {}".format(balance, previous_balance, rpt.debit))
# if balance < 0:
# return False
return True