Browse Source

Add Profile.bill_to field which goes on invoices.

pull/125/head
Pēteris Caune 8 years ago
parent
commit
dc76e4bdde
6 changed files with 65 additions and 2 deletions
  1. +1
    -1
      hc/accounts/admin.py
  2. +20
    -0
      hc/accounts/migrations/0008_profile_bill_to.py
  3. +1
    -0
      hc/accounts/models.py
  4. +20
    -0
      hc/api/migrations/0032_auto_20170608_1158.py
  5. +16
    -0
      hc/payments/tests/test_invoice.py
  6. +7
    -1
      templates/payments/invoice.html

+ 1
- 1
hc/accounts/admin.py View File

@ -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)


+ 20
- 0
hc/accounts/migrations/0008_profile_bill_to.py View File

@ -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),
),
]

+ 1
- 0
hc/accounts/models.py View File

@ -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()


+ 20
- 0
hc/api/migrations/0032_auto_20170608_1158.py View File

@ -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),
),
]

+ 16
- 0
hc/payments/tests/test_invoice.py View File

@ -25,6 +25,7 @@ class InvoiceTestCase(BaseTestCase):
self.client.login(username="[email protected]", password="password")
r = self.client.get("/invoice/abc123/")
self.assertContains(r, "ABC123") # tx.id in uppercase
self.assertContains(r, "[email protected]") # 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="[email protected]", 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="[email protected]", password="password")
r = self.client.get("/invoice/abc123/")
self.assertContains(r, "Alice and Partners")

+ 7
- 1
templates/payments/invoice.html View File

@ -53,7 +53,13 @@ VAT: LV44103100701
</table>
<p><strong>Bill to:</strong></p>
<p>{{ request.user.email }}</p>
<p>
{% if request.user.profile.bill_to %}
{{ request.user.profile.bill_to|linebreaksbr }}
{% else %}
{{ request.user.email }}
{% endif %}
</p>
<p class="text-center">
If you have a credit card on file it will be automatically charged within 24 hours.


Loading…
Cancel
Save