Esempio n. 1
0
    def clear(self, recur=True, force=False, keep_format=True):
        """


        Line.clear() -> None


        Clear value from instance and optionally details (if ``recur`` is True).
        No-op if line is hardcoded, unless ``force`` is True.
        """
        if self.hardcoded and not force:
            pass
        else:
            consolidate = self.consolidate
            if self._details:
                self._bring_down_local_value()
                if recur:
                    BaseFinancialsComponent.reset(self)

            sig = self.SIGNATURE_FOR_VALUE_RESET
            self.set_value(None, sig, override=True)

            format2keep = self.xl_format.copy()
            self.xl_data = xl_mgmt.LineData(self)

            if keep_format:
                self.xl_format = format2keep

            self.update_stored_xl()

            self.set_consolidate(consolidate)
            # Start with a clean slate for Excel tracking, except for
            # number format

            self.summary_count = 0
Esempio n. 2
0
    def __init__(self, name=None, value=None, parent=None, period=None):
        BaseFinancialsComponent.__init__(self,
                                         name=name,
                                         parent=parent,
                                         period=period)

        self._local_value = None

        self.guide = Guide(priority=3, quality=1)
        self.log = []
        self.position = None

        # summary_type determines how the line is summarized
        self.summary_type = 'sum'

        # summary_count is used for summary_type == 'average'
        self.summary_count = 0

        self._consolidate = True
        self._replica = False
        self._hardcoded = False
        self._include_details = True
        self._sum_details = True
        self.id = ID()
        self._driver_id = None

        if value is not None:
            self.set_value(value, self.SIGNATURE_FOR_CREATION)

        self.workspace = dict()
        self.usage = LineItemUsage()
        self.xl_data = xl_mgmt.LineData(self)
        self.xl_format = xl_mgmt.LineFormat()
Esempio n. 3
0
    def from_database(cls, data, statement):
        """


        LineItem.from_database() -> None

        **CLASS METHOD**

        Method deserializes all LineItems belonging to ``statement``.
        """
        # first pass: create a dict of lines

        new = cls(parent=None, )
        new.tags = Tags.from_database(data['tags'])

        id_str = data['driver_id']
        if id_str:
            new._driver_id = ID.from_database(id_str).bbid

        # defer resolution of .xl
        new.xl_data = xl_mgmt.LineData(new)
        new.xl_format = xl_mgmt.LineFormat.from_database(data['xl_format'])

        new.summary_type = data['summary_type']
        new.summary_count = data['summary_count']
        new._consolidate = data['consolidate']
        new._replica = data['replica']
        new._include_details = data['include_details']
        new._sum_details = data['sum_details']
        new.log = data['log']

        new.guide = Guide.from_database(data['guide'])
        new.id.bbid = ID.from_database(data['bbid']).bbid

        position = data['position']
        position = int(position) if position else None
        new.position = position

        workspace = data.get('workspace', None)
        if workspace and workspace != 'null':
            new.workspace.update(workspace)

        usage = data.get('usage', None)
        if usage and usage != 'null':
            new.usage = LineItemUsage.from_database(usage)

        old_magic_keys = {
            "kpi", "covenants", "financials", "overall", "business summary"
        }
        if 'show on report' in new.tags.all or (new.tags.all & old_magic_keys):
            new.usage.show_on_report = True

        if "business summary" in new.tags.all:
            new.usage.show_on_card = True

        if 'monitor' in new.tags.all:
            new.usage.monitor = True

        return new
Esempio n. 4
0
    def _make_replica(self):
        """


        LineItem._make_replica() -> None


        Create a replica, add replica to details
        """
        replica = copy.copy(self)
        replica.tags = self.tags.copy()
        replica._details = dict()
        replica.xl_data = xl_mgmt.LineData(replica)
        replica.xl_format = self.xl_format.copy()
        replica.set_consolidate(self._consolidate)
        replica._period = self.period
        replica._replica = True
        replica.position = 0
        replica.register(namespace=self.id.namespace)

        self._details[replica.tags.name] = replica
Esempio n. 5
0
    def copy(self, check_include_details=False, clean=False):
        """


        Line.copy() -> Line


        Return a deep copy of the instance and its details. If  is
        True, copy conforms to ``out`` rules.
        """
        new_line = BaseFinancialsComponent.copy(
            self, check_include_details=check_include_details, clean=clean)
        # Shallow copy, should pick up _local_value as is, and then create
        # independent containers for tags.

        new_line.guide = copy.deepcopy(self.guide)
        new_line.log = self.log[:]
        new_line._sum_over_time = self.sum_over_time
        new_line._include_details = self.include_details
        new_line._sum_details = self.sum_details
        new_line._driver_id = copy.copy(self._driver_id)
        new_line.set_consolidate(self._consolidate)
        new_line.id = copy.copy(self.id)
        new_line.usage = self.usage.copy()
        new_line.workspace = self.workspace.copy()
        new_line.xl_data = xl_mgmt.LineData(new_line)
        new_line.xl_format = self.xl_format.copy()

        if not clean:
            new_line.set_hardcoded(self._hardcoded)
            if check_include_details and not new_line._details and self._details:
                new_line.set_value(self.value,
                                   self.SIGNATURE_FOR_COPY,
                                   override=True)
        else:
            new_line._hardcoded = False
            new_line._local_value = None
            new_line.log = []

        return new_line