Esempio n. 1
0
    def post(self):
        contract = self.request.validated["contract"]
        data = self.request.validated["ownership_data"]

        location = get_transfer_location(self.request, "Contract", contract_id=contract.id)
        transfer = extract_transfer(self.request, transfer_id=data["id"])

        if transfer.get("usedFor") and transfer.get("usedFor") != location:
            self.request.errors.add("body", "transfer", "Transfer already used")
            self.request.errors.status = 403
            return

        update_ownership(contract, transfer)
        self.request.validated["contract"] = contract

        transfer.usedFor = location
        self.request.validated["transfer"] = transfer

        if save_transfer(self.request):
            self.LOGGER.info(
                "Updated transfer relation {}".format(transfer.id),
                extra=context_unpack(self.request, {"MESSAGE_ID": "transfer_relation_update"}),
            )

            if save_contract(self.request):
                self.LOGGER.info(
                    "Updated ownership of contract {}".format(contract.id),
                    extra=context_unpack(self.request, {"MESSAGE_ID": "contract_ownership_update"}),
                )

                return {"data": contract.serialize("view")}
Esempio n. 2
0
    def post(self):
        agreement = self.request.validated["agreement"]
        data = self.request.validated["ownership_data"]

        route_name = "{}.Agreement".format(agreement.agreementType)
        location = get_transfer_location(self.request,
                                         route_name,
                                         agreement_id=agreement.id)
        transfer = extract_transfer(self.request, transfer_id=data["id"])

        if transfer.get("usedFor") and transfer.get("usedFor") != location:
            self.request.errors.add("body", "transfer",
                                    "Transfer already used")
            self.request.errors.status = 403
            return

        update_ownership(agreement, transfer)
        self.request.validated["agreement"] = agreement

        transfer.usedFor = location
        self.request.validated["transfer"] = transfer

        if save_transfer(self.request):
            self.LOGGER.info(
                "Updated transfer relation {}".format(transfer.id),
                extra=context_unpack(
                    self.request, {"MESSAGE_ID": "transfer_relation_update"}),
            )

            if save_agreement(self.request):
                self.LOGGER.info(
                    "Updated ownership of agreement {}".format(agreement.id),
                    extra=context_unpack(
                        self.request,
                        {"MESSAGE_ID": "agreement_ownership_update"}),
                )

                return {"data": agreement.serialize("view")}
Esempio n. 3
0
    def post(self):
        tender = self.request.validated["tender"]
        data = self.request.validated["ownership_data"]

        route_name = "{}:Tender".format(tender.procurementMethodType)
        location = get_transfer_location(self.request,
                                         route_name,
                                         tender_id=tender.id)
        transfer = extract_transfer(self.request, transfer_id=data["id"])

        if transfer.get("usedFor") and transfer.get("usedFor") != location:
            self.request.errors.add("body", "transfer",
                                    "Transfer already used")
            self.request.errors.status = 403
            return

        update_ownership(tender, transfer)
        self.request.validated["tender"] = tender

        transfer.usedFor = location
        self.request.validated["transfer"] = transfer

        if save_transfer(self.request):
            self.LOGGER.info(
                "Updated transfer relation {}".format(transfer.id),
                extra=context_unpack(
                    self.request, {"MESSAGE_ID": "transfer_relation_update"}),
            )

            if save_tender(self.request):
                self.LOGGER.info(
                    "Updated ownership of tender {}".format(tender.id),
                    extra=context_unpack(
                        self.request,
                        {"MESSAGE_ID": "tender_ownership_update"}),
                )

                return {"data": tender.serialize("view")}