add customer field to credit notes for when they are not related to a user directly
This commit is contained in:
parent
7cf8085829
commit
c0f2478819
32
src/shop/migrations/0050_auto_20170916_1336.py
Normal file
32
src/shop/migrations/0050_auto_20170916_1336.py
Normal 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'),
|
||||||
|
),
|
||||||
|
]
|
|
@ -380,33 +380,70 @@ class CreditNote(CreatedUpdatedModel):
|
||||||
class Meta:
|
class Meta:
|
||||||
ordering = ['-created']
|
ordering = ['-created']
|
||||||
|
|
||||||
amount = models.DecimalField(max_digits=10, decimal_places=2)
|
amount = models.DecimalField(
|
||||||
text = models.TextField()
|
max_digits=10,
|
||||||
|
decimal_places=2
|
||||||
|
)
|
||||||
|
|
||||||
|
text = models.TextField(
|
||||||
|
help_text="Description of what this credit note covers"
|
||||||
|
)
|
||||||
|
|
||||||
pdf = models.FileField(
|
pdf = models.FileField(
|
||||||
null=True,
|
null=True,
|
||||||
blank=True,
|
blank=True,
|
||||||
upload_to='creditnotes/'
|
upload_to='creditnotes/'
|
||||||
)
|
)
|
||||||
|
|
||||||
user = models.ForeignKey(
|
user = models.ForeignKey(
|
||||||
'auth.User',
|
'auth.User',
|
||||||
verbose_name=_('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',
|
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(
|
paid = models.BooleanField(
|
||||||
verbose_name=_('Paid?'),
|
verbose_name=_('Paid?'),
|
||||||
help_text=_('Whether the amount in this creditnote has been paid back to the customer.'),
|
help_text=_('Whether the amount in this creditnote has been paid back to the customer.'),
|
||||||
default=False,
|
default=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
sent_to_customer = models.BooleanField(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):
|
def __str__(self):
|
||||||
return 'creditnote#%s - %s DKK (sent to %s: %s)' % (
|
if self.user:
|
||||||
self.id,
|
return 'creditnoote#%s - %s DKK (customer: user %s)' % (
|
||||||
self.amount,
|
self.id,
|
||||||
self.user.email,
|
self.amount,
|
||||||
self.sent_to_customer,
|
self.user.email,
|
||||||
)
|
)
|
||||||
|
else:
|
||||||
|
return 'creditnoote#%s - %s DKK (customer: user %s)' % (
|
||||||
|
self.id,
|
||||||
|
self.amount,
|
||||||
|
self.customer,
|
||||||
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def vat(self):
|
def vat(self):
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
<h3>Customer: {{ creditnote.user.email }}</h3>
|
<h3>Customer: {% if creditnote.user %}{{ creditnote.user.email }}{% else %}{{ creditnote.customer }}{% endif %}</h3>
|
||||||
<br>
|
<br>
|
||||||
<h2>CREDITNOTE</h2>
|
<h2>CREDITNOTE</h2>
|
||||||
<table style="width:90%; margin:1em;">
|
<table style="width:90%; margin:1em;">
|
||||||
|
|
Loading…
Reference in a new issue