Esempio n. 1
0
def add(request):
    if not check_user_login(request):
        return login(request)

    user = request.session.get('user')

    moneyiousertype_list = MoneyService().getMoneyIOUserTypeList(user)
    moneyiousertype_count = MoneyService().getMoneyIOUserTypeCount(user)
    BudgetDetailFormSet = formset_factory(BudgetDetailForm,
                                          max_num=moneyiousertype_count)
    if request.method == 'POST':
        budgetform = BudgetForm(request.POST)
        budgetdetailformset = BudgetDetailFormSet(request.POST)
        if budgetform.is_valid() and budgetdetailformset.is_valid():
            name = budgetform.cleaned_data['name']
            begindate = budgetform.cleaned_data['begindate']
            enddate = budgetform.cleaned_data['enddate']
            currency = AccountService().getCurrency(
                budgetform.cleaned_data['currency'])
            description = budgetform.cleaned_data['description']
            budget = BudgetService().addBudget(name, begindate, enddate,
                                               currency, description, user)

            for budgetdetailform in budgetdetailformset.forms:
                moneyiousertypeid = budgetdetailform.cleaned_data[
                    'moneyiousertypeid']
                moneyiousertype = MoneyService().getMoneyIOUserType(
                    moneyiousertypeid, user)
                money = budgetdetailform.cleaned_data['money']
                if money > 0.0:
                    BudgetService().addBudgetDetail(budget, moneyiousertype,
                                                    money)
            return HttpResponseRedirect('/budget/')

    else:
        budgetform = BudgetForm()

        formsetinitdata = [{
            'moneyiousertypeid': moneyiousertype.id,
            'moneyiousertypename': moneyiousertype.name,
            'money': 0.0
        } for moneyiousertype in moneyiousertype_list]
        budgetdetailformset = BudgetDetailFormSet(initial=formsetinitdata)

    page_title = ugettext('Add Budget')
    pageinfo = PageInfo(page_menu_name='Budget',
                        user=user,
                        page_title=page_title)
    helptext_list = AdminService().getCategoryHelpTextList('Budget')
    form_action_url = '/budget/add/'
    return render_to_response(
        'budget_add_edit.html', {
            'helptext_list': helptext_list,
            'form_action_url': form_action_url,
            'budgetform': budgetform,
            'budgetdetailformset': budgetdetailformset,
            'user': user,
            'pageinfo': pageinfo
        })
Esempio n. 2
0
def moneyiosystype_edit(request, id):
    if not check_user_is_admin(request):
        return HttpResponseRedirect('/notadmin/')
    
    user = request.session.get('user')
    if request.method == 'POST':
        form = MoneyIOSysTypeForm(data=request.POST)
        if form.is_valid(): 
            name = form.cleaned_data['name']
            isio = int(form.cleaned_data['isio'])
            AdminService().editMoneyIOSysType(id, name, isio)
            return HttpResponseRedirect('/admin/')
    else:                
        moneyiosystype = MoneyService().getMoneyIOSysType(id)
        if moneyiosystype:
            form = MoneyIOSysTypeForm(initial=
                               {'name': moneyiosystype.name, 
                                'isio':moneyiosystype.isio
                                })
        else:
            form = MoneyIOSysTypeForm()

    page_title=ugettext('Edit Money Income and Expense System Type')
    form_action_url='/admin/moneyiosystype/edit/' + id
    page_module='Admin'
    return render_to_response('common_add_edit.html', {'page_title':page_title, 
                                                       'form_action_url': form_action_url, 
                                                       'form': form, 
                                                       'user':user,
                                                       'page_module' : page_module
                                                       })
Esempio n. 3
0
    def clean(self):
        cleaned_data = self.cleaned_data

        begindate = cleaned_data.get('begindate')
        enddate = cleaned_data.get('enddate')

        if begindate and enddate and begindate >= enddate:
            raise forms.ValidationError(
                ugettext('The begin data should be earlier than end date'))

        isautogenmoneyio = cleaned_data.get('isautogenmoneyio')
        money = cleaned_data.get('money')
        if isautogenmoneyio and money <= 0:
            raise forms.ValidationError(
                ugettext('The amount should be more than zero'))

        account_id = cleaned_data.get('account')
        account = AccountService().getAccount(account_id, self.user)
        moneyiousertype_id = cleaned_data.get('moneyiousertype')
        moneyiousertype = MoneyService().getMoneyIOUserType(
            moneyiousertype_id, self.user)

        if (isautogenmoneyio and account and moneyiousertype
                and moneyiousertype.isio == -1 and money > 0
                and account.totalmoney < money):
            totalmoney = account.totalmoney
            raise forms.ValidationError(
                ugettext(
                    'The account total amount (%(totalmoney)10.2f) is not enough to expense'
                ) % {'totalmoney': totalmoney})
        return cleaned_data
Esempio n. 4
0
 def getModelList(self, model_name, filter_dict, orderby, pagesize, pagecount, user):
     if model_name == 'account':
         return AccountService().getAccountList(filter_dict, orderby, pagesize, pagecount, user)
     elif model_name == 'budget':
         return BudgetService().getBudgetList(filter_dict, orderby, pagesize, pagecount, user)
     elif model_name == 'alarm':
         return AlarmService().getAlarmList(filter_dict, orderby, pagesize, pagecount, user)
     elif model_name == 'object':
         return ObjectService().getObjectList(filter_dict, orderby, pagesize, pagecount, user)
     elif model_name == 'moneyio':
         return MoneyService().getMoneyIOList(filter_dict, orderby, pagesize, pagecount, user)
     elif model_name == 'moneybl':
         return MoneyService().getMoneyBLList(filter_dict, orderby, pagesize, pagecount, user)
     elif model_name == 'moneytransfer':
         return MoneyService().getMoneyTransferList(filter_dict, orderby, pagesize, pagecount, user)
     elif model_name == 'usermessage':
         return UserService().getMessageList(filter_dict, orderby, pagesize, pagecount, user)
Esempio n. 5
0
 def __init__(self, id, user, *args, **kwargs):
     super(AlarmForm, self).__init__(*args, **kwargs)
     self.id = id
     self.user = user
     self.fields['account'].choices = AccountService().getAccountChoices(
         self.user)
     self.fields['moneyiousertype'].choices = MoneyService(
     ).getMoneyIOUserTypeChoices(self.user)
     self.fields['currency'].choices = AccountService().getCurrencyChoices()
     if 'data' in kwargs:
         self.data = kwargs['data']
Esempio n. 6
0
    def executeAlarm(self, alarm):
        today = datetime.date.today()
        if (alarm and (alarm.begindate == None or alarm.begindate <= today)
                and (alarm.enddate == None or alarm.enddate >= today)):

            currenttime = datetime.datetime.now()
            nextalarmtime = currenttime
            if alarm.latestalarmtime:
                latestalarmtime = alarm.latestalarmtime
            else:
                latestalarmtime = alarm.createtime

            cycletype = alarm.cycletype
            cyclevalue = alarm.cyclevalue

            if cycletype == 'Year':
                nextalarmtime = common.datetimeutil.datetime_offset_by_month(
                    latestalarmtime, cyclevalue * 12)
            elif cycletype == 'Month':
                nextalarmtime = common.datetimeutil.datetime_offset_by_month(
                    latestalarmtime, cyclevalue)
            elif cycletype == 'Week':
                nextalarmtime = latestalarmtime + datetime.timedelta(
                    days=7 * cyclevalue)
            elif cycletype == 'Day':
                nextalarmtime = latestalarmtime + datetime.timedelta(
                    days=1 * cyclevalue)

            if nextalarmtime <= currenttime:
                UserService().createMessageByAlarm(alarm)
                alarm.latestalarmtime = currenttime
                alarm.put()

                if alarm.isautogenmoneyio:
                    moneyiotemplate_list = MoneyIOTemplate.all().filter(
                        'alarm', alarm)
                    if moneyiotemplate_list:
                        moneyiotemplate = moneyiotemplate_list[0]
                        if (moneyiotemplate
                                and (moneyiotemplate.moneyiotype.isio == 1 or
                                     (moneyiotemplate.moneyiotype.isio == -1
                                      and moneyiotemplate.account.totalmoney >=
                                      moneyiotemplate.money))):
                            MoneyService().addMoneyIO(
                                account=moneyiotemplate.account,
                                happentime=datetime.date.today(),
                                moneyiotype=moneyiotemplate.moneyiotype,
                                money=moneyiotemplate.money,
                                currency=moneyiotemplate.currency,
                                description='Created by alarm ' + alarm.name,
                                user=moneyiotemplate.user,
                                alarm=alarm)
Esempio n. 7
0
    def addAlarm(self, name, account, begindate, enddate, cycletype,
                 cyclevalue, isautogenmoneyio, moneyiousertype, money,
                 currency, description, user):
        alarm = Alarm(name=name)
        alarm.account = account
        alarm.begindate = begindate
        alarm.enddate = enddate
        alarm.cycletype = cycletype
        alarm.cyclevalue = cyclevalue
        alarm.isautogenmoneyio = isautogenmoneyio
        alarm.moneyiousertype = moneyiousertype
        alarm.money = money
        alarm.currency = currency
        alarm.description = description
        if user:
            alarm.user = user
        alarm.put()

        MoneyService().createMoneyIOTemplate(alarm)
Esempio n. 8
0
def add(request):
    if not check_user_login(request):
        return login(request)

    user = request.session.get('user')
    if request.method == 'POST':
        form = AlarmForm(data=request.POST, user=user, id=None)
        if form.is_valid():
            name = form.cleaned_data['name']
            account = AccountService().getAccount(form.cleaned_data['account'],
                                                  user)
            begindate = form.cleaned_data['begindate']
            enddate = form.cleaned_data['enddate']
            cycletype = form.cleaned_data['cycletype']
            cyclevalue = form.cleaned_data['cyclevalue']
            isautogenmoneyio = form.cleaned_data['isautogenmoneyio']
            moneyiousertype = MoneyService().getMoneyIOUserType(
                form.cleaned_data['moneyiousertype'], user)
            money = form.cleaned_data['money']
            currency = AccountService().getCurrency(
                form.cleaned_data['currency'])
            description = form.cleaned_data['description']
            AlarmService().addAlarm(name, account, begindate, enddate,
                                    cycletype, cyclevalue, isautogenmoneyio,
                                    moneyiousertype, money, currency,
                                    description, user)
            return HttpResponseRedirect('/alarm/')
    else:
        form = AlarmForm(user=user, id=None)

    pageinfo = PageInfo(page_menu_name='Alarm',
                        user=user,
                        page_title=ugettext('Add Alarm'))
    helptext_list = AdminService().getCategoryHelpTextList('Alarm')
    form_action_url = '/alarm/add/'
    return render_to_response(
        'common_add_edit.html', {
            'pageinfo': pageinfo,
            'helptext_list': helptext_list,
            'form_action_url': form_action_url,
            'form': form,
            'user': user
        })
Esempio n. 9
0
def detail_data(request, id):
    if not check_user_login(request):
        return login(request)

    user = request.session.get('user')
    budget = BudgetService().getBudget(id, user)
    if budget:
        budgetdetail_list = BudgetService().getBudgetDetailList(budget)
        filter_dict = {
            'happentime >=': budget.begindate,
            'happentime <=': budget.enddate
        }
        moneystat = MoneyService().getMoneyStat(filter_dict, budget.currency,
                                                user)
        for budgetdetail in budgetdetail_list:
            BudgetService().updateBudgetDetailActualMoney(
                budgetdetail, moneystat)
        jsondata = BudgetService().encode(budgetdetail_list)
        return HttpResponse(JSONEncoder().encode(jsondata))
    else:
        return HttpResponse('')
Esempio n. 10
0
def index(request):
    if not check_user_login(request):
        return login(request)

    helptext_list = AdminService().getCategoryHelpTextList('Home')
    user = request.session.get('user', None)
    pageinfo = PageInfo(page_menu_name='Home', user=user)

    begindate = datetime.datetime.strptime(
        common.datetimeutil.get_firstday_month(), '%Y-%m-%d')
    enddate = datetime.date.today()

    moneyio_list = MoneyService().getMoneyIOList(None, '-createtime', 5, 1,
                                                 user)[0]

    account_list = AccountService().getAccountList(None, '-createtime', 5, 1,
                                                   user)[0]

    object_list = ObjectService().getObjectList(None, '-createtime', 5, 1,
                                                user)[0]

    budget_filter_dict = {'begindate >=': begindate, 'begindate <=': enddate}
    budget_list = BudgetService().getBudgetList(budget_filter_dict,
                                                '-begindate', 5, 1, user)[0]

    errormessage = request.session.get('errormessage', None)
    request.session['errormessage'] = None

    return render_to_response(
        'index.html', {
            'user': user,
            'helptext_list': helptext_list,
            'pageinfo': pageinfo,
            'moneyio_list': moneyio_list,
            'account_list': account_list,
            'object_list': object_list,
            'budget_list': budget_list,
            'errormessage': errormessage
        })
Esempio n. 11
0
 def initCoolUserData(self, user):
     moneyiousertype_list = MoneyService().getMoneyIOUserTypeList(user)
     if moneyiousertype_list == None or moneyiousertype_list.count() == 0:
         MoneyService().initMoneyIOUserTypeFromSystem(user)
Esempio n. 12
0
 def deleteMoneyIOSysType(self, id):
     moneyiosystype = MoneyService().getMoneyIOSysType(id)
     if moneyiosystype:
         moneyiosystype.delete()
Esempio n. 13
0
 def editMoneyIOSysType(self, id, name, isio):
     moneyiosystype = MoneyService().getMoneyIOSysType(id)
     if moneyiosystype:
         moneyiosystype.name = name
         moneyiosystype.isio = isio
         moneyiosystype.put()
Esempio n. 14
0
 def initCoolUserData(self, user):
     moneyiousertype_list = MoneyService().getMoneyIOUserTypeList(user)
     if moneyiousertype_list == None or moneyiousertype_list.count() == 0:
         MoneyService().initMoneyIOUserTypeFromSystem(user)
Esempio n. 15
0
def edit(request, id):
    if not check_user_login(request):
        return login(request)

    user = request.session.get('user')
    if request.method == 'POST':
        form = AlarmForm(data=request.POST, user=user, id=id)
        if form.is_valid():
            name = form.cleaned_data['name']
            account = AccountService().getAccount(form.cleaned_data['account'],
                                                  user)
            begindate = form.cleaned_data['begindate']
            enddate = form.cleaned_data['enddate']
            cycletype = form.cleaned_data['cycletype']
            cyclevalue = form.cleaned_data['cyclevalue']
            isautogenmoneyio = form.cleaned_data['isautogenmoneyio']
            moneyiousertype = MoneyService().getMoneyIOUserType(
                form.cleaned_data['moneyiousertype'], user)
            money = form.cleaned_data['money']
            currency = AccountService().getCurrency(
                form.cleaned_data['currency'])
            description = form.cleaned_data['description']
            AlarmService().editAlarm(id, name, account, begindate, enddate,
                                     cycletype, cyclevalue, isautogenmoneyio,
                                     moneyiousertype, money, currency,
                                     description, user)
            return HttpResponseRedirect('/alarm/')
    else:
        alarm = AlarmService().getAlarm(id, user)
        if alarm:
            alarm_account_id = None
            if alarm.account:
                alarm_account_id = alarm.account.id
            alarm_moneyiousertype_id = None
            if alarm.moneyiousertype:
                alarm_moneyiousertype_id = alarm.moneyiousertype.id
            form = AlarmForm(initial={
                'name': alarm.name,
                'account': alarm_account_id,
                'begindate': alarm.begindate,
                'enddate': alarm.enddate,
                'cycletype': alarm.cycletype,
                'cyclevalue': alarm.cyclevalue,
                'isautogenmoneyio': alarm.isautogenmoneyio,
                'moneyiousertype': alarm_moneyiousertype_id,
                'money': alarm.money,
                'currency': alarm.currency.id,
                'description': alarm.description,
            },
                             user=user,
                             id=id)
        else:
            return HttpResponseRedirect('/alarm/')

    page_title = ugettext('Edit Alarm')
    helptext_list = AdminService().getCategoryHelpTextList('Alarm')
    form_action_url = '/alarm/edit/' + id
    page_module = 'Alarm'
    return render_to_response(
        'common_add_edit.html', {
            'page_title': page_title,
            'helptext_list': helptext_list,
            'form_action_url': form_action_url,
            'form': form,
            'user': user,
            'page_module': page_module
        })