mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Merge pull request #2791 from matmair/matmair/issue2788
Preserve orders if companies are deleted
This commit is contained in:
commit
4053a91450
@ -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
|
||||
|
@ -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>
|
||||
@ -38,6 +40,7 @@
|
||||
</a></li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
{% endif %}
|
||||
{% endblock actions %}
|
||||
|
||||
{% block thumbnail %}
|
||||
|
@ -88,7 +88,14 @@ src="{% static 'img/blank_image.png' %}"
|
||||
<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>
|
||||
@ -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 %}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -85,7 +85,13 @@ src="{% static 'img/blank_image.png' %}"
|
||||
<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>
|
||||
@ -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 %}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -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'),
|
||||
),
|
||||
]
|
@ -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(
|
||||
|
@ -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' %}"
|
||||
@ -110,7 +110,13 @@ src="{% static 'img/blank_image.png' %}"
|
||||
<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>
|
||||
|
@ -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 %}
|
||||
|
@ -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>
|
||||
@ -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>
|
||||
|
@ -74,7 +74,7 @@ table td.expand {
|
||||
|
||||
<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 %}
|
||||
|
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user