コード例 #1
0
ファイル: views.py プロジェクト: hungddit/LIMS-Backend
    def _create_item_transfers(self, sum_item_amounts, error_items=[]):
        """
        Create ItemTransfers to alter inventory amounts
        """
        transfers = []
        for item, amount in sum_item_amounts.items():
            try:
                amount_symbol = '{:~}'.format(amount['amount']).split(' ')[1]
                measure = AmountMeasure.objects.get(symbol=amount_symbol)
                amount['amount'] = amount['amount'].magnitude
            except:
                measure = AmountMeasure.objects.get(symbol='item')

            # Look up to see if there is a matching ItemTransfer already and then
            # use this instead
            try:
                transfer = ItemTransfer.objects.get(
                    item=item,
                    barcode=amount.get('barcode', None),
                    coordinates=amount.get('coordinates', None))
                # At this point need to subtract amount from available in existing
                # transfer! Need to mark in some way not completed though so can put
                # back if the trasnfer is cancelled
                transfer.amount_to_take = amount['amount']
            except (ObjectDoesNotExist, MultipleObjectsReturned):
                transfer = ItemTransfer(item=item,
                                        barcode=amount.get('barcode', None),
                                        coordinates=amount.get(
                                            'coordinates', None),
                                        amount_taken=amount['amount'],
                                        amount_measure=measure)
            if item in error_items:
                transfer.is_valid = False
            transfers.append(transfer)
        return transfers
コード例 #2
0
ファイル: views.py プロジェクト: GETLIMS/LIMS-Backend
    def _create_item_transfers(self, sum_item_amounts, error_items=[]):
        """
        Create ItemTransfers to alter inventory amounts
        """
        transfers = []
        for item, amount in sum_item_amounts.items():
            try:
                amount_symbol = '{:~}'.format(amount['amount']).split(' ')[1]
                measure = AmountMeasure.objects.get(symbol=amount_symbol)
                amount['amount'] = amount['amount'].magnitude
            except:
                measure = AmountMeasure.objects.get(symbol='item')

            # Look up to see if there is a matching ItemTransfer already and then
            # use this instead
            try:
                transfer = ItemTransfer.objects.get(item=item,
                                                    barcode=amount.get('barcode', None),
                                                    coordinates=amount.get('coordinates', None))
                # At this point need to subtract amount from available in existing
                # transfer! Need to mark in some way not completed though so can put
                # back if the trasnfer is cancelled
                transfer.amount_to_take = amount['amount']
            except (ObjectDoesNotExist, MultipleObjectsReturned):
                transfer = ItemTransfer(
                    item=item,
                    barcode=amount.get('barcode', None),
                    coordinates=amount.get('coordinates', None),
                    amount_taken=amount['amount'],
                    amount_measure=measure)
            if item in error_items:
                transfer.is_valid = False
            transfers.append(transfer)
        return transfers