def test_func_add_history(self):
        history = PaymentHistory()

        data_wallet = dict(
            id=1,
            payment_id=self.PAYMENT_ID,
            hard_id=self.HARD_ID,
            name=self.TEST_STRING,
            user_id=self.USER_ID,
            discodes_id=self.DISCODES_ID,
            card_pan=self.CARD_PAN
        )
        wallet = PaymentWallet()
        wallet.__dict__.update(data_wallet)

        data_report = dict(
            term_id=self.TERM_ID,
            event_id=self.EVENT_ID,
            person_id=self.PERSON_ID,
            payment_id=self.FIRM_ID,
            firm_id=self.FIRM_ID,
            creation_date=date_helper.get_current_date(),
        )
        report = Report()
        report.__dict__.update(data_report)

        assert history.add_history(wallet, report)

        history.delete()
def alarm_manager():
    alarm_stack = AlarmStack.query.filter(AlarmStack.count != 0).all()
    for alarm in alarm_stack:
        term = Term.get_by_id(alarm.term_id)
        if not term:
            continue

        if not term.config_date:
            continue

        delta = date_helper.get_current_date(format=False) - term.config_date
        if delta.total_seconds() <= alarm.interval:
            continue

        alarm.count -= 1
        alarm.save()

        emails = alarm.decode_field(alarm.emails)
        term_info = Term.get_info_by_id(alarm.term_id)
        for email in emails:
            mail.send.delay(
                TermAlarmMessage,
                to=email,
                term=term_info)
        return True
    return False
Beispiel #3
0
 def __init__(self):
     self.status = self.STATUS_VALID
     self.wallet_status = self.STATUS_VALID
     self.type = self.TYPE_TIMEOUT
     self.creation_date = date_helper.get_current_date()
     self.name = u'Пользователь'
     self.manually_blocked = self.STATUS_VALID
Beispiel #4
0
 def __init__(self):
     self.lang = 'en'
     self.name = 'No name'
     self.premium = 0
     self.status = self.STATUS_GENERATED
     self.type = self.TYPE_FULL
     self.hard_type = self.DEFAULT_HARD_TYPE
     self.generated_date = date_helper.get_current_date()
Beispiel #5
0
 def __init__(self):
     self.lang = 'en'
     self.name = 'No name'
     self.premium = 0
     self.status = self.STATUS_GENERATED
     self.type = self.TYPE_FULL
     self.hard_type = self.DEFAULT_HARD_TYPE
     self.generated_date = date_helper.get_current_date()
Beispiel #6
0
 def __init__(self):
     self.term_id = 0
     self.status = self.STATUS_NEW
     self.system = self.SYSTEM_MPS
     self.type = self.TYPE_PAYMENT
     self.request_id = 0
     self.report_id = 0
     self.invoice_id = 0
     self.creation_date = date_helper.get_current_date()
 def __init__(self):
     self.term_id = 0
     self.status = self.STATUS_NEW
     self.system = self.SYSTEM_MPS
     self.type = self.TYPE_PAYMENT
     self.request_id = 0
     self.report_id = 0
     self.invoice_id = 0
     self.creation_date = date_helper.get_current_date()
Beispiel #8
0
 def __init__(self):
     self.discodes_id = 0
     self.name = 'My spot'
     self.type = self.TYPE_FULL
     self.blacklist = self.ACTIVE_OFF
     self.balance = 0
     self.user_id = 0
     self.creation_date = date_helper.get_current_date()
     self.status = self.STATUS_NOACTIVE
 def __init__(self):
     self.discodes_id = 0
     self.name = 'My spot'
     self.type = self.TYPE_FULL
     self.blacklist = self.ACTIVE_OFF
     self.balance = 0
     self.user_id = 0
     self.creation_date = date_helper.get_current_date()
     self.status = self.STATUS_NOACTIVE
Beispiel #10
0
    def save(self):
        if not self.registered_date and self.status == self.STATUS_REGISTERED:
            self.registered_date = date_helper.get_current_date()

        if not self.removed_date:
            if self.status == self.STATUS_REMOVED_USER or self.status == self.STATUS_REMOVED_SYS:
                self.removed_date = date_helper.get_current_date()

        if not self.url:
            self.get_url()

        if not self.code128:
            self.gen_code128()
            g.max_code128 = self.code128

        if not self.code:
            self.code = self.get_code(self.discodes_id)

        return BaseModel.save(self)
Beispiel #11
0
    def save(self):
        if not self.registered_date and self.status == self.STATUS_REGISTERED:
            self.registered_date = date_helper.get_current_date()

        if not self.removed_date:
            if self.status == self.STATUS_REMOVED_USER or self.status == self.STATUS_REMOVED_SYS:
                self.removed_date = date_helper.get_current_date()

        if not self.url:
            self.get_url()

        if not self.code128:
            self.gen_code128()
            g.max_code128 = self.code128

        if not self.code:
            self.code = self.get_code(self.discodes_id)

        return BaseModel.save(self)
Beispiel #12
0
 def test_report(self):
     data = dict(
         term_id=self.TERM_ID,
         event_id=self.PERSON_ID,
         person_id=self.EVENT_ID,
         payment_id=self.FIRM_ID,
         firm_id=self.FIRM_ID,
         creation_date=date_helper.get_current_date(),
     )
     self.model_test(Report, data)
Beispiel #13
0
    def select_term_list(firm_id, **kwargs):
        date_pattern = '%H:%M %d.%m.%y'

        order = kwargs['order'] if 'order' in kwargs and kwargs[
            'order'] else 'config_date'
        order_desc = kwargs['order_desc'] if 'order_desc' in kwargs else True
        limit = kwargs['limit'] if 'limit' in kwargs else 10
        page = kwargs['page'] if 'page' in kwargs else 1

        firm_term = FirmTerm.get_list_by_firm_id(firm_id)
        g.firm_term = firm_term

        query = Term.query.filter(Term.id.in_(firm_term))

        if order:
            if order_desc:
                query = query.order_by(desc(order))
            else:
                query = query.order_by(order)

        terms = query.paginate(page, limit, False).items

        result = []
        for term in terms:
            firm_general = FirmTerm.query.filter_by(term_id=term.id).first()

            seans_date = None
            seans_alarm = 0
            if term.config_date:
                delta = date_helper.get_current_date(
                    format=False) - term.config_date

                seans_alarm = delta.total_seconds() > Term.SEANS_ALARM

                seans_date = date_helper.from_utc(term.config_date, term.tz)
                seans_date = seans_date.strftime(date_pattern)
            data = dict(
                id=term.id,
                hard_id=term.hard_id,
                name=term.name,
                firm=firm_general.firm.name,
                status=int(term.status == Term.STATUS_VALID),
                seans_date=seans_date,
                seans_alarm=int(seans_alarm),
                tz=term.tz,
            )

            result.append(data)

        value = dict(
            result=result,
            count=query.count(),
        )

        return value
Beispiel #14
0
    def select_term_list(firm_id, **kwargs):
        date_pattern = '%H:%M %d.%m.%y'

        order = kwargs['order'] if 'order' in kwargs and kwargs[
            'order'] else 'config_date'
        order_desc = kwargs['order_desc'] if 'order_desc' in kwargs else True
        limit = kwargs['limit'] if 'limit' in kwargs else 10
        page = kwargs['page'] if 'page' in kwargs else 1

        firm_term = FirmTerm.get_list_by_firm_id(firm_id)
        g.firm_term = firm_term

        query = Term.query.filter(Term.id.in_(firm_term))

        if order:
            if order_desc:
                query = query.order_by(desc(order))
            else:
                query = query.order_by(order)

        terms = query.paginate(page, limit, False).items

        result = []
        for term in terms:
            firm_general = FirmTerm.query.filter_by(term_id=term.id).first()

            seans_date = None
            seans_alarm = 0
            if term.config_date:
                delta = date_helper.get_current_date(
                    format=False) - term.config_date

                seans_alarm = delta.total_seconds() > Term.SEANS_ALARM

                seans_date = date_helper.from_utc(term.config_date, term.tz)
                seans_date = seans_date.strftime(date_pattern)
            data = dict(
                id=term.id,
                hard_id=term.hard_id,
                name=term.name,
                firm=firm_general.firm.name,
                status=int(term.status == Term.STATUS_VALID),
                seans_date=seans_date,
                seans_alarm=int(seans_alarm),
                tz=term.tz,
            )

            result.append(data)

        value = dict(
            result=result,
            count=query.count(),
        )

        return value
Beispiel #15
0
def api_set_callback(term_id, action, version=None):
    """Сообщение об удачной загрузки настроек или черного списка"""

    VALID_ACTITON = (
        'config',
        'blacklist'
    )
    if not action in VALID_ACTITON:
        abort(405)

    term = Term.get_valid_term(term_id)

    if term is None:
        abort(404)

    if action == 'config':
        term.config_date = date_helper.get_current_date()
        AlarmStack.reset_count(term.id)
    elif action == 'blacklist':
        term.blacklist_date = date_helper.get_current_date()

    term.save()

    return set_message('success', 'Success', 201)
    def report_generate(task):
        log = logging.getLogger('task')

        result = ReportResult(task)
        if not result.task:
            log.error('Not found task')
            return False

        if not result.interval:
            log.error('Faled interval')
            return False

        sender_task = ReportSenderTask()

        html_method_name = "_get_%s" % result.type['meta']
        excel_method_name = "_get_%s_xls" % result.type['meta']
        attibute = ReportSenderTask.__dict__
        if html_method_name not in attibute:
            return False
        if excel_method_name not in attibute:
            return False

        result = getattr(sender_task, "_get_%s" % result.type['meta'])(result)
        if result.data and result.all['summ'] != 0:

            attach = None
            if task.excel == ReportStack.EXCEL_YES:
                attach = getattr(
                    sender_task, "_get_%s_xls" %
                    result.type['meta'])(result)

            emails = task.decode_field(task.emails)
            for email in emails:
                mail.send.delay(
                    ReportMessage,
                    to=email,
                    attach=attach,
                    result=result,
                    template=result.type['meta'])

        if task.interval == ReportStack.INTERVAL_ONCE:
            task.delete()
        else:
            task.launch_date = date_helper.get_current_date()
            task.save()

        return True
    def rechek_manager():
        loyalties_list = []
        loyalties = PaymentLoyalty.query.filter(
            PaymentLoyalty.stop_date > date_helper.get_current_date()).all()

        for loyalty in loyalties:
            if loyalty.id in loyalties_list:
                continue
            loyalties_list.append(loyalty.id)

        element_keys = PaymentLoyaltySharing.query.filter(
            PaymentLoyaltySharing.control_value.__ne__(None), PaymentLoyaltySharing.loyalty_id.in_(loyalties_list)).all()

        if not element_keys:
            return False

        for key in element_keys:
            SocSharingTask.recheck_condition.delay(key)

        return True
Beispiel #18
0
    def rechek_manager():
        loyalties_list = []
        loyalties = PaymentLoyalty.query.filter(
            PaymentLoyalty.stop_date > date_helper.get_current_date()).all()

        for loyalty in loyalties:
            if loyalty.id in loyalties_list:
                continue
            loyalties_list.append(loyalty.id)

        element_keys = PaymentLoyaltySharing.query.filter(
            PaymentLoyaltySharing.control_value.__ne__(None),
            PaymentLoyaltySharing.loyalty_id.in_(loyalties_list)).all()

        if not element_keys:
            return False

        for key in element_keys:
            SocSharingTask.recheck_condition.delay(key)

        return True
Beispiel #19
0
def api_upload_report(term_id, report_datetime):
    """Прием и сохранение отчета"""

    if not len(report_datetime) == 13:
        abort(400)

    if not re.search('\d{6}_\d{6}', str(report_datetime)):
        abort(400)

    term = Term.get_valid_term(term_id)

    if term is None:
        abort(400)

    file = request.stream.read()
    filename = "%s/%s_%s" % (
        app.config['REPORT_TMP_PACH'],
        str(term_id),
        str(report_datetime))

    if not request.headers.get('Content-MD5'):
        abort(400)

    if request.headers.get('Content-MD5') != hash_helper.get_content_md5(file):
        abort(400)

    if file:
        with open(filename, 'w') as f:
            f.write(file)
    else:
        abort(400)

    term.report_date = date_helper.get_current_date()
    term.save()

    ReportParserTask.report_manager.delay(filename)

    return set_message('success', hash_helper.get_content_md5(file), 201)
Beispiel #20
0
 def __init__(self):
     self.lock = self.LOCK_FREE
     self.creation_date = date_helper.get_current_date()
Beispiel #21
0
 def __init__(self):
     self.limit = 0
     self.balance = 0
     self.interval = self.INTERVAL_MONTH
     self.creation_date = date_helper.get_current_date()
     self.status = self.STATUS_ACTIVE
Beispiel #22
0
 def __init__(self):
     self.group = self.GROUP_DEFAULT
     self.status = self.STATUS_NOACTIVE
     self.creation_date = date_helper.get_current_date()
Beispiel #23
0
 def __init__(self):
     self.lang = "en"
     self.creation_date = date_helper.get_current_date()
     self.status = self.STATUS_NOACTIVE
Beispiel #24
0
 def __init__(self):
     self.creation_date = date_helper.get_current_date()
Beispiel #25
0
 def __init__(self):
     self.creation_date = date_helper.get_current_date()
 def __init__(self):
     self.generated_date = date_helper.get_current_date()
     self.status = self.STATUS_GENERATED
 def __init__(self):
     self.limit = 0
     self.balance = 0
     self.interval = self.INTERVAL_MONTH
     self.creation_date = date_helper.get_current_date()
     self.status = self.STATUS_ACTIVE
 def __init__(self):
     self.generated_date = date_helper.get_current_date()
     self.status = self.STATUS_GENERATED
 def __init__(self):
     self.rules = self.RULE_FIXED
     self.creation_date = date_helper.get_current_date()
Beispiel #30
0
 def __init__(self):
     self.group = self.GROUP_DEFAULT
     self.status = self.STATUS_NOACTIVE
     self.creation_date = date_helper.get_current_date()
Beispiel #31
0
 def __init__(self):
     self.rules = self.RULE_FIXED
     self.creation_date = date_helper.get_current_date()