def test_changed_field(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.changed_field) history.last_due_date = Date(localtoday()) history.last_status = Payment.STATUS_PENDING view = self.store.find(PaymentChangeHistoryView, id=history.id).one() self.assertEquals(view.changed_field, u"Due Date") history.last_due_date = None view = self.store.find(PaymentChangeHistoryView, id=history.id).one() self.assertEquals(view.changed_field, u"Status")
def test_changed_field(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.changed_field) history.last_due_date = Date(localtoday()) history.last_status = Payment.STATUS_PENDING view = self.store.find(PaymentChangeHistoryView, id=history.id).one() self.assertEquals(view.changed_field, u'Due Date') history.last_due_date = None view = self.store.find(PaymentChangeHistoryView, id=history.id).one() self.assertEquals(view.changed_field, u'Status')
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 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_set_not_paid(self): sale = self.create_sale() self.add_product(sale) payment = self.add_payments(sale, method_type=u'check')[0] sale.order(self.current_user) sale.confirm(self.current_user) account = self.create_account() payment.method.destination_account = account payment.pay() # Verify if payment is referenced on account transaction. transactions = self.store.find(AccountTransaction, account=account, payment=payment) self.assertEqual(transactions.count(), 1) original_transaction = list(transactions)[0] self.assertEqual(original_transaction.operation_type, AccountTransaction.TYPE_IN) self.assertEqual(original_transaction.value, payment.value) entry = PaymentChangeHistory(payment=payment, change_reason=u'foo', store=self.store) payment.set_not_paid(entry) # Now that the payment was reverted, there should also be a reverted operation, # and the payment will not be referenced in transactions anymore. transactions = self.store.find(AccountTransaction, account=account, payment=payment) self.assertEqual(transactions.count(), 0) new_transactions = self.store.find(AccountTransaction, source_account=account) self.assertEqual(new_transactions.count(), 1) reversed_transaction = list(new_transactions)[0] self.assertEqual(reversed_transaction.operation_type, AccountTransaction.TYPE_OUT) self.assertEqual( self.store.find(AccountTransaction, payment=payment).count(), 0) # Verify all transactions - The created account, will be referenced as source # and destination account. query = Or(AccountTransaction.source_account == account, AccountTransaction.account == account) total_transactions = self.store.find(AccountTransaction, query).count() self.assertEqual(total_transactions, 2) payment.pay() self.assertEqual( self.store.find(AccountTransaction, payment=payment).count(), 1) total_transactions = self.store.find(AccountTransaction, query).count() self.assertEqual(total_transactions, 3)
def _remove_payment(self, payment): if payment.is_preview(): payment.group.remove_item(payment) payment.delete() elif payment.is_paid(): if not self._allow_remove_paid: return entry = PaymentChangeHistory(payment=payment, change_reason=_(u'Payment renegotiated'), store=self.store) payment.set_not_paid(entry) entry.new_status = Payment.STATUS_CANCELLED payment.cancel() else: payment.cancel() self._has_modified_payments = True self._update_payment_list() self.update_view()
def test_set_not_paid(self): sale = self.create_sale() self.add_product(sale) payment = self.add_payments(sale, method_type=u'check')[0] sale.order() sale.confirm() account = self.create_account() payment.method.destination_account = account payment.pay() self.assertEquals( self.store.find(AccountTransaction, payment=payment).count(), 1) self.assertEquals(account.transactions.count(), 1) self.assertEquals(account.transactions.sum(AccountTransaction.value), payment.value) entry = PaymentChangeHistory(payment=payment, change_reason=u'foo', store=self.store) payment.set_not_paid(entry) self.assertEquals(account.transactions.count(), 2) self.assertEquals(account.transactions.sum(AccountTransaction.value), 0) self.assertEquals( self.store.find(AccountTransaction, payment=payment).count(), 0) payment.pay() self.assertEquals( self.store.find(AccountTransaction, payment=payment).count(), 1) self.assertEquals(account.transactions.count(), 3) self.assertEquals(account.transactions.sum(AccountTransaction.value), payment.value)
def create_model(self, store): return PaymentChangeHistory(payment=self._payment, store=store)