<commit_before># -*- coding: utf-8; -*-
"""Utility functions for model data handling."""
import copy

from pathlib import PurePath

import django.utils.text

from mptt.utils import get_cached_trees

from pharmaship.inventory import models


def req_qty_element(element, req_qty_list):
    """Return the required quantity of an element.

    Use the allowance list and required quantities list.
    """
    # Required quantity
    maximum = [0, ]
    additional = 0<commit_msg>Move a repeated parsing function into utils<commit_after># -*- coding: utf-8; -*-
"""Utility functions for model data handling."""
import copy

from pathlib import PurePath

import django.utils.text

from mptt.utils import get_cached_trees

from pharmaship.inventory import models


def get_quantity(transaction_list, item_id):
    """Get the item quantity from a transaction list.

    Transactions of type 1 ("in") or 8 ("stock count") are setters.
    Other types are decreasing the value.

    :param django.db.models.query.QuerySet transaction_list: List of \
    transactions :class:`pharmaship.inventory.models.QtyTransaction`.
    :param int item_id: ID of item

    :return: Quantity of item
    :rtype: int
    """
    result = 0
    for transaction in transaction_list:
        if transaction.object_id == item_id:
            if transaction.transaction_type in [1, 8]:
                result = transaction.value
            else:
                result -= transaction.value
    return result


def req_qty_element(element, req_qty_list):
    """Return the required quantity of an element.

    Use the allowance list and required quantities list.
    """
    # Required quantity
    maximum = [0, ]
    additional = 0
{'fraction_non_alphanumeric': 0.08387096774193549, 'fraction_numerical': 0.0064516129032258064, 'mean_word_length': 3.150851581508516, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '900243', 'n_tokens_mistral': 487, 'n_tokens_neox': 464, 'n_words': 171}