Exemplo n.º 1
0
    def receive_line_item(self, line, location, quantity, user, status=StockStatus.OK, purchase_price=None, **kwargs):
        """ Receive a line item (or partial line item) against this PO
        """

        notes = kwargs.get('notes', '')

        if not self.status == PurchaseOrderStatus.PLACED:
            raise ValidationError({"status": _("Lines can only be received against an order marked as 'Placed'")})

        try:
            if not (quantity % 1 == 0):
                raise ValidationError({"quantity": _("Quantity must be an integer")})
            if quantity < 0:
                raise ValidationError({"quantity": _("Quantity must be a positive number")})
            quantity = int(quantity)
        except (ValueError, TypeError):
            raise ValidationError({"quantity": _("Invalid quantity provided")})

        # Create a new stock item
        if line.part and quantity > 0:
            stock = stock_models.StockItem(
                part=line.part.part,
                supplier_part=line.part,
                location=location,
                quantity=quantity,
                purchase_order=self,
                status=status,
                purchase_price=purchase_price,
            )

            stock.save(add_note=False)

            tracking_info = {
                'status': status,
                'purchaseorder': self.pk,
            }

            stock.add_tracking_entry(
                StockHistoryCode.RECEIVED_AGAINST_PURCHASE_ORDER,
                user,
                notes=notes,
                deltas=tracking_info,
                location=location,
                purchaseorder=self,
                quantity=quantity
            )

        # Update the number of parts received against the particular line item
        line.received += quantity
        line.save()

        # Has this order been completed?
        if len(self.pending_line_items()) == 0:

            self.received_by = user
            self.complete_order()  # This will save the model
Exemplo n.º 2
0
    def receive_line_item(self,
                          line,
                          location,
                          quantity,
                          user,
                          status=StockStatus.OK):
        """ Receive a line item (or partial line item) against this PO
        """

        if not self.status == PurchaseOrderStatus.PLACED:
            raise ValidationError({
                "status":
                _("Lines can only be received against an order marked as 'Placed'"
                  )
            })

        try:
            quantity = int(quantity)
            if quantity <= 0:
                raise ValidationError(
                    {"quantity": _("Quantity must be greater than zero")})
        except ValueError:
            raise ValidationError({"quantity": _("Invalid quantity provided")})

        # Create a new stock item
        if line.part:
            stock = stock_models.StockItem(part=line.part.part,
                                           supplier_part=line.part,
                                           location=location,
                                           quantity=quantity,
                                           purchase_order=self,
                                           status=status)

            stock.save()

            text = _("Received items")
            note = f"{_('Received')} {quantity} {_('items against order')} {str(self)}"

            # Add a new transaction note to the newly created stock item
            stock.addTransactionNote(text, user, note)

        # Update the number of parts received against the particular line item
        line.received += quantity
        line.save()

        # Has this order been completed?
        if len(self.pending_line_items()) == 0:

            self.received_by = user
            self.complete_order()  # This will save the model
Exemplo n.º 3
0
    def receive_line_item(self, line, location, quantity, user, status=StockStatus.OK, purchase_price=None):
        """ Receive a line item (or partial line item) against this PO
        """

        if not self.status == PurchaseOrderStatus.PLACED:
            raise ValidationError({"status": _("Lines can only be received against an order marked as 'Placed'")})

        try:
            if not (quantity % 1 == 0):
                raise ValidationError({"quantity": _("Quantity must be an integer")})
            if quantity < 0:
                raise ValidationError({"quantity": _("Quantity must be a positive number")})
            quantity = int(quantity)
        except (ValueError, TypeError):
            raise ValidationError({"quantity": _("Invalid quantity provided")})

        # Create a new stock item
        if line.part and quantity > 0:
            stock = stock_models.StockItem(
                part=line.part.part,
                supplier_part=line.part,
                location=location,
                quantity=quantity,
                purchase_order=self,
                status=status,
                purchase_price=purchase_price,
            )

            stock.save()

            text = _("Received items")
            note = _('Received {n} items against order {name}').format(n=quantity, name=str(self))

            # Add a new transaction note to the newly created stock item
            stock.addTransactionNote(text, user, note)

        # Update the number of parts received against the particular line item
        line.received += quantity
        line.save()

        # Has this order been completed?
        if len(self.pending_line_items()) == 0:

            self.received_by = user
            self.complete_order()  # This will save the model
Exemplo n.º 4
0
    def receive_line_item(self,
                          line,
                          location,
                          quantity,
                          user,
                          status=StockStatus.OK,
                          **kwargs):
        """
        Receive a line item (or partial line item) against this PurchaseOrder
        """

        # Extract optional batch code for the new stock item
        batch_code = kwargs.get('batch_code', '')

        # Extract optional list of serial numbers
        serials = kwargs.get('serials', None)

        # Extract optional notes field
        notes = kwargs.get('notes', '')

        # Extract optional barcode field
        barcode = kwargs.get('barcode', None)

        # Prevent null values for barcode
        if barcode is None:
            barcode = ''

        if self.status != PurchaseOrderStatus.PLACED:
            raise ValidationError(
                "Lines can only be received against an order marked as 'PLACED'"
            )

        try:
            if quantity < 0:
                raise ValidationError(
                    {"quantity": _("Quantity must be a positive number")})
            quantity = InvenTree.helpers.clean_decimal(quantity)
        except TypeError:
            raise ValidationError({"quantity": _("Invalid quantity provided")})

        # Create a new stock item
        if line.part and quantity > 0:

            # Determine if we should individually serialize the items, or not
            if type(serials) is list and len(serials) > 0:
                serialize = True
            else:
                serialize = False
                serials = [None]

            for sn in serials:

                stock = stock_models.StockItem(
                    part=line.part.part,
                    supplier_part=line.part,
                    location=location,
                    quantity=1 if serialize else quantity,
                    purchase_order=self,
                    status=status,
                    batch=batch_code,
                    serial=sn,
                    purchase_price=line.purchase_price,
                    uid=barcode)

                stock.save(add_note=False)

                tracking_info = {
                    'status': status,
                    'purchaseorder': self.pk,
                }

                stock.add_tracking_entry(
                    StockHistoryCode.RECEIVED_AGAINST_PURCHASE_ORDER,
                    user,
                    notes=notes,
                    deltas=tracking_info,
                    location=location,
                    purchaseorder=self,
                    quantity=quantity)

        # Update the number of parts received against the particular line item
        line.received += quantity
        line.save()

        # Has this order been completed?
        if len(self.pending_line_items()) == 0:

            self.received_by = user
            self.complete_order()  # This will save the model