From dc76e4bdde3d871de9ea5faa879bcb93c8cecdd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C4=93teris=20Caune?= Date: Thu, 8 Jun 2017 15:07:57 +0300 Subject: [PATCH] Add Profile.bill_to field which goes on invoices. --- hc/accounts/admin.py | 2 +- .../migrations/0008_profile_bill_to.py | 20 +++++++++++++++++++ hc/accounts/models.py | 1 + hc/api/migrations/0032_auto_20170608_1158.py | 20 +++++++++++++++++++ hc/payments/tests/test_invoice.py | 16 +++++++++++++++ templates/payments/invoice.html | 8 +++++++- 6 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 hc/accounts/migrations/0008_profile_bill_to.py create mode 100644 hc/api/migrations/0032_auto_20170608_1158.py diff --git a/hc/accounts/admin.py b/hc/accounts/admin.py index 81491d59..104fa759 100644 --- a/hc/accounts/admin.py +++ b/hc/accounts/admin.py @@ -26,7 +26,7 @@ class ProfileFieldset(Fieldset): class TeamFieldset(Fieldset): name = "Team" fields = ("team_name", "team_access_allowed", "check_limit", - "ping_log_limit") + "ping_log_limit", "bill_to") @admin.register(Profile) diff --git a/hc/accounts/migrations/0008_profile_bill_to.py b/hc/accounts/migrations/0008_profile_bill_to.py new file mode 100644 index 00000000..e2d492f9 --- /dev/null +++ b/hc/accounts/migrations/0008_profile_bill_to.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.1 on 2017-06-08 11:58 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('accounts', '0007_profile_check_limit'), + ] + + operations = [ + migrations.AddField( + model_name='profile', + name='bill_to', + field=models.TextField(blank=True), + ), + ] diff --git a/hc/accounts/models.py b/hc/accounts/models.py index da0f13fc..68280fdc 100644 --- a/hc/accounts/models.py +++ b/hc/accounts/models.py @@ -38,6 +38,7 @@ class Profile(models.Model): token = models.CharField(max_length=128, blank=True) api_key = models.CharField(max_length=128, blank=True) current_team = models.ForeignKey("self", models.SET_NULL, null=True) + bill_to = models.TextField(blank=True) objects = ProfileManager() diff --git a/hc/api/migrations/0032_auto_20170608_1158.py b/hc/api/migrations/0032_auto_20170608_1158.py new file mode 100644 index 00000000..00c1ac5f --- /dev/null +++ b/hc/api/migrations/0032_auto_20170608_1158.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.1 on 2017-06-08 11:58 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0031_auto_20170509_1320'), + ] + + operations = [ + migrations.AlterField( + model_name='channel', + name='kind', + field=models.CharField(choices=[('email', 'Email'), ('webhook', 'Webhook'), ('hipchat', 'HipChat'), ('slack', 'Slack'), ('pd', 'PagerDuty'), ('po', 'Pushover'), ('pushbullet', 'Pushbullet'), ('opsgenie', 'OpsGenie'), ('victorops', 'VictorOps'), ('discord', 'Discord'), ('telegram', 'Telegram')], max_length=20), + ), + ] diff --git a/hc/payments/tests/test_invoice.py b/hc/payments/tests/test_invoice.py index 5a94c5ab..cb0e3dae 100644 --- a/hc/payments/tests/test_invoice.py +++ b/hc/payments/tests/test_invoice.py @@ -25,6 +25,7 @@ class InvoiceTestCase(BaseTestCase): self.client.login(username="alice@example.org", password="password") r = self.client.get("/invoice/abc123/") self.assertContains(r, "ABC123") # tx.id in uppercase + self.assertContains(r, "alice@example.org") # bill to @patch("hc.payments.views.braintree") def test_it_checks_customer_id(self, mock_braintree): @@ -38,3 +39,18 @@ class InvoiceTestCase(BaseTestCase): self.client.login(username="alice@example.org", password="password") r = self.client.get("/invoice/abc123/") self.assertEqual(r.status_code, 403) + + @patch("hc.payments.views.braintree") + def test_it_shows_company_data(self, mock_braintree): + self.profile.bill_to = "Alice and Partners" + self.profile.save() + + tx = Mock() + tx.id = "abc123" + tx.customer_details.id = "test-customer-id" + tx.created_at = None + mock_braintree.Transaction.find.return_value = tx + + self.client.login(username="alice@example.org", password="password") + r = self.client.get("/invoice/abc123/") + self.assertContains(r, "Alice and Partners") diff --git a/templates/payments/invoice.html b/templates/payments/invoice.html index f6d31a21..4cab0104 100644 --- a/templates/payments/invoice.html +++ b/templates/payments/invoice.html @@ -53,7 +53,13 @@ VAT: LV44103100701

Bill to:

-

{{ request.user.email }}

+

+{% if request.user.profile.bill_to %} + {{ request.user.profile.bill_to|linebreaksbr }} +{% else %} + {{ request.user.email }} +{% endif %} +

If you have a credit card on file it will be automatically charged within 24 hours.