Permalink
Browse files

split the registerinvoiceinaccounting in two parts for better readabi…

…lity fixed some bugs in the register invoice method ... but still not final yet
  • Loading branch information...
1 parent 71fb970 commit e418bdf6a8362352977c885481801722b19085e5 @scaphilo committed Dec 30, 2012
Showing with 25 additions and 30 deletions.
  1. +3 −3 accounting/locale/de/LC_MESSAGES/django.po
  2. +9 −0 accounting/models.py
  3. +13 −27 crm/models.py
@@ -159,17 +159,17 @@ msgstr "Buchungen"
#: const/accountTypeChoices.py:6
msgid "Earnings"
-msgstr "Erflog (Einnahmen)"
+msgstr "Ertrag (Einnahmen)"
#: const/accountTypeChoices.py:7
msgid "Spendings"
msgstr "Aufwand (Ausgaben)"
#: const/accountTypeChoices.py:8
msgid "Liabilities"
-msgstr "Passiva"
+msgstr "Passiva (Schulden)"
#: const/accountTypeChoices.py:9
msgid "Assets"
-msgstr "Aktiva"
+msgstr "Aktiva (Vermögen)"
View
@@ -20,6 +20,15 @@ class AccountingPeriod(models.Model):
begin = models.DateField(verbose_name=_("Begin"))
end = models.DateField(verbose_name=_("End"))
+ @staticmethod
+ def getCurrentValidAccountingPeriod():
+ currentValidAccountingPeriod = None
+ for accountingPeriod in AccountingPeriod.objects.all():
+ if accountingPeriod.begin < date.today() and accountingPeriod.end > date.today():
+ return accountingPeriod
+ if currentValidAccountingPeriod == None:
+ raise NoFeasableAccountingPeriodFound()
+
def createPDF(self, deliveryorder):
XMLSerializer = serializers.get_serializer("xml")
xml_serializer = XMLSerializer()
View
@@ -370,7 +370,6 @@ def createInvoice(self):
invoice.payableuntil = date.today()+timedelta(days=self.customer.defaultCustomerBillingCycle.timeToPaymentDate)
invoice.dateofcreation = date.today().__str__()
invoice.customerBillingCycle = self.customer.defaultCustomerBillingCycle
-# TODO: today is not correct it has to be replaced
invoice.save()
try:
quotePositions = SalesContractPosition.objects.filter(contract=self.id)
@@ -464,40 +463,27 @@ def registerinvoiceinaccounting(self, request):
dictprices = dict()
dicttax = dict()
exists = False
- currentValidAccountingPeriod = None
- for accountingPeriod in accounting.models.AccountingPeriod.objects.all():
- if accountingPeriod.begin < date.today() and accountingPeriod.end > date.today():
- currentValidAccountingPeriod = accountingPeriod
- break
- if currentValidAccountingPeriod == None:
- raise NoFeasableAccountingPeriodFound()
+ currentValidAccountingPeriod = accounting.models.AccountingPeriod.getCurrentValidAccountingPeriod()
activaaccount = accounting.models.Account.objects.filter(isopeninterestaccount=True)
for position in list(SalesContractPosition.objects.filter(contract=self.id)):
profitaccount = position.product.accoutingProductCategorie.profitAccount
- for dictprice in dictprices:
- if (dictprice.id == profitaccount.id):
- exists = True
- if exists:
- dictprices[profitaccount] += position.lastCalculatedPrice
- dicttax[profitaccount] += position.lastCalculatedTax
- else:
- dictprices[profitaccount] = position.lastCalculatedPrice
- dicttax[profitaccount] = position.lastCalculatedTax
+ dictprices[profitaccount] = position.lastCalculatedPrice
+ dicttax[profitaccount] = position.lastCalculatedTax
for booking in accounting.models.Booking.objects.filter(accountingPeriod=currentValidAccountingPeriod):
if booking.bookingReference == self:
raise InvoiceAlreadyRegistered()
for profitaccount, amount in dictprices.iteritems():
- booking = accounting.models.Booking()
- booking.toAccount = activaaccount[0]
- booking.fromAccount = profitaccount
- booking.bookingReference = self
- booking.accountingPeriod = currentValidAccountingPeriod
- booking.bookingDate = date.today().__str__()
- booking.staff = request.user
- booking.amount = amount
- booking.lastmodifiedby = request.user
- booking.save()
+ booking = accounting.models.Booking()
+ booking.toAccount = activaaccount[0]
+ booking.fromAccount = profitaccount
+ booking.bookingReference = self
+ booking.accountingPeriod = currentValidAccountingPeriod
+ booking.bookingDate = date.today().__str__()
+ booking.staff = request.user
+ booking.amount = amount
+ booking.lastmodifiedby = request.user
+ booking.save()
def registerpaymentinaccounting(self, request, paymentaccount, amount, date):
activaaccount = accounting.Account.objects.filter(isopeninterestaccount=True)

0 comments on commit e418bdf

Please sign in to comment.