def pay(self, paid_date=None, paid_value=None, account=None): """Pay the current payment set its status as :obj:`.STATUS_PAID`""" if self.status != Payment.STATUS_PENDING: raise ValueError(_(u"This payment is already paid.")) self._check_status(self.STATUS_PENDING, u'pay') paid_value = paid_value or (self.value - self.discount + self.interest) self.paid_value = paid_value self.paid_date = paid_date or TransactionTimestamp() self.status = self.STATUS_PAID if (self.is_separate_payment() or self.method.operation.create_transaction()): AccountTransaction.create_from_payment(self, account) sale = self.group and self.group.sale if sale: transaction = IPaymentTransaction(sale) transaction.create_commission(self) if self.value == self.paid_value: msg = _(u"{method} payment with value {value:.2f} was paid").format( method=self.method.method_name, value=self.value) else: msg = _(u"{method} payment with value original value " u"{original_value:.2f} was paid with value " u"{value:.2f}").format( method=self.method.method_name, original_value=self.value, value=self.paid_value) Event.log(Event.TYPE_PAYMENT, msg.capitalize())
def pay(self, paid_date=None, paid_value=None, source_account=None, destination_account=None, account_transaction_number=None): """Pay the current payment set its status as :obj:`.STATUS_PAID` If this payment belongs to a sale, and all other payments from the sale are paid then the sale will be set as paid. """ if self.status != Payment.STATUS_PENDING: raise ValueError(_(u"This payment is already paid.")) self._check_status(self.STATUS_PENDING, u'pay') paid_value = paid_value or (self.value - self.discount + self.interest) self.paid_value = paid_value self.paid_date = paid_date or TransactionTimestamp() self.status = self.STATUS_PAID if (self.is_separate_payment() or self.method.operation.create_transaction()): AccountTransaction.create_from_payment( self, code=account_transaction_number, source_account=source_account, destination_account=destination_account) sale = self.group and self.group.sale if sale: sale.create_commission(self) # When paying payments of a sale, check if the other payments are # paid. If they are, this means you can change the sale status to # paid as well. if sale.can_set_paid(): sale.set_paid() if self.value == self.paid_value: msg = _( u"{method} payment with value {value:.2f} was paid").format( method=self.method.method_name, value=self.value) else: msg = _(u"{method} payment with value original value " u"{original_value:.2f} was paid with value " u"{value:.2f}").format(method=self.method.method_name, original_value=self.value, value=self.paid_value) Event.log(self.store, Event.TYPE_PAYMENT, msg.capitalize())
def pay(self, paid_date=None, paid_value=None, source_account=None, destination_account=None, account_transaction_number=None): """Pay the current payment set its status as :obj:`.STATUS_PAID` If this payment belongs to a sale, and all other payments from the sale are paid then the sale will be set as paid. """ if self.status != Payment.STATUS_PENDING: raise ValueError(_(u"This payment is already paid.")) self._check_status(self.STATUS_PENDING, u'pay') paid_value = paid_value or (self.value - self.discount + self.interest) self.paid_value = paid_value self.paid_date = paid_date or TransactionTimestamp() self.status = self.STATUS_PAID if (self.is_separate_payment() or self.method.operation.create_transaction()): AccountTransaction.create_from_payment( self, code=account_transaction_number, source_account=source_account, destination_account=destination_account) sale = self.group and self.group.sale if sale: sale.create_commission(self) # When paying payments of a sale, check if the other payments are # paid. If they are, this means you can change the sale status to # paid as well. if sale.can_set_paid(): sale.set_paid() if self.value == self.paid_value: msg = _(u"{method} payment with value {value:.2f} was paid").format( method=self.method.method_name, value=self.value) else: msg = _(u"{method} payment with value original value " u"{original_value:.2f} was paid with value " u"{value:.2f}").format(method=self.method.method_name, original_value=self.value, value=self.paid_value) Event.log(self.store, Event.TYPE_PAYMENT, msg.capitalize())
def test_create_from_payment(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 self.assertRaises(PaymentError, AccountTransaction.create_from_payment, payment) payment.pay() transaction = AccountTransaction.create_from_payment(payment) imbalance_account = sysparam(self.store).IMBALANCE_ACCOUNT self.assertEquals(transaction.source_account, imbalance_account) self.assertEquals(transaction.account, account) self.assertEquals(transaction.payment, payment)
def test_create_from_payment(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 self.assertRaises(PaymentError, AccountTransaction.create_from_payment, payment) payment.pay() transaction = AccountTransaction.create_from_payment(payment) imbalance_account = sysparam.get_object(self.store, 'IMBALANCE_ACCOUNT') self.assertEquals(transaction.source_account, imbalance_account) self.assertEquals(transaction.account, account) self.assertEquals(transaction.payment, payment)
def test_create_from_payment(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 with self.assertRaisesRegex(PaymentError, "Payment needs to be paid"): AccountTransaction.create_from_payment(payment) payment.pay() transaction = AccountTransaction.create_from_payment(payment) imbalance_account = sysparam.get_object(self.store, 'IMBALANCE_ACCOUNT') self.assertEqual(transaction.source_account, imbalance_account) self.assertEqual(transaction.account, account) self.assertEqual(transaction.payment, payment) self.assertEqual(transaction.operation_type, AccountTransaction.TYPE_IN) # Payment from purchase. purchase = self.create_purchase_order() purchase.status = PurchaseOrder.ORDER_PENDING purchase.add_item(self.create_sellable(), 1) payment = self.add_payments(purchase, method_type=u'money')[0] purchase.confirm() account = self.create_account() payment.method.destination_account = account with self.assertRaisesRegex(PaymentError, "Payment needs to be paid"): AccountTransaction.create_from_payment(payment) payment.pay() transaction = AccountTransaction.create_from_payment(payment) imbalance_account = sysparam.get_object(self.store, 'IMBALANCE_ACCOUNT') self.assertEqual(transaction.source_account, account) self.assertEqual(transaction.account, imbalance_account) self.assertEqual(transaction.payment, payment) self.assertEqual(transaction.operation_type, AccountTransaction.TYPE_OUT)
def test_create_from_payment(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 with self.assertRaisesRegex(PaymentError, "Payment needs to be paid"): AccountTransaction.create_from_payment(payment) payment.pay() transaction = AccountTransaction.create_from_payment(payment) imbalance_account = sysparam.get_object(self.store, 'IMBALANCE_ACCOUNT') self.assertEqual(transaction.source_account, imbalance_account) self.assertEqual(transaction.account, account) self.assertEqual(transaction.payment, payment) self.assertEqual(transaction.operation_type, AccountTransaction.TYPE_IN) # Payment from purchase. purchase = self.create_purchase_order() purchase.status = PurchaseOrder.ORDER_PENDING purchase.add_item(self.create_sellable(), 1) payment = self.add_payments(purchase, method_type=u'money')[0] purchase.confirm() account = self.create_account() payment.method.destination_account = account with self.assertRaisesRegex(PaymentError, "Payment needs to be paid"): AccountTransaction.create_from_payment(payment) payment.pay() transaction = AccountTransaction.create_from_payment(payment) imbalance_account = sysparam.get_object(self.store, 'IMBALANCE_ACCOUNT') self.assertEqual(transaction.source_account, account) self.assertEqual(transaction.account, imbalance_account) self.assertEqual(transaction.payment, payment) self.assertEqual(transaction.operation_type, AccountTransaction.TYPE_OUT)