diff --git a/weblate_web/tests.py b/weblate_web/tests.py index 8dfe1d383c..a334034ac4 100644 --- a/weblate_web/tests.py +++ b/weblate_web/tests.py @@ -542,19 +542,19 @@ def create_service(self, years=1, days=0, recurring="y", package="extended"): ), Package( name="hosted:test-1-m", - verbose="Hosted (basic)", + verbose="Weblate hosting (basic)", price=42, category=PackageCategory.PACKAGE_DEDICATED, ), Package( name="hosted:test-1", - verbose="Hosted (basic)", + verbose="Weblate hosting (basic)", price=420, category=PackageCategory.PACKAGE_DEDICATED, ), Package( name="hosted:test-2", - verbose="Hosted (upgraded)", + verbose="Weblate hosting (upgraded)", price=840, category=PackageCategory.PACKAGE_DEDICATED, ), @@ -1249,7 +1249,7 @@ def test_hosted_pay(self): self.assertRedirects(response, payment_url) response = self.client.post(payment_url, {"method": "pay"}, follow=True) self.assertRedirects(response, reverse("user")) - self.assertContains(response, "Weblate: Hosted (basic)") + self.assertContains(response, "Weblate hosting (basic)") service = Service.objects.get(pk=service.pk) hosted = service.hosted_subscriptions @@ -1281,7 +1281,7 @@ def test_hosted_pay_yearly(self): self.assertRedirects(response, payment_url) response = self.client.post(payment_url, {"method": "pay"}, follow=True) self.assertRedirects(response, reverse("user")) - self.assertContains(response, "Weblate: Hosted (basic)") + self.assertContains(response, "Weblate hosting (basic)") service = Service.objects.get(pk=service.pk) hosted = service.hosted_subscriptions @@ -1316,7 +1316,7 @@ def test_hosted_upgrade(self): self.assertRedirects(response, payment_url) response = self.client.post(payment_url, {"method": "pay"}, follow=True) self.assertRedirects(response, reverse("user")) - self.assertContains(response, "Weblate: Hosted (upgraded)") + self.assertContains(response, "Weblate hosting (upgraded)") service = Service.objects.get(pk=service.pk) hosted = service.hosted_subscriptions diff --git a/weblate_web/views.py b/weblate_web/views.py index f2442c51fd..ce81c01363 100644 --- a/weblate_web/views.py +++ b/weblate_web/views.py @@ -65,12 +65,14 @@ EditNameForm, MethodForm, ) +from weblate_web.invoices.models import Invoice, InvoiceCategory, InvoiceKind from weblate_web.models import ( PAYMENTS_ORIGIN, REWARD_LEVELS, TOPIC_DICT, Donation, Package, + PackageCategory, Post, Project, Service, @@ -867,14 +869,18 @@ def subscription_pay(request, pk): subscription.package = subscription.yearly_package subscription.save(update_fields=["package"]) with override("en"): - payment = Payment.objects.create( - amount=subscription.package.price, - # pylint: disable=no-member - description=f"Weblate: {subscription.package}", - recurring=subscription.package.get_repeat(), + customer = get_customer(request, subscription.service) + invoice = Invoice.objects.create( + customer=customer, extra={"subscription": subscription.pk}, - customer=get_customer(request, subscription.service), + vat_rate=customer.vat_rate, + kind=InvoiceKind.DRAFT, + category=InvoiceCategory.SUPPORT + if subscription.package.category == PackageCategory.PACKAGE_SUPPORT + else InvoiceCategory.HOSTING, ) + invoice.invoiceitem_set.create(package=subscription.package) + payment = invoice.create_payment(subscription.package.get_repeat()) return redirect(payment.get_payment_url()) @@ -910,15 +916,19 @@ def subscription_new(request): service = None subscription = Subscription(package=package) + customer = get_customer(request, service) with override("en"): - payment = Payment.objects.create( - amount=subscription.package.price, - # pylint: disable=no-member - description=f"Weblate: {subscription.package}", - recurring=subscription.package.get_repeat(), + invoice = Invoice.objects.create( + customer=customer, extra={"subscription": plan, "service": service.pk if service else None}, - customer=get_customer(request, service), + vat_rate=customer.vat_rate, + kind=InvoiceKind.DRAFT, + category=InvoiceCategory.SUPPORT + if subscription.package.category == PackageCategory.PACKAGE_SUPPORT + else InvoiceCategory.HOSTING, ) + invoice.invoiceitem_set.create(package=subscription.package) + payment = invoice.create_payment(subscription.package.get_repeat()) return redirect(payment.get_payment_url())