def _add_additional_basket(self, basket_weight, basket_type):
        """
        Utility for adding weighed and unweighed baskets to CATCH_ADDITIONAL_BASKETS
        for use in WM3 calculation of catch weight.
        
        :param basket_weight: 
        :param basket_type: digit as text.
        :return: 
        """
        if basket_type not in self._catch_additional_basket_types:
            raise Exception(f"Unrecognized catch additional basket type {basket_type}")

        if self._weight_method != '3':
            msg = f"Weight Method is '{self._weight_method}', not '3'; additional baskets not allowed."
            self._logger.error(msg)
            raise Exception(msg)

        # Consistency check: if basket type is unweighed, basket weight should be 0 or None
        if basket_type == ObserverCatchBaskets.LOOKUP_VALUE_CAB_BASKET_TYPE_UNWEIGHED_FULL and \
                basket_weight is not None and basket_weight != 0.0:
            msg = f"Basket type unweighed should have no or zero basket weight."
            self._logger.error(f"Basket type unweighed should have no or zero basket weight.")
            raise Exception(msg)

        basket_type_description = self._catch_additional_basket_types[basket_type]
        self._logger.debug(f'Add catch additional basket with wt={basket_weight} and '
                           f'type={basket_type_description}.')

        if basket_weight is None:
            basket_weight = 0.0
            self._logger.debug(f"Unweighted baskets will be given weight of 0.0")

        new_basket = None
        try:
            new_basket = CatchAdditionalBaskets.create(
                    catch=self._current_catch.catch,
                    basket_weight=float(basket_weight),
                    basket_type=basket_type,
                    created_by=ObserverDBUtil.get_current_user_id(),
                    created_date=ObserverDBUtil.get_arrow_datestr(date_format=ObserverDBUtil.oracle_date_format)
            )
        except Exception as e:
            self._logger.error(e)
        finally:
            return new_basket
Exemple #2
0
    def _add_catch_basket(self, weight):
        """
        Used only for special-case species MIX, a pseudo-species whose use indicates the basket data
        should be added to catch-level bucket, CATCH_ADDITIONAL_BASKETS rather than to a species-specific
        bucket, SPECIES_COMP_BASKETS.

        Add basket item to DB and model.

        Note: CATCH_ADDITIONAL_BASKETS does not have a field for count.

        @param weight: lbs
        """
        self._logger.debug(f'Add catch (not species) basket. wt: {weight}')
        # Get the current catch and exit if not defined
        current_catch_id = self._current_species_comp_item.species_composition.catch.catch
        if current_catch_id is None:
            self._logger.error('Catch ID is None')
            return

        if weight is None:
            weight = 0.0

        try:
            new_basket = CatchAdditionalBaskets.create(
                catch=current_catch_id,
                basket_weight=weight,
                created_by=ObserverDBUtil.get_current_user_id(),
                # FIELD-2087: Using default dateformat for time display; reformat before sync later
                created_date=ObserverDBUtil.get_arrow_datestr(
                    date_format=ObserverDBUtil.default_dateformat),
            )
            self._baskets_model.add_basket(new_basket)
            self._logger.info(f'Added addl basket wt: {weight}')

        finally:
            self._calculate_totals()
            self.basketAdded.emit()