add customer field to credit notes for when they are not related to a user directly

This commit is contained in:
Thomas Steen Rasmussen 2017-09-17 14:20:21 +02:00
parent 7cf8085829
commit c0f2478819
3 changed files with 79 additions and 10 deletions

View file

@ -0,0 +1,32 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.5 on 2017-09-16 11:36
from __future__ import unicode_literals
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('shop', '0049_auto_20170914_2034'),
]
operations = [
migrations.AddField(
model_name='creditnote',
name='customer',
field=models.TextField(blank=True, default='', help_text='Customer info if no user is selected'),
),
migrations.AlterField(
model_name='creditnote',
name='text',
field=models.TextField(help_text='Description of what this credit note covers'),
),
migrations.AlterField(
model_name='creditnote',
name='user',
field=models.ForeignKey(blank=True, help_text='The user this credit note belongs to, if any.', null=True, on_delete=django.db.models.deletion.CASCADE, related_name='creditnotes', to=settings.AUTH_USER_MODEL, verbose_name='User'),
),
]

View file

@ -380,32 +380,69 @@ class CreditNote(CreatedUpdatedModel):
class Meta:
ordering = ['-created']
amount = models.DecimalField(max_digits=10, decimal_places=2)
text = models.TextField()
amount = models.DecimalField(
max_digits=10,
decimal_places=2
)
text = models.TextField(
help_text="Description of what this credit note covers"
)
pdf = models.FileField(
null=True,
blank=True,
upload_to='creditnotes/'
)
user = models.ForeignKey(
'auth.User',
verbose_name=_('User'),
help_text=_('The user this credit note belongs to.'),
help_text=_('The user this credit note belongs to, if any.'),
related_name='creditnotes',
null=True,
blank=True
)
customer = models.TextField(
help_text="Customer info if no user is selected",
blank=True,
default='',
)
paid = models.BooleanField(
verbose_name=_('Paid?'),
help_text=_('Whether the amount in this creditnote has been paid back to the customer.'),
default=False,
)
sent_to_customer = models.BooleanField(default=False)
def clean(self):
errors = []
if self.user and self.customer:
msg = "Customer info should be blank if a user is selected."
errors.append(ValidationError({'user', msg}))
errors.append(ValidationError({'customer', msg}))
if not self.user and not self.customer:
msg = "Either pick a user or fill in Customer info"
errors.append(ValidationError({'user', msg}))
errors.append(ValidationError({'customer', msg}))
if errors:
raise ValidationError(errors)
def __str__(self):
return 'creditnote#%s - %s DKK (sent to %s: %s)' % (
if self.user:
return 'creditnoote#%s - %s DKK (customer: user %s)' % (
self.id,
self.amount,
self.user.email,
self.sent_to_customer,
)
else:
return 'creditnoote#%s - %s DKK (customer: user %s)' % (
self.id,
self.amount,
self.customer,
)
@property

View file

@ -13,7 +13,7 @@
</td>
</tr>
</table>
<h3>Customer: {{ creditnote.user.email }}</h3>
<h3>Customer: {% if creditnote.user %}{{ creditnote.user.email }}{% else %}{{ creditnote.customer }}{% endif %}</h3>
<br>
<h2>CREDITNOTE</h2>
<table style="width:90%; margin:1em;">