mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Add a post-save hook the "Build" model to check stock
This commit is contained in:
parent
6db6a70fc2
commit
99b324d1ef
@ -8,17 +8,19 @@ import decimal
|
||||
|
||||
import os
|
||||
from datetime import datetime
|
||||
from django import dispatch
|
||||
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
from django.core.exceptions import ValidationError
|
||||
|
||||
from django.urls import reverse
|
||||
from django.core.validators import MinValueValidator
|
||||
from django.db import models, transaction
|
||||
from django.db.models import Sum, Q
|
||||
from django.db.models.functions import Coalesce
|
||||
from django.core.validators import MinValueValidator
|
||||
from django.db.models.signals import post_save
|
||||
from django.dispatch.dispatcher import receiver
|
||||
from django.urls import reverse
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from markdownx.models import MarkdownxField
|
||||
|
||||
@ -27,16 +29,17 @@ from mptt.exceptions import InvalidMove
|
||||
|
||||
from InvenTree.status_codes import BuildStatus, StockStatus, StockHistoryCode
|
||||
from InvenTree.helpers import increment, getSetting, normalize, MakeBarcode
|
||||
from InvenTree.validators import validate_build_order_reference
|
||||
from InvenTree.models import InvenTreeAttachment, ReferenceIndexingMixin
|
||||
from InvenTree.validators import validate_build_order_reference
|
||||
|
||||
import common.models
|
||||
|
||||
import InvenTree.fields
|
||||
import InvenTree.helpers
|
||||
import InvenTree.tasks
|
||||
|
||||
from stock import models as StockModels
|
||||
from part import models as PartModels
|
||||
from stock import models as StockModels
|
||||
from users import models as UserModels
|
||||
|
||||
|
||||
@ -1014,6 +1017,19 @@ class Build(MPTTModel, ReferenceIndexingMixin):
|
||||
return self.status == BuildStatus.COMPLETE
|
||||
|
||||
|
||||
@receiver(post_save, sender=Build, dispatch_uid='build_post_save_log')
|
||||
def after_save_build(sender, instance: Build, created: bool, **kwargs):
|
||||
"""
|
||||
Callback function to be executed after a Build instance is saved
|
||||
"""
|
||||
|
||||
if created:
|
||||
# A new Build has just been created
|
||||
|
||||
# Run checks on required parts
|
||||
InvenTree.tasks.offload_task('build.tasks.check_build_stock', instance)
|
||||
|
||||
|
||||
class BuildOrderAttachment(InvenTreeAttachment):
|
||||
"""
|
||||
Model for storing file attachments against a BuildOrder object
|
||||
|
@ -1,6 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from decimal import Decimal
|
||||
import logging
|
||||
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
@ -39,7 +40,7 @@ def check_build_stock(build: build.models.Build):
|
||||
|
||||
available = max(0, in_stock - allocated)
|
||||
|
||||
required = bom_item.quantity * build.quantity
|
||||
required = Decimal(bom_item.quantity) * Decimal(build.quantity)
|
||||
|
||||
if available < required:
|
||||
# There is not sufficient stock for this part
|
||||
|
@ -21,7 +21,9 @@
|
||||
|
||||
{% for line in lines %}
|
||||
<tr style="height: 2.5rem; border-bottom: 1px solid">
|
||||
<td style='padding-left: 1em;'><a href='{{ line.link }}'>{{ line.part.full_name }}</a></td>
|
||||
<td style='padding-left: 1em;'>
|
||||
<a href='{{ line.link }}'>{{ line.part.full_name }}</a>{% if part.description %} - <em>{{ part.description }}</em>{% endif %}
|
||||
</td>
|
||||
<td style="text-align: center;">
|
||||
{% decimal line.required %} {% if line.part.units %}{{ line.part.units }}{% endif %}
|
||||
</td>
|
||||
|
Loading…
Reference in New Issue
Block a user