def calculateValue(self, document):
     value = BigDecimal(0)
     for position in document.getPositions():
         if document.getType() == "CHARGING":
             value = value.add(position.getValue().multiply(BigDecimal(-1)))
         else:
             value = value.add(position.getValue())
     return value
Пример #2
0
 def collectItems(self):
     output = []
     elements = self._possession.getElements()
     elements = sorted(
         elements,
         key=lambda item: item.getGroup().getValue() + item.getName())
     lastGroupId = elements[0].getGroup().getId()
     groupTotal = BigDecimal(0)
     groupItems = 0
     for element in elements:
         if element.getGroup().getId() != lastGroupId:
             if groupItems > 1:
                 self.createTotalLine(output, groupTotal)
                 groupTotal = BigDecimal(0)
             self.createEmptyLine(output)
             groupItems = 0
             lastGroupId = element.getGroup().getId()
             groupTotal = BigDecimal(0)
         item = dict([])
         item['group'] = element.getGroup().getValue()
         item['element'] = element.getName()
         value = self.calculateValue(element)
         item['value'] = value
         groupTotal = groupTotal.add(value)
         self._total = self._total.add(value)
         groupItems += 1
         output.append(item)
     self.createTotalLine(output, groupTotal)
     self.createEmptyLine(output)
     self.createTotalLine(output, self._total)
     return output
 def getStartBalance(self):
     balance = BigDecimal(0)
     for zpk in self._possession.getZpks():
         balance = balance.add(
             BigDecimal(zpk.getCurrentBalance().getStartCredit() -
                        zpk.getCurrentBalance().getStartDebit()).setScale(
                            2, RoundingMode.HALF_UP))
     return balance
Пример #4
0
 def checkIfPayed(self, invoice):
     costs = BigDecimal(0.0)
     payments = BigDecimal(0.0)
     for position in invoice.getPositions():
         if position.getType(
         ) == "INVOICE_COST" and not position.isCanceled():
             costs = costs.add(position.getValue())
         elif position.getType(
         ) == "INVOICE_PAYMENT" and not position.isCanceled():
             payments = payments.add(position.getValue())
     if costs.equals(payments):
         self._logger.info("Costs equals payments, marking as payed...")
         invoice.putAttribute("PAYED", 'true')
     else:
         self._logger.info(
             "Costs(%f) doesn't equal payments(%f), marking as unpayed..." %
             (costs.floatValue(), payments.floatValue()))
         invoice.putAttribute("PAYED", 'false')
Пример #5
0
 def calculateValue(self, invoice):
     value = BigDecimal(0.0)
     for position in invoice.getPositions():
         if position.getType(
         ) == "INVOICE_COST" and not position.isCanceled():
             value = value.add(position.getValue().setScale(
                 2, RoundingMode.HALF_UP))
     invoice.putAttribute(
         "VALUE", str(value.setScale(2, RoundingMode.HALF_UP).floatValue()))
Пример #6
0
 def calculateValueGross(self, valueNet, taxId):
     try:
         tax = self.findById("Dictionary", taxId)
         bdValueNet = BigDecimal(valueNet)
         bdTax = BigDecimal(tax.getKey())
         return bdValueNet.add(
             bdValueNet.multiply(bdTax).setScale(
                 2, RoundingMode.HALF_UP)).setScale(2, RoundingMode.HALF_UP)
     except:
         return BigDecimal(0)
Пример #7
0
    def parse_example_target(self, target):
        parsed = self.parse_entity_id(target)
        if parsed:
            return Datamodel.makeWikidataItemIdValue(parsed)
        r = re.compile('[± ]+')

        if self.datatype == 'quantity' or self.datatype == 'number':
            # First remove any spurious spaces or commas
            spurious_space_comma_re = re.compile('[ ,](\d\d\d)')
            target = spurious_space_comma_re.sub(r'\1', target)

            try:
                parts = [p.strip() for p in r.split(target) if p.strip()]
                print(parts)
                if parts[-1].startswith('[') and parts[-1].endswith(']'):
                    parts = parts[:-1]
                amount = BigDecimal(parts[0])
                precision = 0
                unit = ""
                if len(parts) > 1:
                    unit_qid = self.parse_entity_id(parts[-1])
                    if unit_qid:
                        unit = Datamodel.makeWikidataItemIdValue(
                            unit_qid).getIri()
                    try:
                        precision = BigDecimal(parts[1])
                    except NumberFormatException:
                        pass
                if precision:
                    return Datamodel.makeQuantityValue(
                        amount, amount.subtract(precision),
                        amount.add(precision), unit)
                else:
                    return Datamodel.makeQuantityValue(amount, unit)
            except NumberFormatException as e:
                print(e)

        target = target.strip()
        if target.startswith('<code>') and target.endswith('</code>'):
            target = target[len('<code>'):-len('</code>')]

        if target.startswith('['):
            wiki = mwparserfromhell.parse(target)
            for extlink in wiki.filter_external_links():
                return Datamodel.makeStringValue(unicode(
                    extlink.title.strip()))

        if target.startswith('"') and target.endswith(
                '"') and self.datatype == 'string':
            return Datamodel.makeStringValue(target[1:-1])
        elif self.datatype == 'string' or self.datatype == 'external-id':
            return Datamodel.makeStringValue(target.strip())
 def recalculateShares(self, community):
     totalArea = BigDecimal(0)
     percent = BigDecimal(100)
     for possession in community.getPossessions():
         totalArea = totalArea.add(possession.getArea())
     self._logger.info("Total area of community %s calculated as %f" %
                       (community.getName(), totalArea.floatValue()))
     for possession in community.getPossessions():
         tmpPossessionArea = possession.getArea().divide(
             totalArea, 6, RoundingMode.HALF_UP)
         possessionArea = tmpPossessionArea.multiply(percent)
         self._logger.info(
             "Possession area for %d calculated as %f" %
             (possession.getId(), possessionArea.floatValue()))
         possession.setShare(possessionArea)
Пример #9
0
class ChargingPredictionReport(Report):
    def obtainData(self):
        self._community = self.findById("Community",
                                        self._svars.get('communityId'))
        self._possession = self.findById("Possession",
                                         self._svars.get('possessionId'))
        self._total = BigDecimal(0)
        self._items = self.collectItems()
        self._paymentStartDate = self.getPaymentStartDate()
        self._chargingAccount = self.getChargingAccount()
        self._rfAccount = self.getRFAccount()

    def collectItems(self):
        output = []
        elements = self._possession.getElements()
        elements = sorted(
            elements,
            key=lambda item: item.getGroup().getValue() + item.getName())
        lastGroupId = elements[0].getGroup().getId()
        groupTotal = BigDecimal(0)
        groupItems = 0
        for element in elements:
            if element.getGroup().getId() != lastGroupId:
                if groupItems > 1:
                    self.createTotalLine(output, groupTotal)
                    groupTotal = BigDecimal(0)
                self.createEmptyLine(output)
                groupItems = 0
                lastGroupId = element.getGroup().getId()
                groupTotal = BigDecimal(0)
            item = dict([])
            item['group'] = element.getGroup().getValue()
            item['element'] = element.getName()
            value = self.calculateValue(element)
            item['value'] = value
            groupTotal = groupTotal.add(value)
            self._total = self._total.add(value)
            groupItems += 1
            output.append(item)
        self.createTotalLine(output, groupTotal)
        self.createEmptyLine(output)
        self.createTotalLine(output, self._total)
        return output

    def createTotalLine(self, output, total):
        item = dict([])
        item['group'] = ' '
        item['element'] = ' '
        item['value'] = "=" + str(total.setScale(2, RoundingMode.HALF_UP))
        output.append(item)

    def createEmptyLine(self, output):
        item = dict([])
        item['group'] = ' '
        item['element'] = ' '
        item['value'] = ' '
        output.append(item)

    def calculateValue(self, element):
        calculator = Calculator()
        return BigDecimal(
            calculator.calculate(element.getElement(),
                                 self._possession)).setScale(
                                     2, RoundingMode.HALF_UP)

    def getPaymentStartDate(self):
        bp = BookingPeriodManager()
        return self._label.get(bp.getCurrentMonthLabel(
        )) + " " + bp.findDefaultBookingPeriod().getName()

    def getChargingAccount(self):
        for account in self._community.getAccounts():
            if account.getType().getKey() in ["DEFAULT", "RENT"]:
                return AccountManager().makeReadable(account.getNumber())

    def getRFAccount(self):
        for account in self._community.getAccounts():
            if account.getType().getKey() in ["REPAIR_FUND"]:
                return AccountManager().makeReadable(account.getNumber())

    def fillTemplate(self):
        self._context.put("paymentStartDate", self._paymentStartDate)
        self._context.put("totalValue", self._total)
        self._context.put("chargingAccount", self._chargingAccount)
        self._context.put("rfAccount", self._rfAccount)
        self._context.put("community", self._community)
        self._context.put("possession", self._possession)
        self._context.put("items", self._items)
        self._context.put("labelDocumentCreationDate",
                          self._label.get('report.documentCreationDate'))
        self._context.put("labelChargingPrediction",
                          self._label.get('report.chargingPrediction'))
        self._context.put("labelCommunity",
                          self._label.get('report.community'))
        self._context.put("labelPossession",
                          self._label.get('report.possession'))
        self._context.put("labelOwners", self._label.get('report.owners'))
        self._context.put("labelPaymentStartDate",
                          self._label.get('report.paymentStartDate'))
        self._context.put("labelGroup", self._label.get('report.group'))
        self._context.put("labelElement", self._label.get('report.element'))
        self._context.put("labelValue", self._label.get('report.value'))
        self._context.put("labelTotal", self._label.get('report.totalValue'))
        self._context.put("labelChargingAccount",
                          self._label.get('report.chargingAccount'))
        self._context.put("labelRFAccount",
                          self._label.get('report.rfAccount'))

    def getTemplateName(self):
        return "report-charging-prediction"