Skip to content

Commit c117cdf

Browse files
Default invoice settings
1 parent d607c32 commit c117cdf

File tree

7 files changed

+115
-2
lines changed

7 files changed

+115
-2
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Generated by Django 4.2.11 on 2025-02-14 07:57
2+
3+
from django.db import migrations
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
("core", "0003_alter_currencyexchange_base_currency_and_more"),
10+
]
11+
12+
operations = [
13+
migrations.RemoveField(
14+
model_name="invoicesettings",
15+
name="site",
16+
),
17+
]
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Generated by Django 4.2.11 on 2025-02-14 08:04
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
("core", "0004_remove_invoicesettings_site"),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name="invoicesettings",
15+
name="is_default",
16+
field=models.BooleanField(
17+
default=False, help_text="If this is the default invoice settings."
18+
),
19+
),
20+
]

nxtbn/core/models.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,6 @@ class Meta:
162162
verbose_name_plural = "Site Settings"
163163

164164
class InvoiceSettings(models.Model): # This info will be seen in the invoice
165-
site = models.OneToOneField(Site, on_delete=models.CASCADE, null=True, blank=True, help_text="The site this configuration applies to.")
166165
store_name = models.CharField(max_length=100, blank=True, null=True, help_text="Name of the store.")
167166
store_address = models.TextField(blank=True, null=True, help_text="Physical address of the store.")
168167
city = models.CharField(max_length=100, blank=True, null=True, help_text="City of the store.")
@@ -171,6 +170,15 @@ class InvoiceSettings(models.Model): # This info will be seen in the invoice
171170
logo = models.ImageField(upload_to='logos/', blank=True, null=True, help_text="Logo of the site.")
172171
contact_email = models.EmailField(blank=True, null=True, help_text="Contact email for site administrators.")
173172
contact_phone = models.CharField(max_length=20, blank=True, null=True, help_text="Contact phone number for site administrators.")
173+
is_default = models.BooleanField(default=False, help_text="If this is the default invoice settings.")
174+
175+
def save(self, *args, **kwargs):
176+
if self.is_default:
177+
InvoiceSettings.objects.filter(is_default=True).update(is_default=False)
178+
else:
179+
if not InvoiceSettings.objects.filter(is_default=True).exists():
180+
raise ValidationError("There must be at least one default invoice setting.")
181+
super().save(*args, **kwargs)
174182

175183

176184

nxtbn/core/receivers.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ def create_default_site_settings(sender, **kwargs):
3131
)
3232

3333
InvoiceSettings.objects.create(
34-
site=site,
3534
store_name="nxtbn commerce",
3635
store_address="Default Store Address",
3736
city="Default City",
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Generated by Django 4.2.11 on 2025-02-14 07:57
2+
3+
from django.db import migrations
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
("payment", "0004_alter_payment_currency"),
10+
]
11+
12+
operations = [
13+
migrations.AlterModelOptions(
14+
name="payment",
15+
options={
16+
"permissions": [("CAN_INITIATE_PAYMENT_REFUND", "Can initiate refunds")]
17+
},
18+
),
19+
]
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Generated by Django 4.2.11 on 2025-02-14 07:57
2+
3+
from django.db import migrations
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
("users", "0005_user_is_store_admin_user_is_store_staff_and_more"),
10+
]
11+
12+
operations = [
13+
migrations.AlterModelOptions(
14+
name="user",
15+
options={
16+
"permissions": [
17+
("can_read_customer", "Can read customer"),
18+
("can_create_customer", "Can update customer"),
19+
]
20+
},
21+
),
22+
]
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Generated by Django 4.2.11 on 2025-02-14 07:57
2+
3+
from django.db import migrations
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
(
10+
"warehouse",
11+
"0011_stocktransfer_created_at_stocktransfer_last_modified_and_more",
12+
),
13+
]
14+
15+
operations = [
16+
migrations.AlterModelOptions(
17+
name="stocktransfer",
18+
options={
19+
"permissions": [
20+
("can_receive_transferred_stock", "Can receive transferred stock"),
21+
(
22+
"can_mark_stock_transfer_as_completed",
23+
"Can mark stock transfer as completed",
24+
),
25+
]
26+
},
27+
),
28+
]

0 commit comments

Comments
 (0)