Esempio n. 1
0
    def save(self, request):
        name = self.cleaned_data['name']
        description = self.cleaned_data['description']
        pub_date = self.cleaned_data['pub_date']
        end_bets_date = self.cleaned_data['end_bets_date']
        end_date = self.cleaned_data.get('end_date')
        forbidden = self.cleaned_data['forbidden']

        account = Account(name=name, type='b')
        account.save()

        new_bet = ChoiceBet(owner=request.user.profile,
                            name=name,
                            description=description,
                            end_bets_date=end_bets_date,
                            end_date=end_date,
                            account=account)
        try:
            choices = create_choices(request, new_bet)
        except ValidationError:
            raise

        new_bet.save()
        for choice in choices:
            choice.save()

        for forbidden_user in forbidden:
            new_bet.forbidden.add(forbidden_user)

        if pub_date is not None:
            new_bet.pub_date = pub_date
            new_bet.save()

        return new_bet
Esempio n. 2
0
    def save(self, user):
        name = self.cleaned_data['name']
        description = self.cleaned_data['description']
        pub_date = self.cleaned_data['pub_date']
        end_bets_date = self.cleaned_data['end_bets_date']
        time_period_start = self.cleaned_data['time_period_start']
        time_period_end = self.cleaned_data['time_period_end']
        forbidden = self.cleaned_data['forbidden']

        account = Account(name=name, type='b')
        account.save()

        new_bet = DateBet.objects.create(
            owner=user,
            name=name,
            description=description,
            end_bets_date=end_bets_date,
            time_period_start=time_period_start,
            time_period_end=time_period_end,
            account=account
        )

        for forbidden_user in forbidden:
            new_bet.forbidden.add(forbidden_user)

        if pub_date is not None:
            new_bet.pub_date = pub_date
            new_bet.save()

        return new_bet
Esempio n. 3
0
    def save(self, user):
        name = self.cleaned_data['name']
        description = self.cleaned_data['description']
        pub_date = self.cleaned_data['pub_date']
        end_bets_date = self.cleaned_data['end_bets_date']
        time_period_start = self.cleaned_data['time_period_start']
        time_period_end = self.cleaned_data['time_period_end']
        forbidden = self.cleaned_data['forbidden']

        account = Account(name=name, type='b')
        account.save()

        new_bet = DateBet.objects.create(owner=user,
                                         name=name,
                                         description=description,
                                         end_bets_date=end_bets_date,
                                         time_period_start=time_period_start,
                                         time_period_end=time_period_end,
                                         account=account)

        for forbidden_user in forbidden:
            new_bet.forbidden.add(forbidden_user)

        if pub_date is not None:
            new_bet.pub_date = pub_date
            new_bet.save()

        return new_bet
Esempio n. 4
0
 def test_income_calulation(self):
     today = datetime.date.today()
     to_date=today
     from_date = today.replace(month=1,day=1)
     from django.contrib.auth.models import User
     user_id = User.objects.get(username='******').id
     income =  Account.sum_by_type(user_id=user_id, account_type='income', from_date=from_date, to_date=to_date)
     print "i"*100, income
     _income =  Account.sum_by_type_old(user_id=user_id, account_type='income', from_date=from_date, to_date=to_date)
     self.assertEqual(income, _income)
Esempio n. 5
0
 def save(self, *args, **kwargs):
     if not self.ledger_id:
         ledger = Account(name=self.name)
         ledger.save()
         self.ledger = ledger
     else:
         if not self.ledger.name == self.name:
             self.ledger.name = self.name
             self.ledger.save()
     super(Item, self).save(*args, **kwargs)
Esempio n. 6
0
    def save(self, commit=True):
        user = super(SignupForm, self).save(commit=False)
        user.email = self.cleaned_data['email']
        if commit:
            user.save()

        account = Account(name=user.username, type='p')
        account.save(commit)
        profile = Profile(user=user, account=account)
        profile.save(commit)
        return user
    def create(self, validated_data):
        account = validated_data.pop('account')
        code = account.get('code')
        current_dr = account.get('current_dr')
        current_cr = account.get('current_cr')
        # site_id = validated_data.pop('site').get('id')
        bank = Bank.objects.create(**validated_data)

        if bank.account:
            account = bank.account
            account.code = code
            account.current_dr = current_dr
            account.current_cr = current_cr
            account.save()
        else:
            account = Account(name=bank.name, code=code, current_dr=current_dr, current_cr=current_cr)
            account.save()
            bank.account = account
        bank.save()
        return bank
    def create(self, validated_data):
        account = validated_data.pop('account')
        code = account.get('code')
        current_dr = account.get('current_dr')
        current_cr = account.get('current_cr')
        # site_id = validated_data.pop('site').get('id')
        vendor = Vendor.objects.create(**validated_data)

        if vendor.account:
            account = vendor.account
            account.code = code
            account.current_dr = current_dr
            account.current_cr = current_cr
            account.save()
        else:
            account = Account(name=vendor.name, code=code, current_dr=current_dr, current_cr=current_cr)
            account.save()
            vendor.account = account
        vendor.save()
        return vendor
Esempio n. 9
0
 def save(self, *args, **kwargs):
     if self.pk is None:
         account = Account(code=self.ac_no[-10:], name=self.bank_name + ' Account (' + str(self.ac_no) + ' )')
         account.company = self.company
         account.add_category('Bank Account')
         account.save()
         self.account = account
     super(BankAccount, self).save(*args, **kwargs)
    def update(self, instance, validated_data):
        bank = Bank.objects.get(pk=instance.id)
        bank.name = validated_data.pop('name')
        bank.address = validated_data.pop('address')
        bank.phone_no = validated_data.pop('phone_no')
        bank.save()
        account = validated_data.pop('account')
        code = account.get('code')
        current_dr = account.get('current_dr')
        current_cr = account.get('current_cr')

        if bank.account:
            account = bank.account
            account.code = code
            account.name = bank.name
            account.current_dr = current_dr
            account.current_cr = current_cr
            account.save()
        else:
            account = Account(name=bank.name, code=code, current_dr=current_dr, current_cr=current_cr)
            account.save()
            bank.account = account
            bank.save()
        return bank
    def update(self, instance, validated_data):
        vendor = Vendor.objects.get(pk=instance.id)
        vendor.name = validated_data.pop('name')
        vendor.address = validated_data.pop('address')
        vendor.phone_no = validated_data.pop('phone_no')
        vendor.save()
        account = validated_data.pop('account')
        code = account.get('code')
        current_dr = account.get('current_dr')
        current_cr = account.get('current_cr')

        if vendor.account:
            account = vendor.account
            account.name = vendor.name
            account.code = code
            account.current_dr = current_dr
            account.current_cr = current_cr
            account.save()
        else:
            account = Account(name=vendor.name, code=code, current_dr=current_dr, current_cr=current_cr)
            account.save()
            vendor.account = account
        vendor.save()
        return vendor
Esempio n. 12
0
    def save(self, request):
        name = self.cleaned_data['name']
        description = self.cleaned_data['description']
        pub_date = self.cleaned_data['pub_date']
        end_bets_date = self.cleaned_data['end_bets_date']
        end_date = self.cleaned_data.get('end_date')
        forbidden = self.cleaned_data['forbidden']

        account = Account(name=name, type='b')
        account.save()

        new_bet = ChoiceBet(
            owner=request.user.profile,
            name=name,
            description=description,
            end_bets_date=end_bets_date,
            end_date=end_date,
            account=account
        )
        try:
            choices = create_choices(request, new_bet)
        except ValidationError:
            raise

        new_bet.save()
        for choice in choices:
            choice.save()

        for forbidden_user in forbidden:
            new_bet.forbidden.add(forbidden_user)

        if pub_date is not None:
            new_bet.pub_date = pub_date
            new_bet.save()

        return new_bet
Esempio n. 13
0
 def save(self, *args, **kwargs):
     if self.pk is None:
         #dummy_account = Account.objects.all()[:1][0]
         #self.account = dummy_account
         super(Employee, self).save(*args, **kwargs)
         account = Account(code='13-0001-' + str(self.id), name=self.name)
         account.company = self.company
         account.add_category('Employee')
         account.save()
         self.account = account
     super(Employee, self).save(*args, **kwargs)
Esempio n. 14
0
 def save(self, *args, **kwargs):
     if not self.account_id:
         account = Account(name=self.name)
         account.save()
         self.account = account
     super(Party, self).save(*args, **kwargs)