示例#1
0
    def test_calculations(self):
        for i, val in enumerate(self.test_data['input']):
            self.bid.update(val)

            amount_perfomance = npv(
                self.bid['contractDuration']['years'],
                self.bid['contractDuration']['days'],
                self.bid['yearlyPaymentsPercentage'],
                self.bid['annualCostsReduction'],
                self.bid['announcementDate'],
                self.bid['NBUdiscountRate'],
            )

            self.assertTrue(isinstance(amount_perfomance, Fraction))

            expected = self.test_data['expected_results'][i][
                'amountPerformance']
            self.assertEqual(humanize(amount_perfomance), expected)

            amount_contract = escp(
                self.bid['contractDuration']['years'],
                self.bid['contractDuration']['days'],
                self.bid['yearlyPaymentsPercentage'],
                self.bid['annualCostsReduction'],
                self.bid['announcementDate'],
            )

            self.assertTrue(isinstance(amount_contract, Fraction))

            expected = self.test_data['expected_results'][i]['amountContract']
            self.assertEqual(humanize(amount_contract), expected)
 def amountPerformance_npv(self):
     """ Calculated energy service contract performance indicator """
     return to_decimal(
         npv(self.contractDuration.years, self.contractDuration.days,
             self.yearlyPaymentsPercentage, self.annualCostsReduction,
             self.__parent__.noticePublicationDate,
             self.__parent__.NBUdiscountRate))
示例#3
0
 def amountPerfomance_npv(self):
     """ Calculated energy service contract perfomance indicator """
     return float(npv(self.contractDuration.years,
                      self.contractDuration.days,
                      self.yearlyPaymentsPercentage,
                      self.annualCostsReduction,
                      get_tender(self).__class__.announcementDate or get_tender(self).enquiryPeriod.startDate,
                      get_tender(self).NBUdiscountRate))
    def validate(self):
        if super(BidsForm, self).validate():
            try:
                if str(self.yearlyPaymentsPercentage.data) == "-0.01":
                    return -1

                if self.contractDuration.data == 0 and self.contractDurationDays.data == 0:
                    message = u'You can\'t bid 0 days and 0 years'
                    append_error_to_form(self, message)
                    raise ValidationError(message)
                nbu_rate = self.auction.auction_document['NBUdiscountRate']
                annual_costs_reduction = [
                    bid['annualCostsReduction']
                    for bid in self.document['initial_bids']
                    if bid['bidder_id'] == self.bidder_id.data
                ][0]
                amount = npv(
                    self.contractDuration.data,
                    self.contractDurationDays.data,
                    self.yearlyPaymentsPercentage.data,
                    annual_costs_reduction,
                    parser.parse(
                        self.auction.auction_document['noticePublicationDate']
                    ),  # XXX TODO TEMP!!!!!
                    nbu_rate)
                stage_id = self.document['current_stage']
                if self.document['stages'][stage_id]['type'] == 'bids':
                    validate_bid_change_on_bidding(self, amount)
                else:
                    message = u'Stage not for bidding'
                    append_error_to_form(self, message)
                    raise ValidationError(message)
                return amount
            except ValidationError:
                return False
        return False
示例#5
0
文件: lot.py 项目: lttga/op2
    create_tender_feature_bid_invalid,
    create_tender_feature_bid,
    tender_features_invalid,
    # TenderLotBidResourceTest
    create_tender_bid_invalid,
    patch_tender_bid,
    bids_invalidation_on_lot_change,
)
from openprocurement.tender.esco.utils import to_decimal

lot_bid_amountPerformance = round(
    to_decimal(
        npv(
            test_bids[0]["value"]["contractDuration"]["years"],
            test_bids[0]["value"]["contractDuration"]["days"],
            test_bids[0]["value"]["yearlyPaymentsPercentage"],
            test_bids[0]["value"]["annualCostsReduction"],
            get_now(),
            NBU_DISCOUNT_RATE,
        )),
    2,
)

lot_bid_amount = round(
    to_decimal(
        escp(
            test_bids[0]["value"]["contractDuration"]["years"],
            test_bids[0]["value"]["contractDuration"]["days"],
            test_bids[0]["value"]["yearlyPaymentsPercentage"],
            test_bids[0]["value"]["annualCostsReduction"],
            get_now(),
        )),
    # TenderLotFeatureBidderResourceTest
    create_tender_feature_bid_invalid,
    create_tender_feature_bid,
    tender_features_invalid,
    # TenderLotBidResourceTest
    create_tender_bid_invalid,
    patch_tender_bid,
    bids_invalidation_on_lot_change,
)
from openprocurement.tender.esco.utils import to_decimal

lot_bid_amountPerformance = round(
    to_decimal(
        npv(test_bids[0]['value']['contractDuration']['years'],
            test_bids[0]['value']['contractDuration']['days'],
            test_bids[0]['value']['yearlyPaymentsPercentage'],
            test_bids[0]['value']['annualCostsReduction'], get_now(),
            NBU_DISCOUNT_RATE)), 2)

lot_bid_amount = round(
    to_decimal(
        escp(test_bids[0]['value']['contractDuration']['years'],
             test_bids[0]['value']['contractDuration']['days'],
             test_bids[0]['value']['yearlyPaymentsPercentage'],
             test_bids[0]['value']['annualCostsReduction'], get_now())), 2)


class TenderLotResourceTest(BaseESCOContentWebTest):

    initial_auth = ('Basic', ('broker', ''))
    test_lots_data = test_lots  # TODO: change attribute identifier