Example #1
0
 def handleNodeList(self, nodeList, parent):
     for element in nodeList:
         if element.nodeType is not element.TEXT_NODE:
             if element.tagName == "BAREME":
                 code = element.getAttribute("code")
                 desc = element.getAttribute("description")
                 tranches = Bareme(code)
                 for tranche in element.getElementsByTagName("TRANCHE"):
                     seuil = self.handleValues(tranche.getElementsByTagName("SEUIL")[0], self._date)
                     assi = tranche.getElementsByTagName("ASSIETTE")
                     if assi:
                         assiette = self.handleValues(assi[0], self._date)
                     else:
                         assiette = 1
                     taux = self.handleValues(tranche.getElementsByTagName("TAUX")[0], self._date)
                     if not seuil is None and not taux is None:
                         tranches.addTranche(seuil, taux * assiette)
                 tranches.marToMoy()
                 node = BaremeNode(code, desc, tranches, parent)
             elif element.tagName == "CODE":
                 code = element.getAttribute("code")
                 desc = element.getAttribute("description")
                 valueFormat = element.getAttribute("format")
                 val = self.handleValues(element, self._date)
                 if not val is None:
                     node = CodeNode(code, desc, float(val), parent, valueFormat)
             else:
                 code = element.getAttribute("code")
                 desc = element.getAttribute("description")
                 node = Node(code, desc, parent)
                 self.handleNodeList(element.childNodes, node)
Example #2
0
class BaremeNode(Node):
    def __init__(self, code, description, value, parent):
        super(BaremeNode, self).__init__(code, description, parent)
        self.value = value
        # create a copy of the default value by hand
        self.default = Bareme(value._name)
        for s, t in value._tranches:
            self.default.addTranche(s, t)
        self.default.marToMoy()
        self.typeInfo = "BAREME"

    def _recurseXml(self, parent):
        if self.isDirty():
            child = SubElement(parent, tag=self.typeInfo, attrib={"code": self.code, "description": self.description})

            bareme = self.value
            S = bareme.seuils
            T = bareme.taux
            date = CONF.get("simulation", "datesim")

            for i in range(self.value.getNb()):
                tranche = SubElement(child, tag="TRANCHE", attrib={"code": "tranche%d" % i})

                seuil = SubElement(tranche, tag="SEUIL", attrib={"code": "tranche%d" % i})

                SubElement(seuil, tag="VALUE", attrib={"valeur": "%f" % S[i], "deb": date, "fin": date})

                taux = SubElement(tranche, tag="TAUX")

                SubElement(taux, tag="VALUE", attrib={"valeur": "%f" % T[i], "deb": date, "fin": date})

    def load(self, other):
        self.value = other.value

    def data(self, column):
        r = super(BaremeNode, self).data(column)
        if column is 1:
            r = self.value
        return r

    def setData(self, column, value):
        pass

    def hasValue(self):
        return True

    def isDirty(self):
        if self.value._tranches == self.default._tranches:
            return False
        return True
Example #3
0
 def handleNodeList(self, nodeList, parent):
     for element in nodeList:
         if element.nodeType is not element.TEXT_NODE:
             if element.tagName == "BAREME":
                 code = element.getAttribute('code')
                 desc = element.getAttribute('description')
                 tranches = Bareme(code)
                 for tranche in element.getElementsByTagName("TRANCHE"):
                     seuil = self.handleValues(
                         tranche.getElementsByTagName("SEUIL")[0],
                         self._date)
                     assi = tranche.getElementsByTagName("ASSIETTE")
                     if assi:
                         assiette = self.handleValues(assi[0], self._date)
                     else:
                         assiette = 1
                     taux = self.handleValues(
                         tranche.getElementsByTagName("TAUX")[0],
                         self._date)
                     if not seuil is None and not taux is None:
                         tranches.addTranche(seuil, taux * assiette)
                 tranches.marToMoy()
                 node = BaremeNode(code, desc, tranches, parent)
             elif element.tagName == "CODE":
                 code = element.getAttribute('code')
                 desc = element.getAttribute('description')
                 valueFormat = element.getAttribute('format')
                 val = self.handleValues(element, self._date)
                 if not val is None:
                     node = CodeNode(code, desc, float(val), parent,
                                     valueFormat)
             else:
                 code = element.getAttribute('code')
                 desc = element.getAttribute('description')
                 node = Node(code, desc, parent)
                 self.handleNodeList(element.childNodes, node)
Example #4
0
class BaremeNode(Node):
    def __init__(self, code, description, value, parent):
        super(BaremeNode, self).__init__(code, description, parent)
        self.value = value
        # create a copy of the default value by hand
        self.default = Bareme(value._name)
        for s, t in value._tranches:
            self.default.addTranche(s, t)
        self.default.marToMoy()
        self.typeInfo = 'BAREME'

    def _recurseXml(self, parent):
        if self.isDirty():
            child = SubElement(parent,
                               tag=self.typeInfo,
                               attrib={
                                   'code': self.code,
                                   'description': self.description
                               })

            bareme = self.value
            S = bareme.seuils
            T = bareme.taux
            date = CONF.get('simulation', 'datesim')

            for i in range(self.value.getNb()):
                tranche = SubElement(child,
                                     tag='TRANCHE',
                                     attrib={'code': 'tranche%d' % i})

                seuil = SubElement(tranche,
                                   tag='SEUIL',
                                   attrib={'code': 'tranche%d' % i})

                SubElement(seuil,
                           tag='VALUE',
                           attrib={
                               'valeur': '%f' % S[i],
                               'deb': date,
                               'fin': date
                           })

                taux = SubElement(tranche, tag='TAUX')

                SubElement(taux,
                           tag='VALUE',
                           attrib={
                               'valeur': '%f' % T[i],
                               'deb': date,
                               'fin': date
                           })

    def load(self, other):
        self.value = other.value

    def data(self, column):
        r = super(BaremeNode, self).data(column)
        if column is 1: r = self.value
        return r

    def setData(self, column, value):
        pass

    def hasValue(self):
        return True

    def isDirty(self):
        if self.value._tranches == self.default._tranches:
            return False
        return True