def report_results(self, auction_doc): LOGGER.info('Report auction results {}'.format(auction_doc.id)) lot_id = auction_doc.merchandisingObject # Get lot try: lot = self.lots_client.get_lot(lot_id).data except ResourceNotFound: LOGGER.warning( 'Lot {} not found when report auction {} results'.format( lot_id, auction_doc.id)) return if lot.status != 'active.auction': LOGGER.info('Auction {} results already reported to lot {}'.format( auction_doc.id, lot_id)) return LOGGER.info('Received lot {} from CDB'.format(lot_id)) if auction_doc.status == 'complete': next_lot_status = 'pending.sold' else: next_lot_status = 'active.salable' # Report results try: self.switch_lot_status(lot['id'], next_lot_status) except Exception as e: LOGGER.error('Failed update lot info {}. {}'.format( lot_id, e.message))
def process_single_auction(self, auction_id): try: auction = self.auctions_client.get_auction(auction_id) except ResourceNotFound: LOGGER.warning('Auction object {} not found'.format(auction_id)) else: self.process_auction(auction['data'])
def _get_lot(self, auction_doc): lot_id = auction_doc.merchandisingObject try: lot = self.lots_client.get_lot(lot_id).data except ResourceNotFound: LOGGER.warning( 'Lot {} not found when report auction {} results'.format( lot_id, auction_doc.id)) return LOGGER.info('Received lot {} from CDB'.format(lot_id)) return lot
def _check_lot_auction(self, lot, auction_doc): lot_auction = next( (auction for auction in lot.auctions if auction_doc.id == auction.get('relatedProcessID')), None) if not lot_auction: LOGGER.warning('Auction object {} not found in lot {}'.format( auction_doc.id, lot.id)) return if lot_auction['status'] != 'active': LOGGER.info('Auction {} results already reported to lot {}'.format( auction_doc.id, lot.id)) return return lot_auction
def _receive_lot(self, auction_doc): lot_id = auction_doc.merchandisingObject # Get lot try: lot = self.lots_client.get_lot(lot_id).data except ResourceNotFound: self.invalidate_auction(auction_doc.id) return LOGGER.info('Received lot {} from CDB'.format(lot_id)) is_lot_unusable = bool( (lot.status == u'active.awaiting' and auction_doc.id != lot.auctions[-1]) or lot.status not in [u'active.salable', u'active.awaiting', u'active.auction']) if is_lot_unusable: # lot['status'] = 'active.salable' # self.lots_client.patch_resource_item(lot) LOGGER.warning( 'Lot status \'{}\' not equal \'active.salable\''.format( lot.status), extra={'MESSAGE_ID': 'invalid_lot_status'}) self.invalidate_auction(auction_doc.id) return elif lot.status == u'active.auction' and auction_doc.id == lot.auctions[ -1]: # Switch auction self.switch_auction_status(auction_doc['id'], 'active.tendering') return elif lot.status == u'active.auction' and auction_doc.id != lot.auctions[ -1]: self.invalidate_auction(auction_doc.id) elif lot.status == u'active.awaiting' and auction_doc.id == lot.auctions[ -1]: return lot # Lock lot auctions_list = lot.get('auctions', []) auctions_list.append(auction_doc.id) lot_patch_data = { 'data': { 'status': 'active.awaiting', 'auctions': auctions_list } } self._patch_resource_item(self.lots_client, lot.id, lot_patch_data, 'Lock lot {}'.format(lot.id), {'MESSAGE_ID': 'lock_lot'}) return lot
def process_auction(self, auction): LOGGER.info('Received auction {} in status {}'.format( auction['id'], auction['status']), extra={ 'MESSAGE_ID': GET_AUCTION_MESSAGE_ID, 'STATUS': auction['status'] }) if auction[ 'procurementMethodType'] not in self.auction_type_processing_configurator: LOGGER.warning( 'Such procurementMethodType %s is not supported by this' ' convoy configuration' % auction['procurementMethodType']) return processing = self.auction_type_processing_configurator.get( auction['procurementMethodType']) processing.process_auction(auction)