def instrucoes(self): instructions = [] payment = self.payment # FIXME: Penalty and interest are also defined on the payment method. We # should use that information instead. We could also add a discount # information on the payment method. penalty = currency(self.penalty_percentage / 100 * payment.value) interest = currency(self.interest_percentage / 100 * payment.value) discount = currency(self.discount_percentage / 100 * payment.value) data = sysparam.get_string('BILL_INSTRUCTIONS') for line in data.split('\n')[:4]: line = line.replace('$DATE', payment.due_date.strftime('%d/%m/%Y')) line = line.replace('$PENALTY', converter.as_string(currency, penalty)) line = line.replace('$INTEREST', converter.as_string(currency, interest)) line = line.replace('$DISCOUNT', converter.as_string(currency, discount)) line = line.replace('$INVOICE_NUMBER', str(self.numero_documento)) instructions.append(line) # FIXME: Only add this if not a stoq.link subscriber #instructions.append('') #instructions.append('\n' + _('Stoq Retail Management') + ' - www.stoq.com.br') return instructions
def _get_instrucoes(self, payment): instructions = [] sale = payment.group.sale if sale: invoice_number = sale.invoice_number else: invoice_number = payment.identifier penalty = currency( (sysparam.get_decimal('BILL_PENALTY') / 100) * payment.value) interest = currency( (sysparam.get_decimal('BILL_INTEREST') / 100) * payment.value) discount = currency( (sysparam.get_decimal('BILL_DISCOUNT') / 100) * payment.value) data = sysparam.get_string('BILL_INSTRUCTIONS') for line in data.split('\n')[:4]: line = line.replace('$DATE', payment.due_date.strftime('%d/%m/%Y')) line = line.replace('$PENALTY', converter.as_string(currency, penalty)) line = line.replace('$INTEREST', converter.as_string(currency, interest)) line = line.replace('$DISCOUNT', converter.as_string(currency, discount)) line = line.replace('$INVOICE_NUMBER', str(invoice_number)) instructions.append(line) instructions.append('') instructions.append('\n' + _('Stoq Retail Management') + ' - www.stoq.com.br') return instructions
def _get_instrucoes(self, payment): instructions = [] sale = payment.group.sale if sale: invoice_number = sale.invoice.invoice_number else: invoice_number = payment.identifier penalty = currency( (sysparam.get_decimal('BILL_PENALTY') / 100) * payment.value) interest = currency( (sysparam.get_decimal('BILL_INTEREST') / 100) * payment.value) discount = currency( (sysparam.get_decimal('BILL_DISCOUNT') / 100) * payment.value) data = sysparam.get_string('BILL_INSTRUCTIONS') for line in data.split('\n')[:4]: line = line.replace('$DATE', payment.due_date.strftime('%d/%m/%Y')) line = line.replace('$PENALTY', converter.as_string(currency, penalty)) line = line.replace('$INTEREST', converter.as_string(currency, interest)) line = line.replace('$DISCOUNT', converter.as_string(currency, discount)) line = line.replace('$INVOICE_NUMBER', str(invoice_number)) instructions.append(line) instructions.append('') instructions.append('\n' + _('Stoq Retail Management') + ' - www.stoq.com.br') return instructions
def post_init(self): self.register_validate_function(self._validation_func) self.force_validation() before_debt = currency(self.model.sale_total - self.model.paid_total) now_debt = currency(before_debt - self.model.returned_total) info(_("The client's debt has changed. " "Use this step to adjust the payments."), _("The debt before was %s and now is %s. Cancel some unpaid " "installments and create new ones.") % ( converter.as_string(currency, before_debt), converter.as_string(currency, now_debt)))
def post_init(self): self.register_validate_function(self._validation_func) self.force_validation() before_debt = currency(self.model.sale_total - self.model.paid_total) now_debt = currency(before_debt - self.model.returned_total) info( _("The client's debt has changed. " "Use this step to adjust the payments."), _("The debt before was %s and now is %s. Cancel some unpaid " "installments and create new ones.") % (converter.as_string(currency, before_debt), converter.as_string(currency, now_debt)))
def _set_credit_visible(self, client, total_amount): if client is None: self.method_set_visible(u'credit', False) return credit_widget = self._widgets.get(u'credit', None) if credit_widget: credit_balance = client.credit_account_balance credit_widget.set_label(_("Credit (%s)") % ( converter.as_string(currency, credit_balance))) self.method_set_visible(u'credit', bool(credit_balance)) self.method_set_sensitive(u'credit', credit_balance >= total_amount)
def _show_trade_infobar(self, trade): self._remove_trade_infobar() if not trade: return button = gtk.Button(_("Cancel trade")) button.connect('clicked', self._on_remove_trade_button__clicked) value = converter.as_string(currency, self._trade.returned_total) msg = _("There is a trade with value %s in progress...\n" "When checking out, it will be used as part of " "the payment.") % (value, ) self._trade_infobar = self.window.add_info_bar( gtk.MESSAGE_INFO, msg, action_widget=button)
def _show_trade_infobar(self, trade): self._remove_trade_infobar() if not trade: return button = gtk.Button(_("Cancel trade")) button.connect('clicked', self._on_remove_trade_button__clicked) value = converter.as_string(currency, self._trade.returned_total) msg = _("There is a trade with value %s in progress...\n" "When checking out, it will be used as part of " "the payment.") % (value, ) self._trade_infobar = self.window.add_info_bar(gtk.MESSAGE_INFO, msg, action_widget=button)
def test_to_value(self): payment = self.create_payment() history = PaymentChangeHistory(payment=payment, change_reason=u"Teste test test") view = self.store.find(PaymentChangeHistoryView, id=history.id).one() self.assertIsNone(view.to_value) history.new_due_date = Date(localtoday()) due_date = converter.as_string(datetime.date, history.new_due_date) history.new_status = Payment.STATUS_CONFIRMED view = self.store.find(PaymentChangeHistoryView, id=history.id).one() self.assertEquals(view.to_value, due_date) history.new_due_date = None status = Payment.statuses[history.new_status] view = self.store.find(PaymentChangeHistoryView, id=history.id).one() self.assertEquals(view.to_value, status)
def set_client(self, client, total_amount): self.select_method(u'credit') if client and client.credit_account_balance > 0: client_credit = converter.as_string( currency, client.credit_account_balance) self._widgets[u'credit'].set_label( _("Credit (%s)") % client_credit) has_enough_credit = client.credit_account_balance >= total_amount if has_enough_credit: self.select_method(u'credit') else: self.select_method(u'money') self._widgets[u'credit'].set_sensitive(has_enough_credit) else: self.select_method(u'money') self._client = client
def test_to_value(self): payment = self.create_payment() history = PaymentChangeHistory(payment=payment, change_reason=u'Teste test test') view = self.store.find(PaymentChangeHistoryView, id=history.id).one() self.assertIsNotNone(view.to_value) history.new_due_date = Date(localtoday()) due_date = converter.as_string(datetime.date, history.new_due_date) history.new_status = Payment.STATUS_CONFIRMED view = self.store.find(PaymentChangeHistoryView, id=history.id).one() self.assertEquals(view.to_value, due_date) history.new_due_date = None status = Payment.statuses[history.new_status] view = self.store.find(PaymentChangeHistoryView, id=history.id).one() self.assertEquals(view.to_value, status)
def test_from_value(self): payment = self.create_payment() history = PaymentChangeHistory(payment=payment, change_reason=u'Teste test test') view = self.store.find(PaymentChangeHistoryView, id=history.id).one() self.assertIsNone(view.from_value) history.last_due_date = Date(localtoday()) due_date = converter.as_string(datetime.date, history.last_due_date) history.last_status = Payment.STATUS_PENDING view = self.store.find(PaymentChangeHistoryView, id=history.id).one() self.assertEquals(view.from_value, due_date) history.last_due_date = None status = Payment.statuses[history.last_status] view = self.store.find(PaymentChangeHistoryView, id=history.id).one() self.assertEquals(view.from_value, status)
def test_cancel_trade(self, run_dialog): pos = self._get_pos_with_open_till() trade = self.create_trade() run_dialog.return_value = trade self.activate(pos.NewTrade) self.assertIsNotNone(pos._trade_infobar) value = converter.as_string(currency, trade.returned_total) msg = (("There is a trade with value %s in progress...\n" "When checking out, it will be used as part of " "the payment.") % value) self.assertEquals(pos._trade_infobar.label.get_label(), msg) remove_button = pos._trade_infobar.get_action_area().get_children()[0] with mock.patch('stoq.gui.pos.yesno') as yesno: self.click(remove_button) yesno.assertEquals("Do you really want to cancel the trade in progress?", gtk.RESPONSE_NO, "Cancel trade", "Don't cancel")
def test_cancel_trade(self, run_dialog): pos = self._get_pos_with_open_till() trade = self.create_trade() run_dialog.return_value = trade self.activate(pos.NewTrade) self.assertIsNotNone(pos._trade_infobar) value = converter.as_string(currency, trade.returned_total) msg = (("There is a trade with value %s in progress...\n" "When checking out, it will be used as part of " "the payment.") % value) self.assertEqual(pos._trade_infobar.label.get_label(), msg) remove_button = pos._trade_infobar.get_action_area().get_children()[0] with mock.patch('stoq.gui.pos.yesno') as yesno: self.click(remove_button) yesno.assert_called_once_with( "Do you really want to cancel the trade in progress?", Gtk.ResponseType.NO, "Cancel trade", "Don't cancel")
def _update_totals(self): subtotal = self._get_subtotal() text = _(u"Total: %s") % converter.as_string(currency, subtotal) self.order_total_label.set_text(text)
def _update_payment_total(self): balance = currency(self._get_total_paid_payment()) text = _(u"Total payments: %s") % converter.as_string(currency, balance) self.total_payment_label.set_text(text)
def _update_total(self): balance = currency(self._get_till_balance()) text = _(u"Total: %s") % converter.as_string(currency, balance) self.total_label.set_text(text)
def to_value(self): if self.new_due_date: return converter.as_string(datetime.date, self.new_due_date) elif self.new_status: return Payment.statuses[self.new_status]
def from_value(self): if self.last_due_date: return converter.as_string(datetime.date, self.last_due_date) elif self.last_status: return Payment.statuses[self.last_status]