Exemple #1
0
    def __init__(
        self,
        id=None,
        title=None,
        comment=None,
        quantity=None,
        quantity_format=None,
        quantity_b=None,
        quantity_b_format=None,
        tax=None,
        hour_rate=None,
        wage_add=None,
        wage_add_explain=None
    ):
        """Initialize the class."""
        # values of the BaseEntry class
        super(MultiplyEntry, self).__init__(
            id=id,
            title=title,
            comment=comment,
            quantity=quantity,
            quantity_format=quantity_format,
            quantity_b=quantity_b,
            quantity_b_format=quantity_b_format,
            tax=tax
        )

        # new values for this class
        self._hour_rate = QuantityTime(hour_rate)
        self._wage_add = QuantityTime(wage_add)
        self.wage_add_explain = '' if wage_add_explain is None else str(wage_add_explain)
Exemple #2
0
    def get_time(self, entry_list=None, *args, **kwargs):
        """
        Get time according to entry_list or zero.

        entry_list is the global list holding all entry-objects.
        This function calculates the time respecting the entries from the
        entry_list. The ConnectEntry class is an entry for multiplying entries
        times or only prices (depenging on self.is_time()) - e.g. licences
        can cost x-times multiplied the original working time of a task.
        This class can calculate it.
        """
        # if is_time() == False or entry_list not a list, return 0
        if not self.get_is_time() or type(entry_list) is not list:
            return QuantityTime('0:00')
        # is_time() == True, calculate time respecting other entires
        else:
            # otherwise iterate through entry_list and find
            # entries which ids exist in the self._connected list
            out = QuantityTime('0:00')
            for entry in entry_list:
                if entry.get_id() in self._connected:
                    # if its in the list, multiply its time and add it
                    out += (self.get_multiplicator() *
                            entry.get_time(entry_list=entry_list))
            # return the result
            return out * self._quantity * self._quantity_b
Exemple #3
0
def test_offer_data_structure():
    """Test the data structure for offer and appended entries."""
    myoffer = TestOffer().out

    # first check for title of second entry
    assert myoffer.get_entry_list()[1].title == 'Multiply title'

    # check time of third entry
    t = myoffer.get_entry_list()[2].get_time(myoffer.get_entry_list())
    assert t == QuantityTime(0)

    # connect connected entry to base entry (3rd entry to 1st)
    myoffer.get_entry_list()[2].connect_entry(
        entry_list=myoffer.get_entry_list(),
        entry_id=myoffer.get_entry_list()[0].get_id())

    # now time of third entry is 2 * 3 * 2.5 hours
    t = myoffer.get_entry_list()[2].get_time(myoffer.get_entry_list())
    multi = 2 * 3 * QuantityTime(2.5)
    assert t == multi
Exemple #4
0
    def get_time_total(self):
        """Get times of entries summerized."""
        # init output variable
        out = QuantityTime('0:00')

        # iterate through the entries and get its time
        for e in self._entry_list:
            out += e.get_time(entry_list=self._entry_list)

        # return it
        return out
Exemple #5
0
    def __init__(
        self,
        id=None,
        title=None,
        comment=None,
        quantity=None,
        quantity_format=None,
        quantity_b=None,
        quantity_b_format=None,
        tax=None,
        time=None,
        price=None,
        connected=None
    ):
        """Init the class."""
        # gen ID if not set, otherwise get it from argument
        self._id = str(uuid.uuid1()) if id is None else str(id)

        # get other variables from arguments
        self.title = '' if title is None else str(title)
        self.comment = '' if comment is None else str(comment)
        self._quantity = QuantityTime(quantity)
        self.quantity_format = '' if quantity_format is None else str(quantity_format)
        if quantity_b is None:
            self._quantity_b = QuantityTime(1)
        else:
            self._quantity_b = QuantityTime(quantity_b)
        self.quantity_b_format = (
            '' if quantity_b_format is None else str(quantity_b_format)
        )
        self._tax = Decimal(0)                  # set default
        self.set_tax(tax)                       # try to set arguments value
        self._time = QuantityTime(time)
        self._price = Decimal(0)                # set default
        self.set_price(price)                   # try to set arguments value

        # get the connected list (for ConnectEntry only)
        if type(connected) is set:
            self._connected = connected
        else:
            self._connected = set()
Exemple #6
0
def update_entry(entry=None, quantity=None):
    """Try to return new entry with updated quantity etc."""
    is_entry = check_objects.is_entry(entry)
    quantity = str(quantity)

    if not is_entry:
        return entry

    # it's no MultiplyEntry
    if type(entry) is not MultiplyEntry:
        entry.quantity_format = quantity
        return entry

    # it's a multiply entry: try to convert given quantity to QuantityTime and string

    # first split the given quantity
    s = quantity.split(' ')

    # quantity string given as well
    if len(s) > 1:
        # set new quantity format
        entry.quantity_format = '{s} ' + ' '.join(s[1:])

    # only one thign entered
    else:
        # set new quantity format
        entry.quantity_format = '{s}'

    # get the quantity number
    quantity_number = QuantityTime(s[0])

    # first given thing is a number > 0
    if quantity_number > 0:

        # calculate the new hour rate
        hour_rate = entry.get_quantity() / quantity_number

        # set new hour rate
        entry.set_hour_rate(hour_rate)

        # set new quantity
        entry.set_quantity(quantity_number)

    # it's something else, set quantity_format from argument and leave quantity
    else:
        entry.quantity_format = quantity

    return entry
Exemple #7
0
    def __init__(
        self,
        data_path=None,
        language=None,
        offer_title=None,
        offer_comment=None,
        offer_comment_b=None,
        offer_filename=None,
        offer_round_price=None,
        offer_templates=None,
        invoice_title=None,
        invoice_id=None,
        invoice_comment=None,
        invoice_comment_b=None,
        invoice_filename=None,
        invoice_round_price=None,
        invoice_templates=None,
        invoice_due_days=None,
        invoice_delivery=None,
        invoice_ledger_comment=None,
        date_fmt=None,
        commodity=None,
        client_id=None,
        client_company=None,
        client_company_b=None,
        client_attention=None,
        client_salutation=None,
        client_name=None,
        client_family_name=None,
        client_street=None,
        client_post_code=None,
        client_city=None,
        client_country=None,
        client_tax_id=None,
        client_language=None,
        project_title=None,
        project_hours_per_day=None,
        project_work_days=None,
        project_minimum_days=None,
        project_wage=None,
        baseentry_title=None,
        baseentry_comment=None,
        baseentry_quantity=None,
        baseentry_quantity_format=None,
        baseentry_quantity_b=None,
        baseentry_quantity_b_format=None,
        baseentry_time=None,
        baseentry_price=None,
        multiplyentry_title=None,
        multiplyentry_comment=None,
        multiplyentry_quantity=None,
        multiplyentry_quantity_format=None,
        multiplyentry_quantity_b=None,
        multiplyentry_quantity_b_format=None,
        multiplyentry_hour_rate=None,
        connectentry_title=None,
        connectentry_comment=None,
        connectentry_quantity=None,
        connectentry_quantity_format=None,
        connectentry_quantity_b=None,
        connectentry_quantity_b_format=None,
        connectentry_is_time=None,
        connectentry_multiplicator=None,
        ledger_time_def_quantity=None
    ):
        """Initialize the class and hard code defaults, if no file is given."""
        self.language = 'NEW' if language is None else language

        self.offer_title = '' if offer_title is None else offer_title
        self.offer_comment = '' if offer_comment is None else offer_comment
        self.offer_comment_b = '' if offer_comment_b is None else offer_comment_b
        self.offer_filename = '' if offer_filename is None else offer_filename
        self.set_offer_round_price(
            False if offer_round_price is None else offer_round_price
        )
        self._offer_templates = {}                      # set default
        self.set_offer_templates(offer_templates)       # try to set arguments value

        self.invoice_title = '' if invoice_title is None else invoice_title
        self.invoice_id = '' if invoice_id is None else invoice_id
        self.invoice_comment = '' if invoice_comment is None else invoice_comment
        self.invoice_comment_b = '' if invoice_comment_b is None else invoice_comment_b
        self.invoice_filename = '' if invoice_filename is None else invoice_filename
        self.set_invoice_round_price(
            False if invoice_round_price is None else invoice_round_price
        )
        self._invoice_templates = {}                        # set default
        self.set_invoice_templates(invoice_templates)       # try to set arguments value
        self._invoice_due_days = 14                         # set default
        self.set_invoice_due_days(invoice_due_days)         # try to set arguments value
        self.invoice_delivery = '' if invoice_delivery is None else invoice_delivery
        self.invoice_ledger_comment = (
            '' if invoice_ledger_comment is None else invoice_ledger_comment
        )

        self.date_fmt = '' if date_fmt is None else date_fmt
        self.commodity = '' if commodity is None else commodity

        # client default values
        self.client_id = '{CLIENT_COUNT}' if client_id is None else client_id
        self.client_company = '' if client_company is None else client_company
        self.client_company_b = '' if client_company_b is None else client_company_b
        self.client_attention = 'Attn.' if client_attention is None else client_attention
        self.client_salutation = '' if client_salutation is None else client_salutation
        self.client_name = '' if client_name is None else client_name
        self.client_family_name = '' if client_family_name is None else client_family_name
        self.client_street = '' if client_street is None else client_street

        self.client_post_code = '' if client_post_code is None else client_post_code
        self.client_city = '' if client_city is None else client_city
        self.client_country = '' if client_country is None else client_country
        self.client_tax_id = '' if client_tax_id is None else client_tax_id
        self.client_language = 'en' if client_language is None else client_language

        # project default values
        self.project_title = '{PROJECT_COUNT}' if project_title is None else project_title
        self._project_hours_per_day = 0
        self.set_project_hours_per_day(project_hours_per_day)
        self._project_work_days = [0, 1, 2, 3, 4]
        self.set_project_work_days(project_work_days)
        self._project_minimum_days = 2
        self.set_project_minimum_days(project_minimum_days)
        self._project_wage = Decimal(0)
        self.set_project_wage(project_wage)

        # baseentry default values
        self.baseentry_title = '' if baseentry_title is None else baseentry_title
        self.baseentry_comment = '' if baseentry_comment is None else baseentry_comment
        self._baseentry_quantity = QuantityTime(baseentry_quantity)
        self.baseentry_quantity_format = (
            '' if baseentry_quantity_format is None
            else baseentry_quantity_format
        )
        if baseentry_quantity_b is None:
            self._baseentry_quantity_b = QuantityTime(1)
        else:
            self._baseentry_quantity_b = QuantityTime(baseentry_quantity_b)
        self.baseentry_quantity_b_format = (
            '' if baseentry_quantity_b_format is None
            else baseentry_quantity_b_format
        )
        self._baseentry_time = QuantityTime(baseentry_time)
        self._baseentry_price = Decimal(0)
        self.set_baseentry_price(baseentry_price)

        # multiplyentry default values
        self.multiplyentry_title = (
            '' if multiplyentry_title is None
            else multiplyentry_title
        )
        self.multiplyentry_comment = (
            '' if multiplyentry_comment is None
            else multiplyentry_comment
        )
        self._multiplyentry_quantity = QuantityTime(multiplyentry_quantity)
        self.multiplyentry_quantity_format = (
            '' if multiplyentry_quantity_format is None
            else multiplyentry_quantity_format
        )
        if multiplyentry_quantity_b is None:
            self._multiplyentry_quantity_b = QuantityTime(1)
        else:
            self._multiplyentry_quantity_b = QuantityTime(multiplyentry_quantity_b)
        self.multiplyentry_quantity_b_format = (
            '' if multiplyentry_quantity_b_format is None
            else multiplyentry_quantity_b_format
        )
        self._multiplyentry_hour_rate = QuantityTime(multiplyentry_hour_rate)

        # connectentry default values
        self.connectentry_title = (
            '' if connectentry_title is None else connectentry_title
        )
        self.connectentry_comment = (
            '' if connectentry_comment is None else connectentry_comment
        )
        self._connectentry_quantity = QuantityTime(connectentry_quantity)
        self.connectentry_quantity_format = (
            '' if connectentry_quantity_format is None
            else connectentry_quantity_format
        )
        if connectentry_quantity_b is None:
            self._connectentry_quantity_b = QuantityTime(1)
        else:
            self._connectentry_quantity_b = QuantityTime(connectentry_quantity_b)
        self.connectentry_quantity_b_format = (
            '' if connectentry_quantity_b_format is None
            else connectentry_quantity_b_format
        )
        self.set_connectentry_is_time(
            True if connectentry_is_time is None else connectentry_is_time
        )
        self._connectentry_multiplicator = Decimal(0)
        self.set_connectentry_multiplicator(connectentry_multiplicator)

        # ledger time
        self.ledger_time_def_quantity = (
            '1' if ledger_time_def_quantity is None else ledger_time_def_quantity
        )

        # try to load default automatically
        if data_path is not None:
            self.load_settings_from_file(data_path)
Exemple #8
0
 def get_time_zero(self, *args, **kwargs):
     """Get time as '-' if time is 0, else str of time."""
     if self.get_time(*args, **kwargs) == QuantityTime(0):
         return '-'
     else:
         return str(self.get_time(*args, **kwargs))
Exemple #9
0
def test_integrety_entry():
    """Test if BaseEntry, ConnectEntry and MultiplyEntry work as they should."""
    a = BaseEntry(title='Title A',
                  comment='Comment A',
                  quantity=1.0,
                  time=1.0,
                  price=50.00)

    b = MultiplyEntry(title='Title B',
                      comment='Comment B',
                      quantity=2.0,
                      hour_rate=0.5)

    c = ConnectEntry(title='Title C',
                     comment='Comment C',
                     quantity=2.5,
                     is_time=False,
                     multiplicator=0.5)

    d = ConnectEntry(title='Title D',
                     comment='Comment D',
                     quantity=3.0,
                     is_time=True,
                     multiplicator=0.75)

    # init entries in list
    entries = []
    entries.append(a)
    entries.append(b)
    entries.append(c)
    entries.append(d)

    # connect first two entries two the first ConnectEntry
    entries[2].connect_entry(entry_list=entries, entry_id=entries[0].get_id())
    entries[2].connect_entry(entry_list=entries, entry_id=entries[1].get_id())

    # connect first ConnectEntry to the second ConnectEntry
    entries[3].connect_entry(entry_list=entries, entry_id=entries[2].get_id())

    # connect second ConnectEntry to the first ConnectEntry
    # and it should not work anymore
    entries[2].connect_entry(entry_list=entries, entry_id=entries[3].get_id())
    assert entries[3].get_id() not in entries[2].get_connected()

    # connect MultiplyEntry to the second ConnectEntry
    entries[3].connect_entry(entry_list=entries, entry_id=entries[1].get_id())

    # set wage to work with
    wage = Decimal('50.00')

    # check values for BaseEntry
    assert entries[0].title == 'Title A'
    assert entries[0].comment == 'Comment A'
    assert entries[0].get_quantity() == Decimal('1.0')
    assert entries[0].get_time() == QuantityTime(1.0)
    assert entries[0].get_price() == Decimal('50.00')

    # check values for MultiplyEntry
    assert entries[1].title == 'Title B'
    assert entries[1].comment == 'Comment B'
    assert entries[1].get_quantity() == Decimal('2.0')
    assert entries[1].get_hour_rate() == QuantityTime(0.5)
    assert entries[1].get_time() == QuantityTime(1.0)
    assert entries[1].get_price(wage=wage) == Decimal('50.00')

    # check values for first ConnectEntry
    assert entries[2].title == 'Title C'
    assert entries[2].comment == 'Comment C'
    assert entries[2].get_quantity() == Decimal('2.5')
    assert entries[2].get_is_time() is False
    assert entries[2].get_time(entry_list=entries) == QuantityTime(0)
    assert entries[2].get_price(entry_list=entries,
                                wage=wage) == Decimal('125.00')

    # check values for second ConnectEntry
    assert entries[3].title == 'Title D'
    assert entries[3].comment == 'Comment D'
    assert entries[3].get_quantity() == Decimal('3.0')
    assert entries[3].get_is_time() is True
    assert entries[3].get_time(entry_list=entries) == QuantityTime('2:15:00')
    assert entries[3].get_price(entry_list=entries,
                                wage=wage) == Decimal('112.50')