Exemplo n.º 1
0
    def validate_payment_for_printing(cls, payment):
        account = payment.method.destination_account
        if not account:
            msg = _("Payment method missing a destination account: '%s'") % (
                account.description, )
            return msg

        from stoqlib.domain.account import Account
        if (account.account_type != Account.TYPE_BANK or not account.bank):
            msg = _(
                "Account '%s' must be a bank account.\n"
                "You need to configure the bill payment method in "
                "the admin application and try again") % account.description
            return msg

        bank = account.bank
        if bank.bank_number == 0:
            msg = _("Improperly configured bank account: %r") % (bank, )
            return msg

        # FIXME: Verify that all bill option fields are configured properly

        bank_no = bank.bank_number
        bank_info = get_bank_info_by_number(bank_no)
        if not bank_info:
            msg = _("Missing stoq support for bank %d") % (bank_no, )
            return msg
Exemplo n.º 2
0
 def _print_test_bill(self):
     try:
         bank_info = get_bank_info_by_number(self.bank_model.bank_number)
     except NotImplementedError:
         info(_("This bank does not support printing of bills"))
         return
     kwargs = dict(
         valor_documento=12345.67,
         data_vencimento=datetime.date.today(),
         data_documento=datetime.date.today(),
         data_processamento=datetime.date.today(),
         nosso_numero=u'24533',
         numero_documento=u'1138',
         sacado=[_(u"Drawee"), _(u"Address"),
                 _(u"Details")],
         cedente=[_(u"Supplier"),
                  _(u"Address"),
                  _(u"Details"), ("CNPJ")],
         demonstrativo=[_(u"Demonstration")],
         instrucoes=[_(u"Instructions")],
         agencia=self.bank_model.bank_branch,
         conta=self.bank_model.bank_account,
     )
     for opt in self.bank_model.options:
         kwargs[opt.option] = opt.value
     data = bank_info(**kwargs)
     print_report(BillTestReport, data)
Exemplo n.º 3
0
    def validate_payment_for_printing(cls, payment):
        account = payment.method.destination_account
        if not account:
            msg = _("Payment method missing a destination account: '%s'") % (
                account.description, )
            return msg

        from stoqlib.domain.account import Account
        if (account.account_type != Account.TYPE_BANK or
            not account.bank):
            msg = _("Account '%s' must be a bank account.\n"
                    "You need to configure the bill payment method in "
                    "the admin application and try again") % account.description
            return msg

        bank = account.bank
        if bank.bank_number == 0:
            msg = _("Improperly configured bank account: %r") % (bank, )
            return msg

        # FIXME: Verify that all bill option fields are configured properly

        bank_no = bank.bank_number
        bank_info = get_bank_info_by_number(bank_no)
        if not bank_info:
            msg = _("Missing stoq support for bank %d") % (bank_no, )
            return msg
Exemplo n.º 4
0
    def on_ExportBills__activate(self, action):
        payments = [
            v.payment for v in self.results.get_selected_rows()
            if v.method.method_name == 'bill'
        ]
        if not payments:
            warning(_('No bill payments were selected'))
            return

        filename = save(current_name='CNAB.txt',
                        folder=os.path.expanduser('~/'))
        if not filename:
            return

        bank_number = payments[0].method.destination_account.bank.bank_number
        info = get_bank_info_by_number(bank_number)
        try:
            cnab = info.get_cnab(payments)
        except Exception as e:
            log.error(''.join(traceback.format_exception(*sys.exc_info())))
            warning(_('An error ocurred while generating the CNAB'), str(e))
            return

        with open(filename, 'w') as fh:
            fh.write(cnab)
Exemplo n.º 5
0
 def test_generation(self, localnow):
     localnow.return_value = datetime.datetime(2012, 4, 8, 12, 6)
     info = get_bank_info_by_number(self.bank_number)
     payments = self._create_payments()
     with self.sysparam(BILL_PENALTY=Decimal(11),
                        BILL_INTEREST=Decimal('0.4'),
                        BILL_DISCOUNT=Decimal('123.45')):
         cnab = info.get_cnab(payments)
     self._compare_files(cnab, 'cnab-%03d' % self.bank_number)
Exemplo n.º 6
0
 def test_generation(self, localnow):
     localnow.return_value = datetime.datetime(2012, 4, 8, 12, 6)
     info = get_bank_info_by_number(self.bank_number)
     payments = self._create_payments()
     with self.sysparam(BILL_PENALTY=Decimal(11),
                        BILL_INTEREST=Decimal('0.4'),
                        BILL_DISCOUNT=Decimal('123.45')):
         cnab = info.get_cnab(payments)
     self._compare_files(cnab, 'cnab-%03d' % self.bank_number)
Exemplo n.º 7
0
    def add_payments(self):
        if self._bill.boletos:
            return

        for p in self._payments:
            if p.method.method_name != 'bill':
                continue
            account = p.method.destination_account
            _render_class = get_bank_info_by_number(account.bank.bank_number)
            data = _render_class(p)
            self._bill.add_data(data)
Exemplo n.º 8
0
    def add_payments(self):
        if self._bill.boletos:
            return

        for p in self._payments:
            if p.method.method_name != 'bill':
                continue
            account = p.method.destination_account
            _render_class = get_bank_info_by_number(account.bank.bank_number)
            data = _render_class(p)
            self._bill.add_data(data)
Exemplo n.º 9
0
    def on_ExportBills__activate(self, action):
        payments = [v.payment for v in self.results.get_selected_rows()
                    if v.method.method_name == 'bill']
        if not payments:
            warning(_('No bill payments were selected'))
            return

        filename = save(current_name='CNAB.txt', folder=os.path.expanduser('~/'))
        if not filename:
            return

        bank_number = payments[0].method.destination_account.bank.bank_number
        info = get_bank_info_by_number(bank_number)
        try:
            cnab = info.get_cnab(payments)
        except Exception as e:
            log.error(''.join(traceback.format_exception(*sys.exc_info())))
            warning(_('An error ocurred while generating the CNAB'), str(e))
            return

        with open(filename, 'w') as fh:
            fh.write(cnab)
Exemplo n.º 10
0
 def _add_payment(self, payment):
     account = self._get_account(payment)
     bank = self._get_bank(account)
     kwargs = dict(
         valor_documento=payment.value,
         data_vencimento=payment.due_date.date(),
         data_documento=payment.open_date.date(),
         data_processamento=self.today,
         # FIXME: Maybe we should add the branch id to this numbers
         nosso_numero=str(int(payment.identifier)),
         numero_documento=str(int(payment.identifier)),
         sacado=self._get_sacado(),
         cedente=self._get_cedente(),
         demonstrativo=self._get_demonstrativo(),
         instrucoes=self._get_instrucoes(payment),
         agencia=bank.bank_branch,
         conta=bank.bank_account,
     )
     for opt in bank.options:
         kwargs[opt.option] = opt.value
     _render_class = get_bank_info_by_number(bank.bank_number)
     data = _render_class(**kwargs)
     self._bill.add_data(data)
Exemplo n.º 11
0
 def _add_payment(self, payment):
     account = self._get_account(payment)
     bank = self._get_bank(account)
     kwargs = dict(
         valor_documento=payment.value,
         data_vencimento=payment.due_date.date(),
         data_documento=payment.open_date.date(),
         data_processamento=self.today,
         # FIXME: Maybe we should add the branch id to this numbers
         nosso_numero=str(int(payment.identifier)),
         numero_documento=str(int(payment.identifier)),
         sacado=self._get_sacado(),
         cedente=self._get_cedente(),
         demonstrativo=self._get_demonstrativo(),
         instrucoes=self._get_instrucoes(payment),
         agencia=bank.bank_branch,
         conta=bank.bank_account,
     )
     for opt in bank.options:
         kwargs[opt.option] = opt.value
     _render_class = get_bank_info_by_number(bank.bank_number)
     data = _render_class(**kwargs)
     self._bill.add_data(data)
Exemplo n.º 12
0
 def _print_test_bill(self):
     try:
         bank_info = get_bank_info_by_number(self.bank_model.bank_number)
     except NotImplementedError:
         info(_("This bank does not support printing of bills"))
         return
     kwargs = dict(
         valor_documento=12345.67,
         data_vencimento=datetime.date.today(),
         data_documento=datetime.date.today(),
         data_processamento=datetime.date.today(),
         nosso_numero=u'624533',
         numero_documento=u'1138',
         sacado=[_(u"Drawee"), _(u"Address"), _(u"Details")],
         cedente=_(u"Supplier"),
         demonstrativo=[_(u"Demonstration")],
         instrucoes=[_(u"Instructions")],
         agencia=self.bank_model.bank_branch,
         conta=self.bank_model.bank_account,
     )
     for opt in self.bank_model.options:
         kwargs[opt.option] = opt.value
     data = bank_info(**kwargs)
     print_report(BillTestReport, data)
Exemplo n.º 13
0
    def _update_bank_type(self):
        self._remove_bank_option_widgets()

        bank_number = self.bank_type.get_selected()
        bank_info = None
        if bank_number:
            bank_info = get_bank_info_by_number(bank_number)

        self.bank_number = ProxyEntry()
        self.bank_number.props.data_type = int
        self.bank_number.set_sensitive(False)
        bank_number_lbl = self._add_widget(api.escape(_("Number:")),
                                           self.bank_number,
                                           options=True)

        self.bank_branch = ProxyEntry()
        self.bank_branch.connect('validate', self._on_bank_branch__validate,
                                 bank_info)
        self.bank_branch.props.data_type = 'str'
        self.bank_branch.props.mandatory = True
        self.bank_branch.model_attribute = "bank_branch"
        bank_branch_lbl = self._add_widget(api.escape(_("Agency:")),
                                           self.bank_branch,
                                           options=True)
        if bank_number is not None:
            bank_branch_lbl.show()
            self.bank_branch.show()
        else:
            bank_branch_lbl.hide()

        self.bank_account = ProxyEntry()
        self.bank_account.connect('validate', self._on_bank_account__validate,
                                  bank_info)
        self._add_widget(api.escape(_("Account:")),
                         self.bank_account,
                         options=True)
        self.bank_account.model_attribute = "bank_account"
        self.bank_account.props.data_type = 'str'
        if bank_number is not None:
            self.bank_account.props.mandatory = True
        self.bank_account.show()

        attributes = ['bank_account', 'bank_branch', 'bank_number']
        if bank_number is not None:
            bank_number_lbl.show()
            self.bank_number.show()

            self.bank_model.bank_number = bank_number

            for i, option in enumerate(bank_info.get_extra_options()):
                name = 'option' + str(i)
                entry = ProxyEntry()
                entry.model_attribute = name
                setattr(self, name, entry)
                # Set the model attr too so it can be validated
                setattr(self.bank_model, name, u'')
                entry.props.data_type = 'str'
                entry.connect('validate', self._on_bank_option__validate,
                              bank_info, option)
                name = option.replace('_', ' ').capitalize()
                self._add_widget("<i>%s</i>:" % api.escape(name),
                                 entry,
                                 options=True)
                entry.show()
                self._option_fields[option] = entry
                attributes.append(entry.model_attribute)
        else:
            bank_number_lbl.hide()

        self.bank_proxy = self.add_proxy(self.bank_model, attributes)
        self._fill_bank_account()
Exemplo n.º 14
0
    def _update_bank_type(self):
        self._remove_bank_option_widgets()

        bank_number = self.bank_type.get_selected()
        bank_info = None
        if bank_number:
            bank_info = get_bank_info_by_number(bank_number)

        self.bank_number = ProxyEntry()
        self.bank_number.props.data_type = int
        self.bank_number.set_sensitive(False)
        bank_number_lbl = self._add_widget(api.escape(_("Number:")),
                                           self.bank_number, options=True)

        self.bank_branch = ProxyEntry()
        self.bank_branch.connect('validate', self._on_bank_branch__validate,
                                 bank_info)
        self.bank_branch.props.data_type = 'str'
        self.bank_branch.props.mandatory = True
        self.bank_branch.model_attribute = "bank_branch"
        bank_branch_lbl = self._add_widget(api.escape(_("Agency:")),
                                           self.bank_branch, options=True)
        if bank_number is not None:
            bank_branch_lbl.show()
            self.bank_branch.show()
        else:
            bank_branch_lbl.hide()

        self.bank_account = ProxyEntry()
        self.bank_account.connect('validate', self._on_bank_account__validate,
                                  bank_info)
        self._add_widget(api.escape(_("Account:")),
                         self.bank_account, options=True)
        self.bank_account.model_attribute = "bank_account"
        self.bank_account.props.data_type = 'str'
        if bank_number is not None:
            self.bank_account.props.mandatory = True
        self.bank_account.show()

        attributes = ['bank_account', 'bank_branch',
                      'bank_number']
        if bank_number is not None:
            bank_number_lbl.show()
            self.bank_number.show()

            self.bank_model.bank_number = bank_number

            for i, option in enumerate(bank_info.get_extra_options()):
                name = 'option' + str(i)
                entry = ProxyEntry()
                entry.model_attribute = name
                setattr(self, name, entry)
                # Set the model attr too so it can be validated
                setattr(self.bank_model, name, u'')
                entry.props.data_type = 'str'
                entry.connect('validate', self._on_bank_option__validate,
                              bank_info, option)
                self._add_widget("<i>%s</i>:" % (api.escape(option.capitalize()), ),
                                 entry, options=True)
                entry.show()
                self._option_fields[option] = entry
                attributes.append(entry.model_attribute)
        else:
            bank_number_lbl.hide()

        self.bank_proxy = self.add_proxy(
            self.bank_model, attributes)
        self._fill_bank_account()
Exemplo n.º 15
0
def test_get_bank_info_by_number():
    with pytest.raises(NotImplementedError):
        get_bank_info_by_number(696969696699669696969699669)