diff --git a/openprocurement/auctions/core/models/schema.py b/openprocurement/auctions/core/models/schema.py index bb14943c..24ce451c 100644 --- a/openprocurement/auctions/core/models/schema.py +++ b/openprocurement/auctions/core/models/schema.py @@ -413,6 +413,14 @@ class dgfCDB2Document(dgfDocument): ]) +class AuctionDocument(dgfCDB2Document): + """ + Override dgfCDB2Document model + Append auction choice in doucmentOf field + """ + documentOf = StringType(required=True, choices=['auction', 'item', 'lot', 'tender'], default='auction') + + class swiftsureDocument(dgfDocument): documentOf = StringType( required=True, @@ -655,6 +663,35 @@ class dgfCancellation(BaseCancellation): validate_disallow_dgfPlatformLegalDetails]) +class AuctionCancellationDetailsDocument(AuctionDocument): + """ + Override cancellation documents model + Append cancellationDetails choice to documenTtype + """ + documentType = StringType(choices=[ + 'auctionNotice', 'awardNotice', 'contractNotice', + 'notice', 'biddingDocuments', 'technicalSpecifications', + 'evaluationCriteria', 'clarifications', 'shortlistedFirms', + 'riskProvisions', 'billOfQuantity', 'bidders', 'conflictOfInterest', + 'debarments', 'evaluationReports', 'winningBid', 'complaints', + 'contractSigned', 'contractArrangements', 'contractSchedule', + 'contractAnnexe', 'contractGuarantees', 'subContract', + 'eligibilityCriteria', 'contractProforma', 'commercialProposal', + 'qualificationDocuments', 'eligibilityDocuments', 'tenderNotice', + 'illustration', 'auctionProtocol', 'x_dgfAssetFamiliarization', + 'x_presentation', 'x_nda', 'cancellationDetails' + ]) + + +class AuctionCancellation(BaseCancellation): + """ + Override auction cancellation model + include cancellation details in documentType + """ + documents = ListType(ModelType(AuctionCancellationDetailsDocument), default=list()) + + + class swiftsureCancellation(BaseCancellation): documents = ListType( ModelType(swiftsureCancellationDocument), diff --git a/openprocurement/auctions/core/utils.py b/openprocurement/auctions/core/utils.py index 0b679102..55c6d4f1 100644 --- a/openprocurement/auctions/core/utils.py +++ b/openprocurement/auctions/core/utils.py @@ -585,3 +585,44 @@ def generate_rectificationPeriod_tender_period_margin(auction, tp_margin=MINIMAL period.endDate = calculated_endDate if calculated_endDate > now else now period.invalidationDate = None return period + + +def change_document_of(document): + """ + Only for migration + Function that change documnet_of attribute in auction's document + :param document: + :return: True if document was changed else False + """ + if document and document['documentOf'] == 'tender': + document.update({ + 'documentOf': 'auction' + }) + return True + return False + + +def migrate_all_document_of_tender(auction): + """ + Change documentOf to auction if it was tender to auction + Iterate through keys of auctions and get the array of needed type if it exists + Iterate through array of needed type and get array of documents if it exists + Call function that change document_of attribute of document and get execution result (true or false) + if auction wasn't change before set is_changed_auction_data to true + :param auction: + :return: boolean True if document was changed else False + """ + + is_changed_auction_data = False + + for _type in ['bids', 'awards', 'contracts', 'cancellations']: + for type_obj in auction.get(_type, []): + for document in type_obj.get('documents', []): + is_change_document = change_document_of(document) + is_changed_auction_data = is_changed_auction_data or is_change_document + + for auction_document in auction.get('documents', []): + is_change_document = change_document_of(auction_document) + is_changed_auction_data = is_changed_auction_data or is_change_document + + return is_changed_auction_data