diff --git a/InvenTree/company/models.py b/InvenTree/company/models.py index fff38a8e99..9b881c227e 100644 --- a/InvenTree/company/models.py +++ b/InvenTree/company/models.py @@ -290,9 +290,6 @@ class Contact(models.Model): role = models.CharField(max_length=100, blank=True) - company = models.ForeignKey(Company, related_name='contacts', - on_delete=models.CASCADE) - class ManufacturerPart(models.Model): """ Represents a unique part as provided by a Manufacturer diff --git a/InvenTree/company/templates/company/company_base.html b/InvenTree/company/templates/company/company_base.html index 489493fd06..c58ea63791 100644 --- a/InvenTree/company/templates/company/company_base.html +++ b/InvenTree/company/templates/company/company_base.html @@ -23,6 +23,8 @@ {% endif %} +{% define perms.company.change_company or perms.company.delete_company as has_permission %} +{% if has_permission %} @@ -38,6 +40,7 @@ {% endif %} +{% endif %} {% endblock actions %} {% block thumbnail %} diff --git a/InvenTree/company/templates/company/manufacturer_part.html b/InvenTree/company/templates/company/manufacturer_part.html index a3a2bbc65e..5a0e741c1a 100644 --- a/InvenTree/company/templates/company/manufacturer_part.html +++ b/InvenTree/company/templates/company/manufacturer_part.html @@ -88,7 +88,14 @@ src="{% static 'img/blank_image.png' %}" {% trans "Manufacturer" %} - {{ part.manufacturer.name }}{% include "clip.html"%} + + {% if part.manufacturer %} + {{ part.manufacturer.name }}{% include "clip.html"%} + {% else %} + {% trans "No manufacturer information available" %} + {% endif %} + {% endif %} + @@ -329,7 +336,11 @@ $('#delete-part').click(function() { deleteManufacturerPart({{ part.pk }}, { onSuccess: function() { + {% if part.manufacturer %} window.location.href = "{% url 'company-detail' part.manufacturer.id %}"; + {% else%} + window.location.href = "{% url 'index' %}"; + {% endif %} } }); }); diff --git a/InvenTree/company/templates/company/supplier_part.html b/InvenTree/company/templates/company/supplier_part.html index 250c595476..f990b66898 100644 --- a/InvenTree/company/templates/company/supplier_part.html +++ b/InvenTree/company/templates/company/supplier_part.html @@ -85,7 +85,13 @@ src="{% static 'img/blank_image.png' %}" {% trans "Supplier" %} - {{ part.supplier.name }}{% include "clip.html"%} + {% if part.supplier %} + {{ part.supplier.name }}{% include "clip.html"%} + {% else %} + {% trans "No supplier information available" %} + {% endif %} + + {% trans "SKU" %} @@ -356,7 +362,9 @@ $('#delete-part').click(function() { deleteSupplierPart({{ part.pk }}, { onSuccess: function() { + {% if part.supplier %} window.location.href = "{% url 'company-detail' part.supplier.id %}"; + {% endif %} } }); }); diff --git a/InvenTree/order/migrations/0066_alter_purchaseorder_supplier.py b/InvenTree/order/migrations/0066_alter_purchaseorder_supplier.py new file mode 100644 index 0000000000..d37aedaeda --- /dev/null +++ b/InvenTree/order/migrations/0066_alter_purchaseorder_supplier.py @@ -0,0 +1,20 @@ +# Generated by Django 3.2.13 on 2022-04-30 22:11 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('company', '0042_supplierpricebreak_updated'), + ('order', '0065_alter_purchaseorderlineitem_part'), + ] + + operations = [ + migrations.AlterField( + model_name='purchaseorder', + name='supplier', + field=models.ForeignKey(help_text='Company from which the items are being ordered', limit_choices_to={'is_supplier': True}, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='purchase_orders', to='company.company', verbose_name='Supplier'), + ), + ] diff --git a/InvenTree/order/models.py b/InvenTree/order/models.py index 2b722ddecd..060d638de1 100644 --- a/InvenTree/order/models.py +++ b/InvenTree/order/models.py @@ -228,7 +228,7 @@ class PurchaseOrder(Order): prefix = getSetting('PURCHASEORDER_REFERENCE_PREFIX') - return f"{prefix}{self.reference} - {self.supplier.name}" + return f"{prefix}{self.reference} - {self.supplier.name if self.supplier else _('deleted')}" reference = models.CharField( unique=True, @@ -243,7 +243,8 @@ class PurchaseOrder(Order): help_text=_('Purchase order status')) supplier = models.ForeignKey( - Company, on_delete=models.CASCADE, + Company, on_delete=models.SET_NULL, + null=True, limit_choices_to={ 'is_supplier': True, }, @@ -575,7 +576,7 @@ class SalesOrder(Order): prefix = getSetting('SALESORDER_REFERENCE_PREFIX') - return f"{prefix}{self.reference} - {self.customer.name}" + return f"{prefix}{self.reference} - {self.customer.name if self.customer else _('deleted')}" def get_absolute_url(self): return reverse('so-detail', kwargs={'pk': self.id}) @@ -938,7 +939,7 @@ class PurchaseOrderLineItem(OrderLineItem): return "{n} x {part} from {supplier} (for {po})".format( n=decimal2string(self.quantity), part=self.part.SKU if self.part else 'unknown part', - supplier=self.order.supplier.name, + supplier=self.order.supplier.name if self.order.supplier else _('deleted'), po=self.order) order = models.ForeignKey( diff --git a/InvenTree/order/templates/order/order_base.html b/InvenTree/order/templates/order/order_base.html index c2aa10f722..b80275b1f3 100644 --- a/InvenTree/order/templates/order/order_base.html +++ b/InvenTree/order/templates/order/order_base.html @@ -67,7 +67,7 @@ {% block thumbnail %} {% trans "Supplier" %} - {{ order.supplier.name }}{% include "clip.html"%} + + {% if order.supplier %} + {{ order.supplier.name }}{% include "clip.html"%} + {% else %} + {% trans "No suppplier information available" %} + {% endif %} + {% if order.supplier_reference %} diff --git a/InvenTree/order/templates/order/purchase_order_detail.html b/InvenTree/order/templates/order/purchase_order_detail.html index 23bdd908e1..542a7a90ca 100644 --- a/InvenTree/order/templates/order/purchase_order_detail.html +++ b/InvenTree/order/templates/order/purchase_order_detail.html @@ -170,10 +170,12 @@ $('#new-po-line').click(function() { var fields = poLineItemFields({ order: {{ order.pk }}, + {% if order.supplier %} supplier: {{ order.supplier.pk }}, {% if order.supplier.currency %} currency: '{{ order.supplier.currency }}', {% endif %} + {% endif %} }); constructForm('{% url "api-po-line-list" %}', { @@ -210,7 +212,9 @@ $('#new-po-line').click(function() { loadPurchaseOrderLineItemTable('#po-line-table', { order: {{ order.pk }}, + {% if order.supplier %} supplier: {{ order.supplier.pk }}, + {% endif %} {% if roles.purchase_order.change %} allow_edit: true, {% else %} diff --git a/InvenTree/part/templates/part/partial_delete.html b/InvenTree/part/templates/part/partial_delete.html index eb23fbee09..22c739b833 100644 --- a/InvenTree/part/templates/part/partial_delete.html +++ b/InvenTree/part/templates/part/partial_delete.html @@ -43,7 +43,7 @@

{% blocktrans with count=part.manufacturer_parts.all|length %}There are {{count}} manufacturers defined for this part. If you delete this part, the following manufacturer parts will also be deleted:{% endblocktrans %}

@@ -54,7 +54,9 @@

{% blocktrans with count=part.supplier_parts.all|length %}There are {{count}} suppliers defined for this part. If you delete this part, the following supplier parts will also be deleted:{% endblocktrans %}

diff --git a/InvenTree/report/templates/report/inventree_po_report.html b/InvenTree/report/templates/report/inventree_po_report.html index d1cae75c3b..9e546fb70e 100644 --- a/InvenTree/report/templates/report/inventree_po_report.html +++ b/InvenTree/report/templates/report/inventree_po_report.html @@ -74,7 +74,7 @@ table td.expand {

{% trans "Purchase Order" %} {{ prefix }}{{ reference }}

- {{ supplier.name }} + {% if supplier %}{{ supplier.name }}{% endif %}{% else %}{% trans "Supplier was deleted" %}{% endif %}
{% endblock %} diff --git a/InvenTree/stock/templates/stock/item_base.html b/InvenTree/stock/templates/stock/item_base.html index dd77d26d1c..4c8af402cf 100644 --- a/InvenTree/stock/templates/stock/item_base.html +++ b/InvenTree/stock/templates/stock/item_base.html @@ -379,7 +379,11 @@ {% trans "Supplier" %} - {{ item.supplier_part.supplier.name }} + + {% if item.supplier_part.supplier %} + {{ item.supplier_part.supplier.name }} + {% endif %} +