Exemple #1
0
 def _add_assets_to_lot(self, lot):
     result, patched_assets = self.patch_assets(
         lot,
         get_next_status(NEXT_STATUS_CHANGE, 'asset', lot['status'], 'pre'),
         lot['id'])
     if result is False:
         if patched_assets:
             logger.info("Assets {} will be repatched to 'pending'".format(
                 patched_assets))
             result, _ = self.patch_assets({'assets': patched_assets},
                                           get_next_status(
                                               NEXT_STATUS_CHANGE, 'asset',
                                               lot['status'], 'fail'))
             if result is False:
                 log_broken_lot(
                     self.db, logger, self.errors_doc, lot,
                     'patching assets to {}'.format(
                         get_next_status(NEXT_STATUS_CHANGE, 'asset',
                                         lot['status'], 'pre')))
     else:
         result, _ = self.patch_assets(
             lot,
             get_next_status(NEXT_STATUS_CHANGE, 'asset', lot['status'],
                             'finish'), lot['id'])
         if result is False:
             logger.info("Assets {} will be repatched to 'pending'".format(
                 lot['assets']))
             result, _ = self.patch_assets(
                 lot,
                 get_next_status(NEXT_STATUS_CHANGE, 'asset', lot['status'],
                                 'fail'))
             if result is False:
                 log_broken_lot(self.db, logger, self.errors_doc, lot,
                                'patching assets to active')
         else:
             asset = self.assets_client.get_asset(lot['assets'][0]).data
             asset_decision = deepcopy(asset['decisions'][0])
             asset_decision['relatedItem'] = asset['id']
             to_patch = {
                 l_key: asset.get(a_key)
                 for a_key, l_key in KEYS_FOR_LOKI_PATCH.items()
             }
             to_patch['decisions'] = [lot['decisions'][0], asset_decision]
             result = self.patch_lot(
                 lot,
                 get_next_status(NEXT_STATUS_CHANGE, 'lot', lot['status'],
                                 'finish'), to_patch)
             if result is False:
                 log_broken_lot(self.db, logger, self.errors_doc, lot,
                                'patching lot to active.salable')
Exemple #2
0
 def _add_assets_to_lot(self, lot):
     result, patched_assets = self.patch_assets(
         lot,
         get_next_status(NEXT_STATUS_CHANGE, 'asset', lot['status'], 'pre'),
         lot['id'])
     if result is False:
         if patched_assets:
             logger.info("Assets {} will be repatched to 'pending'".format(
                 patched_assets))
             result, _ = self.patch_assets({'assets': patched_assets},
                                           get_next_status(
                                               NEXT_STATUS_CHANGE, 'asset',
                                               lot['status'], 'fail'))
             if result is False:
                 log_broken_lot(
                     self.db, logger, self.errors_doc, lot,
                     'patching assets to {}'.format(
                         get_next_status(NEXT_STATUS_CHANGE, 'asset',
                                         lot['status'], 'pre')))
         return False
     else:
         result, _ = self.patch_assets(
             lot,
             get_next_status(NEXT_STATUS_CHANGE, 'asset', lot['status'],
                             'finish'), lot['id'])
         if result is False:
             logger.info("Assets {} will be repatched to 'pending'".format(
                 lot['assets']))
             result, _ = self.patch_assets(
                 lot,
                 get_next_status(NEXT_STATUS_CHANGE, 'asset', lot['status'],
                                 'fail'))
             if result is False:
                 log_broken_lot(self.db, logger, self.errors_doc, lot,
                                'patching assets to active')
             return False
         else:
             result = self.patch_lot(
                 lot,
                 get_next_status(NEXT_STATUS_CHANGE, 'lot', lot['status'],
                                 'finish'),
             )
             if result is False:
                 log_broken_lot(self.db, logger, self.errors_doc, lot,
                                'patching Lot to active.salable')
                 return False
             return True
    def _add_assets_to_lot(self, lot):
        result, patched_assets = self.patch_assets(
            lot,
            get_next_status(NEXT_STATUS_CHANGE, 'asset', lot['status'], 'pre'),
        )

        if result is False:
            if patched_assets:
                logger.info("Assets {} will be repatched to 'pending'".format(
                    patched_assets))
                result, _ = self.patch_assets({'assets': patched_assets},
                                              get_next_status(
                                                  NEXT_STATUS_CHANGE, 'asset',
                                                  lot['status'], 'fail'))
                if result is False:
                    log_broken_lot(
                        self.db, logger, self.errors_doc, lot,
                        'patching assets to {}'.format(
                            get_next_status(NEXT_STATUS_CHANGE, 'asset',
                                            lot['status'], 'pre')))
            return False
        else:
            result, asset_added_rPs = self.add_related_process_to_assets(lot)
            if not result and asset_added_rPs:
                self.clean_asset_related_processes(asset_added_rPs)
                self.patch_assets(lot, 'pending')
                return False
            elif not result:
                self.patch_assets(lot, 'pending')
                return False

            result, _ = self.patch_assets(
                lot,
                get_next_status(NEXT_STATUS_CHANGE, 'asset', lot['status'],
                                'finish'),
            )
            if result is False:
                log_assets_message(
                    logger, 'info',
                    "Assets {assets} will be repatched to 'pending'",
                    lot['relatedProcesses'])
                self.clean_asset_related_processes(asset_added_rPs)
                result, _ = self.patch_assets(
                    lot,
                    get_next_status(NEXT_STATUS_CHANGE, 'asset', lot['status'],
                                    'fail'))
                if result is False:
                    log_broken_lot(self.db, logger, self.errors_doc, lot,
                                   'patching assets to active')
                return False
            else:
                result, lot_patched_rPs = self._patch_lot_asset_related_processes(
                    lot)

                if not result and lot_patched_rPs:
                    lot_with_patched_rPs = {
                        'id': lot['id'],
                        'relatedProcesses': lot_patched_rPs
                    }
                    self._patch_lot_asset_related_processes(
                        lot_with_patched_rPs, cleanup=True)
                    self.clean_asset_related_processes(asset_added_rPs)
                    self.patch_assets(lot, 'pending')
                    return False
                elif not result:
                    self.clean_asset_related_processes(asset_added_rPs)
                    self.patch_assets(lot, 'pending')
                    return False

                asset = self.assets_client.get_asset(
                    lot['relatedProcesses'][0]['relatedProcessID']).data

                to_patch = {
                    l_key: asset.get(a_key)
                    for a_key, l_key in KEYS_FOR_LOKI_PATCH.items()
                }
                to_patch['decisions'] = deepcopy(lot['decisions'])

                for dec in deepcopy(asset['decisions']):
                    dec.update({'relatedItem': asset['id']})
                    to_patch['decisions'].append(dec)

                result = self.patch_lot(
                    lot,
                    get_next_status(NEXT_STATUS_CHANGE, 'lot', lot['status'],
                                    'finish'), to_patch)
                if result is False:
                    self._patch_lot_asset_related_processes(lot, cleanup=True)
                    self.clean_asset_related_processes(asset_added_rPs)
                    self._process_lot_and_assets(lot, 'composing', 'pending')
                    log_broken_lot(self.db, logger, self.errors_doc, lot,
                                   'patching Lot to pending')
                    return False
                return True