"""Blueprint for Worksheet Tax Correction API.""" from http import HTTPStatus from typing import Optional, Tuple from abacus_common_logic.marshalling.base import PaginationSchema from common_apispec import doc, marshal_with, use_kwargs from flask import Blueprint, request, Response from owsrequest import flask_request from owsresponse import response from owsresponse.adaptors.flask import flaskify from payment.constants import constants from payment.constants.error import ERROR_CODE_AUTHORIZATION from payment.logic import worksheet_tax_correction as logic from payment.schemas.worksheet_tax_correction import ( TaxCorrectionDeleteRequestSchema, WorksheetTaxCorrectionCreateSchema, WorksheetTaxCorrectionsFilterParamsPostSchema, WorksheetTaxCorrectionsListSchema, ) from payment.utils.authorization import check_access worksheet_tax_correction_api = Blueprint( 'worksheet_tax_correction_api', __name__, url_prefix='/tax-corrections', ) @worksheet_tax_correction_api.route( '/bulk/', methods=['POST'], ) @doc( tags=['tax correction'], description='Bulk creation endpoint for worksheet_tax_correction.', ) @check_access @use_kwargs( WorksheetTaxCorrectionCreateSchema(many=True), location='json', required=True ) @marshal_with( None, code=HTTPStatus.CREATED, description=HTTPStatus.CREATED.phrase, apply=False ) def bulk_create_worksheet_tax_correction( *create_params: dict, ) -> Tuple[dict, int] | Response: """Bulk creating worksheet_tax_correction records.""" logic.bulk_create(create_params) return constants.BULK_ENDPOINT_SUCCESS_RESPONSE, HTTPStatus.CREATED @worksheet_tax_correction_api.route( f'/' f'//', methods=['POST'], ) @doc(tags=['tax correction'], description='List endpoint for worksheet_tax_correction.') @check_access @use_kwargs(PaginationSchema, location='query') @use_kwargs(WorksheetTaxCorrectionsFilterParamsPostSchema, location='json') @marshal_with( WorksheetTaxCorrectionsListSchema, code=HTTPStatus.OK, description=HTTPStatus.OK.phrase, ) def get_tax_corrections( correction_type: str, correction_status: str, filters: Optional[dict], limit: Optional[int] = constants.DEFAULT_PAGE_LIMIT, offset: Optional[int] = constants.DEFAULT_PAGE_OFFSET, ) -> Tuple[dict, int] | Response: """Get tax corrections.""" tax_corrections = logic.get_tax_corrections( correction_type=correction_type, correction_status=correction_status, limit=limit, offset=offset, **filters, ) return tax_corrections, HTTPStatus.OK @worksheet_tax_correction_api.route( '/bulk/', methods=['DELETE'], ) @check_access @doc( tags=['tax correction'], description='Delete endpoint for worksheet_tax_corrections', ) @use_kwargs(TaxCorrectionDeleteRequestSchema, location='json', required=True) @marshal_with( None, code=HTTPStatus.NO_CONTENT, description=HTTPStatus.NO_CONTENT.phrase, apply=False, ) @marshal_with( None, code=HTTPStatus.BAD_REQUEST, description=HTTPStatus.BAD_REQUEST.phrase, ) def delete_worksheet_account_contract_payable_details( **payload, ) -> Tuple[None, int] | Response: """Bulk deleting worksheet_tax_corrections by list of worksheet_tax_corrections_ids.""" # noqa: E501 worksheet_tax_correction_ids = payload.get('worksheet_tax_correction_ids') logic.delete_worksheet_tax_corrections( worksheet_tax_correction_ids=worksheet_tax_correction_ids ) return None, HTTPStatus.NO_CONTENT