Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add migrations for partially charged and partially refunded
Unknown2a09d807d288
diff --git a/saleor/payment/migrations/0002_transfer_payment_to_payment_method.py b/saleor/payment/migrations/0002_transfer_payment_to_payment_method.pyindex 55e8a946eb..03fc5ff97c 100644--- a/saleor/payment/migrations/0002_transfer_payment_to_payment_method.py+++ b/saleor/payment/migrations/0002_transfer_payment_to_payment_method.py@@ -23,11 +23,13 @@ def is_fully_refunded(payment):def get_charge_status(payment):if payment.status == PaymentStatus.CONFIRMED:- return ChargeStatus.CHARGED+ if payment.get_charge_amount() <= 0:+ return ChargeStatus.FULLY_CHARGED+ return ChargeStatus.PARTIALLY_CHARGEDif payment.status == PaymentStatus.REFUNDED:if is_fully_refunded(payment):return ChargeStatus.FULLY_REFUNDED- return ChargeStatus.CHARGED+ return ChargeStatus.PARTIALLY_REFUNDEDreturn ChargeStatus.NOT_CHARGEDdiff --git a/saleor/payment/migrations/0009_convert_to_partially_charged_and_partially_refunded.py b/saleor/payment/migrations/0009_convert_to_partially_charged_and_partially_refunded.pynew file mode 100644index 0000000000..3fa5c49a2f--- /dev/null+++ b/saleor/payment/migrations/0009_convert_to_partially_charged_and_partially_refunded.py@@ -0,0 +1,53 @@+# Generated by Django 2.1.4 on 2019-02-15 08:46++from django.db import migrations++from saleor.payment import ChargeStatus, TransactionKind+++CHARGED = 'charged'+++def is_fully_charged(payment):+ if payment.total - payment.captured_amount > 0:+ return False+ return True+++def convert_charged_to_paritally_charged_and_partially_refunded(apps, schema_editor):+ PaymentModel = apps.get_model('payment', 'Payment')+ for payment in PaymentModel.objects.all():+ if payment.charge_status == CHARGED:+ if is_fully_charged(payment):+ payment.charge_status = ChargeStatus.FULLY_CHARGED+ elif payment.transactions.filter(+ kind=TransactionKind.REFUND,+ is_success=True).first() is not None:+ payment.charge_status = ChargeStatus.PARTIALLY_REFUNDED+ else:+ payment.charge_status = ChargeStatus.PARTIALLY_CHARGED+ payment.save()+++def convert_paritally_charged_and_partially_refunded_to_charged(apps, schema_editor):+ PaymentModel = apps.get_model('payment', 'Payment')+ for payment in PaymentModel.objects.all():+ if payment.charge_status in (+ ChargeStatus.PARTIALLY_CHARGED,+ ChargeStatus.FULLY_CHARGED,+ ChargeStatus.PARTIALLY_REFUNDED):+ payment.charge_status = CHARGED+ payment.save()+++class Migration(migrations.Migration):++ dependencies = [+ ('payment', '0008_merge_20190214_0447'),+ ]++ operations = [+ migrations.RunPython(+ convert_charged_to_paritally_charged_and_partially_refunded,+ convert_paritally_charged_and_partially_refunded_to_charged),+ ]