mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Use set_null instead
This commit is contained in:
parent
71a0d8159e
commit
132f4aa82e
@ -21,7 +21,6 @@ class CompanyResource(ModelResource):
|
|||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Company
|
model = Company
|
||||||
exclude = ('is_deleted', )
|
|
||||||
skip_unchanged = True
|
skip_unchanged = True
|
||||||
report_skipped = False
|
report_skipped = False
|
||||||
clean_model_instances = True
|
clean_model_instances = True
|
||||||
@ -38,14 +37,6 @@ class CompanyAdmin(ImportExportModelAdmin):
|
|||||||
'description',
|
'description',
|
||||||
]
|
]
|
||||||
|
|
||||||
exclude = ('is_deleted',)
|
|
||||||
|
|
||||||
def has_delete_permission(self, request, obj=None):
|
|
||||||
"""Magic objects are not allowd to be deleted"""
|
|
||||||
if obj and obj.is_deleted:
|
|
||||||
return False
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
class SupplierPartResource(ModelResource):
|
class SupplierPartResource(ModelResource):
|
||||||
"""
|
"""
|
||||||
|
@ -60,20 +60,6 @@ def rename_company_image(instance, filename):
|
|||||||
return os.path.join(base, fn)
|
return os.path.join(base, fn)
|
||||||
|
|
||||||
|
|
||||||
def get_deleted_company():
|
|
||||||
"""
|
|
||||||
Returns the deleted company object
|
|
||||||
"""
|
|
||||||
return Company.objects.get_or_create(
|
|
||||||
name='deleted',
|
|
||||||
email='deleted',
|
|
||||||
is_deleted=True,
|
|
||||||
is_customer=True,
|
|
||||||
is_supplier=True,
|
|
||||||
is_manufacturer=True
|
|
||||||
)[0]
|
|
||||||
|
|
||||||
|
|
||||||
class Company(models.Model):
|
class Company(models.Model):
|
||||||
""" A Company object represents an external company.
|
""" A Company object represents an external company.
|
||||||
It may be a supplier or a customer or a manufacturer (or a combination)
|
It may be a supplier or a customer or a manufacturer (or a combination)
|
||||||
@ -161,8 +147,6 @@ class Company(models.Model):
|
|||||||
|
|
||||||
is_manufacturer = models.BooleanField(default=False, verbose_name=_('is manufacturer'), help_text=_('Does this company manufacture parts?'))
|
is_manufacturer = models.BooleanField(default=False, verbose_name=_('is manufacturer'), help_text=_('Does this company manufacture parts?'))
|
||||||
|
|
||||||
is_deleted = models.BooleanField(default=False, verbose_name=_('is deleted'), help_text=_('Is this company a deleted placeholder?'))
|
|
||||||
|
|
||||||
currency = models.CharField(
|
currency = models.CharField(
|
||||||
max_length=3,
|
max_length=3,
|
||||||
verbose_name=_('Currency'),
|
verbose_name=_('Currency'),
|
||||||
@ -282,18 +266,6 @@ class Company(models.Model):
|
|||||||
|
|
||||||
return self.purchase_orders.filter(status__in=PurchaseOrderStatus.FAILED)
|
return self.purchase_orders.filter(status__in=PurchaseOrderStatus.FAILED)
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
|
||||||
"""Save the instance, unless it is the magic already deleted object"""
|
|
||||||
if self.pk and self.is_deleted:
|
|
||||||
raise PermissionDenied(_('This company is a placeholder and can not be updated'))
|
|
||||||
return super().save(*args, **kwargs)
|
|
||||||
|
|
||||||
def delete(self, *args, **kwargs):
|
|
||||||
"""Delete the instance, unless it is the magic already deleted object"""
|
|
||||||
if self.is_deleted:
|
|
||||||
raise PermissionDenied(_('This company is a placeholder and can not be deleted'))
|
|
||||||
return super().delete(*args, **kwargs)
|
|
||||||
|
|
||||||
|
|
||||||
class Contact(models.Model):
|
class Contact(models.Model):
|
||||||
""" A Contact represents a person who works at a particular company.
|
""" A Contact represents a person who works at a particular company.
|
||||||
|
@ -24,7 +24,7 @@ from mptt.models import TreeForeignKey
|
|||||||
from users import models as UserModels
|
from users import models as UserModels
|
||||||
from part import models as PartModels
|
from part import models as PartModels
|
||||||
from stock import models as stock_models
|
from stock import models as stock_models
|
||||||
from company.models import Company, SupplierPart, get_deleted_company
|
from company.models import Company, SupplierPart
|
||||||
from plugin.events import trigger_event
|
from plugin.events import trigger_event
|
||||||
|
|
||||||
import InvenTree.helpers
|
import InvenTree.helpers
|
||||||
@ -219,7 +219,7 @@ class PurchaseOrder(Order):
|
|||||||
help_text=_('Purchase order status'))
|
help_text=_('Purchase order status'))
|
||||||
|
|
||||||
supplier = models.ForeignKey(
|
supplier = models.ForeignKey(
|
||||||
Company, on_delete=models.SET(get_deleted_company),
|
Company, on_delete=models.SET_NULL,
|
||||||
limit_choices_to={
|
limit_choices_to={
|
||||||
'is_supplier': True,
|
'is_supplier': True,
|
||||||
},
|
},
|
||||||
@ -567,7 +567,7 @@ class SalesOrder(Order):
|
|||||||
|
|
||||||
customer = models.ForeignKey(
|
customer = models.ForeignKey(
|
||||||
Company,
|
Company,
|
||||||
on_delete=models.SET(get_deleted_company),
|
on_delete=models.SET_NULL,
|
||||||
null=True,
|
null=True,
|
||||||
limit_choices_to={'is_customer': True},
|
limit_choices_to={'is_customer': True},
|
||||||
related_name='sales_orders',
|
related_name='sales_orders',
|
||||||
|
Loading…
Reference in New Issue
Block a user