Ejemplo n.º 1
0
    def run_command(self):
        """Try to run the command."""
        self.values_to_tmp()

        # ask for summerizing
        single_account = npyscreen.notify_input(
            'Account:', title='Summerize into one account? (empty if not)')

        # get replacer dict
        replacer_dict = replacer(settings=self.parentApp.S,
                                 global_list=self.parentApp.L,
                                 client=self.parentApp.tmpClient,
                                 project=self.parentApp.tmpProject,
                                 offerinvoice=self.parentApp.tmpInvoice)

        # ask for payee
        def_payee = self.parentApp.S.ledgeradd_def_payee.format_map(
            replacer_dict)
        payee = npyscreen.notify_input(
            'Payee:',
            pre_text=def_payee,
            title='Summerize into one account? (empty = project title)')

        # cancle on single_account is False or payee is False
        if single_account is False or payee is False:
            return False

        # get payee replaced
        payee = payee.format_map(replacer_dict)

        # generate parameters
        parameter = generate_parameter(single_account=single_account,
                                       payee=payee,
                                       settings=self.parentApp.S,
                                       project=self.parentApp.tmpProject,
                                       invoice=self.parentApp.tmpInvoice)

        if parameter is False:
            npyscreen.notify_confirm('Cannot generate ledgeradd parameter.',
                                     form_color='WARNING')
            return False

        parameter = parameter.format_map(replacer_dict)

        try:
            os.system('{} {}'.format(self.parentApp.S.ledgeradd_command,
                                     parameter))
        except Exception:
            npyscreen.notify_confirm('Command not runned!',
                                     form_color='WARNING')
Ejemplo n.º 2
0
    def rename(self, keypress=None):
        """Try to rename the selected preset."""
        # cancel if there are no values
        if len(self.values) < 1:
            return False

        entry = self.values[self.cursor_line]['item']

        old_name = self.values[self.cursor_line]['name']
        new_name = npyscreen.notify_input('Enter name for preset:',
                                          pre_text=old_name)

        if new_name:
            if self.is_offer(entry):
                renamed = self.parent.parentApp.P.rename_offer(
                    old_name=old_name, new_name=new_name)
            elif self.is_invoice(entry):
                renamed = self.parent.parentApp.P.rename_invoice(
                    old_name=old_name, new_name=new_name)
            elif self.is_entry(entry):
                if self.parent.parentApp.tmpEntry_offer_invoice == 'offer':
                    renamed = self.parent.parentApp.P.rename_offer_entry(
                        old_name=old_name, new_name=new_name)
                else:
                    renamed = self.parent.parentApp.P.rename_invoice_entry(
                        old_name=old_name, new_name=new_name)
            else:
                renamed = False

            if not renamed:
                npyscreen.notify_confirm('Rename did not work ...',
                                         form_color='DANGER')
            else:
                self.parent.beforeEditing()
Ejemplo n.º 3
0
    def actionHighlighted(self, act_on_this, keypress):
        """Do something, because a key was pressed."""
        # cancel if there are no values
        if len(self.values) < 1:
            return False

        # get old
        old_key = act_on_this[0]
        old_val = act_on_this[1]

        # ask new stuff
        file = npyscreen.selectFile(
            starting_value=old_val,
            confirm_if_exists=False
        )

        name = npyscreen.notify_input(
            'Name of template:',
            pre_text=old_key
        )

        if name:
            if self.offerinvoice == 'offer':
                self.parent.parentApp.tmpDefault.del_offer_template(key=old_key)
                self.parent.parentApp.tmpDefault.add_offer_template(
                    key=name, value=file
                )
            else:
                self.parent.parentApp.tmpDefault.del_invoice_template(key=old_key)
                self.parent.parentApp.tmpDefault.add_invoice_template(
                    key=name, value=file
                )

            self.update_values()
Ejemplo n.º 4
0
    def add_template(self, keypress=None):
        """Add template."""
        file = npyscreen.selectFile(
            starting_value=os.path.expanduser('~'),
            confirm_if_exists=False
        )

        name = npyscreen.notify_input(
            'Name of template:'
        )

        # add if name and not exists in dict
        if self.offerinvoice == 'offer':
            if (
                name and
                name not in self.parent.parentApp.tmpDefault.get_offer_templates()
            ):
                self.parent.parentApp.tmpDefault.add_offer_template(
                    key=name, value=file
                )
        else:
            if (
                name and
                name not in self.parent.parentApp.tmpDefault.get_invoice_templates()
            ):
                self.parent.parentApp.tmpDefault.add_invoice_template(
                    key=name, value=file
                )

        self.update_values()
Ejemplo n.º 5
0
    def save_preset(self):
        """Save invoice to presets."""
        self.values_to_tmp()

        name = npyscreen.notify_input('Name for the invoice preset:')

        if name:
            added = self.parentApp.P.add_invoice(
                invoice=self.parentApp.tmpInvoice.copy(), name=name)

            if not added:
                npyscreen.notify_confirm(
                    'Invoice not added. It probably already exists.',
                    form_color='DANGER')
Ejemplo n.º 6
0
    def save_preset(self):
        """Save offer to presets."""
        self.values_to_tmp()

        name = npyscreen.notify_input('Name for the offer preset:')

        if name is not False:
            added = self.parentApp.P.add_offer(
                offer=self.parentApp.tmpOffer.copy(), name=name)

            if not added:
                npyscreen.notify_confirm(
                    'Offer not added. It probably already exists.',
                    form_color='DANGER')
Ejemplo n.º 7
0
    def add_alias(self):
        """Add the alias for the client to the ledger alias file."""
        # get default account string
        default_account = replacer(
            text=self.parentApp.S.ledger_alias_default_account,
            settings=self.parentApp.S,
            global_list=self.parentApp.L,
            client=self.parentApp.tmpClient
        )

        # ask for the account replacement string
        account = npyscreen.notify_input(
            'Account string:',
            pre_text=default_account
        )

        # user canceled
        if account is False:
            return False

        # generate check text
        file = self.parentApp.S.ledger_alias_file
        adder = 'alias {}={}'.format(
            self.parentApp.tmpClient.client_id,
            account
        )

        check_text = '{}\n---\n{}\n---\n{}'.format(
            'Really add this alias to the file?',
            file,
            adder
        )

        # ask user to really add this alias
        really = npyscreen.notify_yes_no(
            check_text
        )

        # add if user chose yes
        if really:
            add_ledger_alias(
                ledgerfile=self.parentApp.S.ledger_alias_file,
                alias=self.parentApp.tmpClient.client_id,
                string=account
            )
Ejemplo n.º 8
0
    def save_preset(self):
        """Save entry to presets."""
        self.values_to_tmp()

        name = npyscreen.notify_input('Name for the BaseEntry preset:')

        if name:
            if self.parentApp.tmpEntry_offer_invoice == 'offer':
                added = self.parentApp.P.add_offer_entry(
                    entry=self.parentApp.tmpEntry.copy(), name=name)
            else:
                added = self.parentApp.P.add_invoice_entry(
                    entry=self.parentApp.tmpEntry.copy(), name=name)

            if not added:
                npyscreen.notify_confirm(
                    'BaseEntry not added. It probably already exists.',
                    form_color='DANGER')
Ejemplo n.º 9
0
    def gen_entries(self):
        """Generate entries form ledger time journal."""
        self.values_to_tmp()

        entries = get_invoice_entries_from_time_journal(
            settings=self.parentApp.S,
            global_list=self.parentApp.L,
            presets=self.parentApp.P,
            client=self.parentApp.tmpClient,
            project=self.parentApp.tmpProject,
            invoice=self.parentApp.tmpInvoice)

        if entries is False:
            npyscreen.notify_confirm(
                'No time tracking data, or time tracking data '
                'does not balance.',
                form_color='WARNING')
            return False

        # get user input for amount format and append the entry
        done = False
        while not done:
            for e in entries:
                new_quantity = npyscreen.notify_input(
                    'Quantity:',
                    title=e.title,
                    pre_text=self.parentApp.S.defaults[
                        self.parentApp.tmpClient.language].
                    ledger_time_def_quantity,
                )

                if new_quantity is False:
                    done = True
                    break
                else:
                    self.parentApp.tmpInvoice.append(
                        update_entry(entry=e, quantity=new_quantity))

            done = True

        self.entries_box.entry_widget.update_values()