Commit ca861678 authored by mashony's avatar mashony

fix(dgf): Change participant description format. Create custom serializer class for dgf procedures

parent c106a7c7
......@@ -7,7 +7,7 @@ from docxtpl import DocxTemplate
from prozorro_sale.protocol_service.utils import (localize_time, get_auction, standardize_amount, SUCCESS_STATUSES_MAP,
parse_duration)
from prozorro_sale.protocol_service.serializers import Procedure
from prozorro_sale.protocol_service.serializers import get_procedure_serializer
from prozorro_sale.protocol_service.errors import TemplateNotFound, TemplateError
......@@ -16,7 +16,7 @@ class ProtocolBuilderBase:
template_extension_type = None
def __init__(self, auction_id):
self.procedure = Procedure(auction_id)
self.procedure = get_procedure_serializer(auction_id)
self.auction = {}
self.auction_id = auction_id
......
......@@ -3,8 +3,12 @@ from prozorro_sale.auth import get_user_legal_name_by_name
class Procedure:
def __init__(self, auction_id):
self.proc_obj = self.get_procedure(auction_id)
def __init__(self, auction_id, procedure=None):
self.proc_obj = procedure
if not self.proc_obj:
self.proc_obj = get_procedure(auction_id)
self._prepare_proc_obj()
self.winner_award = self.get_winner_award()
self.winner_bid = self.get_winner_bid()
self.next_to_winner_bid = self.get_next_to_winner_bid()
......@@ -36,10 +40,8 @@ class Procedure:
def get_user_legal_name(self, name):
return get_user_legal_name_by_name(name) or name
def get_procedure(self, auction_id):
procedure = get_procedure(auction_id)
procedure['owner_legal_name'] = self.get_user_legal_name(name=procedure.get('owner'))
return procedure
def _prepare_proc_obj(self):
self.proc_obj['owner_legal_name'] = self.get_user_legal_name(name=self.proc_obj.get('owner'))
def has_unsuccessful_winner_award(self):
return self.proc_obj['awards'][0]['status'] in {'unsuccessful', 'cancelled'}
......@@ -109,3 +111,40 @@ class Procedure:
def __getitem__(self, item):
return self.proc_obj.get(item)
class DGFProcedure(Procedure):
def _format_participant_description(self, bidder):
return f"Учасник {bidder['name']['uk_UA']}, #{bidder['identifier']['id']}"
def get_bidder_description(self, bid_id):
bidder = self.bids[bid_id]['bidders'][0]
return self._format_participant_description(bidder)
def get_actual_winner_description(self):
if self.winner_award:
buyer = self.winner_award['buyers'][0]
return self._format_participant_description(buyer)
if self.winner_bid:
bidder = self.winner_bid['bidders'][0]
return self._format_participant_description(bidder)
def get_disqualified_winner_description(self):
if list(self.awards.values())[0]['status'] == 'unsuccessful':
disqualified_buyer = list(self.awards.values())[0]['buyers'][0]
return self._format_participant_description(disqualified_buyer)
PROCEDURE_SERIALIZER_MAPPING = {
"dgf": DGFProcedure,
"__default__": Procedure
}
def get_procedure_serializer(auction_id):
procedure = get_procedure(auction_id)
selling_method = procedure["sellingMethod"].split("-")
selling_type = selling_method[0]
default_serializer_class = PROCEDURE_SERIALIZER_MAPPING["__default__"]
serializer_class = PROCEDURE_SERIALIZER_MAPPING.get(selling_type, default_serializer_class)
return serializer_class(auction_id, procedure)
from aiohttp import test_utils
from prozorro_sale.protocol_service.serializers import Procedure
from prozorro_sale.protocol_service.serializers import get_procedure_serializer
from prozorro_sale.auth import load_auth
AUTH_PATH = '/secrets/auth.yml'
......@@ -11,7 +11,7 @@ class TestProcedure:
procedure_obj['awards'][1]['status'] = "pending_waiting"
with test_utils.mock.patch('prozorro_sale.protocol_service.serializers.get_procedure',
return_value=procedure_obj):
procedure = Procedure(procedure_obj['auctionId'])
procedure = get_procedure_serializer(procedure_obj['auctionId'])
assert procedure.proc_obj['owner_legal_name'] == 'Тестовий брокер 1'
assert procedure.winner_bid['owner_legal_name'] == 'Тестовий брокер 2'
......@@ -26,7 +26,7 @@ class TestProcedure:
procedure_obj['awards'][1]['status'] = "pending"
with test_utils.mock.patch('prozorro_sale.protocol_service.serializers.get_procedure',
return_value=procedure_obj):
procedure = Procedure(procedure_obj['auctionId'])
procedure = get_procedure_serializer(procedure_obj['auctionId'])
assert procedure.proc_obj['owner_legal_name'] == 'Тестовий брокер 1'
assert procedure.winner_bid['owner_legal_name'] == 'Тестовий брокер 1'
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment