@@ -162,7 +162,6 @@ class Meta:
162
162
verbose_name_plural = "Site Settings"
163
163
164
164
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." )
166
165
store_name = models .CharField (max_length = 100 , blank = True , null = True , help_text = "Name of the store." )
167
166
store_address = models .TextField (blank = True , null = True , help_text = "Physical address of the store." )
168
167
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
171
170
logo = models .ImageField (upload_to = 'logos/' , blank = True , null = True , help_text = "Logo of the site." )
172
171
contact_email = models .EmailField (blank = True , null = True , help_text = "Contact email for site administrators." )
173
172
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 )
174
182
175
183
176
184
0 commit comments