Skip to content

Commit

Permalink
Merge pull request #2791 from matmair/matmair/issue2788
Browse files Browse the repository at this point in the history
Preserve orders if companies are deleted
  • Loading branch information
SchrodingersGat authored May 4, 2022
2 parents dbc0023 + 055b9c9 commit 4053a91
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 14 deletions.
3 changes: 0 additions & 3 deletions InvenTree/company/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions InvenTree/company/templates/company/company_base.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
<span class='fas fa-shopping-cart'/>
</button>
{% endif %}
{% define perms.company.change_company or perms.company.delete_company as has_permission %}
{% if has_permission %}
<button id='company-edit-actions' title='{% trans "Company actions" %}' class='btn btn-outline-secondary dropdown-toggle' type='button' data-bs-toggle='dropdown'>
<span class='fas fa-tools'></span> <span class='caret'></span>
</button>
Expand All @@ -38,6 +40,7 @@
</a></li>
{% endif %}
</ul>
{% endif %}
{% endblock actions %}

{% block thumbnail %}
Expand Down
13 changes: 12 additions & 1 deletion InvenTree/company/templates/company/manufacturer_part.html
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,14 @@ <h4>
<tr>
<td><span class='fas fa-industry'></span></td>
<td>{% trans "Manufacturer" %}</td>
<td><a href="{% url 'company-detail' part.manufacturer.id %}">{{ part.manufacturer.name }}</a>{% include "clip.html"%}</td>
<td>
{% if part.manufacturer %}
<a href="{% url 'company-detail' part.manufacturer.id %}">{{ part.manufacturer.name }}</a>{% include "clip.html"%}
{% else %}
<em>{% trans "No manufacturer information available" %}</em>
{% endif %}
{% endif %}
</td>
</tr>
<tr>
<td><span class='fas fa-hashtag'></span></td>
Expand Down Expand Up @@ -329,7 +336,11 @@ <h4>{% trans "Parameters" %}</h4>

deleteManufacturerPart({{ part.pk }}, {
onSuccess: function() {
{% if part.manufacturer %}
window.location.href = "{% url 'company-detail' part.manufacturer.id %}";
{% else%}
window.location.href = "{% url 'index' %}";
{% endif %}
}
});
});
Expand Down
10 changes: 9 additions & 1 deletion InvenTree/company/templates/company/supplier_part.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,13 @@ <h4>
<tr>
<td><span class='fas fa-building'></span></td>
<td>{% trans "Supplier" %}</td>
<td><a href="{% url 'company-detail' part.supplier.id %}">{{ part.supplier.name }}</a>{% include "clip.html"%}</td></tr>
<td>{% if part.supplier %}
<a href="{% url 'company-detail' part.supplier.id %}">{{ part.supplier.name }}</a>{% include "clip.html"%}
{% else %}
<em>{% trans "No supplier information available" %}</em>
{% endif %}
</td>
</tr>
<tr>
<td><span class='fas fa-hashtag'></span></td>
<td>{% trans "SKU" %}</td>
Expand Down Expand Up @@ -356,7 +362,9 @@ <h4>{% trans "Pricing Information" %}</h4>

deleteSupplierPart({{ part.pk }}, {
onSuccess: function() {
{% if part.supplier %}
window.location.href = "{% url 'company-detail' part.supplier.id %}";
{% endif %}
}
});
});
Expand Down
20 changes: 20 additions & 0 deletions InvenTree/order/migrations/0066_alter_purchaseorder_supplier.py
Original file line number Diff line number Diff line change
@@ -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'),
),
]
9 changes: 5 additions & 4 deletions InvenTree/order/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def __str__(self):

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,
Expand All @@ -243,7 +243,8 @@ def __str__(self):
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,
},
Expand Down Expand Up @@ -575,7 +576,7 @@ def __str__(self):

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})
Expand Down Expand Up @@ -938,7 +939,7 @@ def __str__(self):
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(
Expand Down
10 changes: 8 additions & 2 deletions InvenTree/order/templates/order/order_base.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@

{% block thumbnail %}
<img class='part-thumb'
{% if order.supplier.image %}
{% if order.supplier and order.supplier.image %}
src="{{ order.supplier.image.url }}"
{% else %}
src="{% static 'img/blank_image.png' %}"
Expand Down Expand Up @@ -110,7 +110,13 @@
<tr>
<td><span class='fas fa-building'></span></td>
<td>{% trans "Supplier" %}</td>
<td><a href="{% url 'company-detail' order.supplier.id %}">{{ order.supplier.name }}</a>{% include "clip.html"%}</td>
<td>
{% if order.supplier %}
<a href="{% url 'company-detail' order.supplier.id %}">{{ order.supplier.name }}</a>{% include "clip.html"%}
{% else %}
<em>{% trans "No suppplier information available" %}</em>
{% endif %}
</td>
</tr>
{% if order.supplier_reference %}
<tr>
Expand Down
4 changes: 4 additions & 0 deletions InvenTree/order/templates/order/purchase_order_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,12 @@ <h4>{% trans "Order Notes" %}</h4>

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" %}', {
Expand Down Expand Up @@ -210,7 +212,9 @@ <h4>{% trans "Order Notes" %}</h4>

loadPurchaseOrderLineItemTable('#po-line-table', {
order: {{ order.pk }},
{% if order.supplier %}
supplier: {{ order.supplier.pk }},
{% endif %}
{% if roles.purchase_order.change %}
allow_edit: true,
{% else %}
Expand Down
4 changes: 3 additions & 1 deletion InvenTree/part/templates/part/partial_delete.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<p>{% 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 %}
<ul class='list-group'>
{% for spart in part.manufacturer_parts.all %}
<li class='list-group-item'>{{ spart.manufacturer.name }} - {{ spart.MPN }}</li>
<li class='list-group-item'>{% if spart.manufacturer %}{{ spart.manufacturer.name }} - {% endif %}{{ spart.MPN }}</li>
{% endfor %}
</ul>
</p>
Expand All @@ -54,7 +54,9 @@
<p>{% 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 %}
<ul class='list-group'>
{% for spart in part.supplier_parts.all %}
{% if spart.supplier %}
<li class='list-group-item'>{{ spart.supplier.name }} - {{ spart.SKU }}</li>
{% endif %}
{% endfor %}
</ul>
</p>
Expand Down
2 changes: 1 addition & 1 deletion InvenTree/report/templates/report/inventree_po_report.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@

<div class='header-right'>
<h3>{% trans "Purchase Order" %} {{ prefix }}{{ reference }}</h3>
{{ supplier.name }}
{% if supplier %}{{ supplier.name }}{% endif %}{% else %}{% trans "Supplier was deleted" %}{% endif %}
</div>

{% endblock %}
Expand Down
6 changes: 5 additions & 1 deletion InvenTree/stock/templates/stock/item_base.html
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,11 @@
<tr>
<td><span class='fas fa-building'></span></td>
<td>{% trans "Supplier" %}</td>
<td><a href="{% url 'company-detail' item.supplier_part.supplier.id %}">{{ item.supplier_part.supplier.name }}</a></td>
<td>
{% if item.supplier_part.supplier %}
<a href="{% url 'company-detail' item.supplier_part.supplier.id %}">{{ item.supplier_part.supplier.name }}</a>
{% endif %}
</td>
</tr>
<tr>
<td><span class='fas fa-shapes'></span></td>
Expand Down

0 comments on commit 4053a91

Please sign in to comment.