Create default shipment in backend

This commit is contained in:
Maksim Stojkovic 2022-05-19 00:10:55 +10:00
parent 9ae8a6b219
commit 2cf67ea0c9
3 changed files with 24 additions and 0 deletions

View File

@ -1111,6 +1111,13 @@ class InvenTreeSetting(BaseInvenTreeSetting):
'default': 'SO', 'default': 'SO',
}, },
'SALESORDER_DEFAULT_SHIPMENT': {
'name': _('Sales Order Default Shipment'),
'description': _('Enable creation of default shipment with sales orders'),
'default': False,
'validator': bool,
},
'PURCHASEORDER_REFERENCE_PREFIX': { 'PURCHASEORDER_REFERENCE_PREFIX': {
'name': _('Purchase Order Reference Prefix'), 'name': _('Purchase Order Reference Prefix'),
'description': _('Prefix value for purchase order reference'), 'description': _('Prefix value for purchase order reference'),

View File

@ -12,6 +12,8 @@ from decimal import Decimal
from django.db import models, transaction from django.db import models, transaction
from django.db.models import Q, F, Sum from django.db.models import Q, F, Sum
from django.db.models.functions import Coalesce from django.db.models.functions import Coalesce
from django.db.models.signals import post_save
from django.dispatch.dispatcher import receiver
from django.core.validators import MinValueValidator from django.core.validators import MinValueValidator
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
@ -808,6 +810,20 @@ class SalesOrder(Order):
def pending_shipment_count(self): def pending_shipment_count(self):
return self.pending_shipments().count() return self.pending_shipments().count()
@receiver(post_save, sender=SalesOrder, dispatch_uid='build_post_save_log')
def after_save_sales_order(sender, instance: SalesOrder, created: bool, **kwargs):
"""
Callback function to be executed after a SalesOrder instance is saved
"""
if created and getSetting('SALESORDER_DEFAULT_SHIPMENT'):
# A new SalesOrder has just been created
# Create default shipment
SalesOrderShipment.objects.create(
order=instance,
reference='1',
)
class PurchaseOrderAttachment(InvenTreeAttachment): class PurchaseOrderAttachment(InvenTreeAttachment):
""" """

View File

@ -12,6 +12,7 @@
<table class='table table-striped table-condensed'> <table class='table table-striped table-condensed'>
<tbody> <tbody>
{% include "InvenTree/settings/setting.html" with key="SALESORDER_REFERENCE_PREFIX" %} {% include "InvenTree/settings/setting.html" with key="SALESORDER_REFERENCE_PREFIX" %}
{% include "InvenTree/settings/setting.html" with key="SALESORDER_DEFAULT_SHIPMENT" icon="fa-truck-loading" %}
</tbody> </tbody>
</table> </table>