"""Worksheet tax correction vat logic.""" from typing import Iterable, List, Optional from sqlalchemy import exc from payment.constants import constants, error from payment.logic.exceptions import LogicError from payment.models import WorksheetTaxCorrectionVAT from payment.repository import worksheet_tax_correction_vat as repository def bulk_create( create_params: Iterable[dict], ) -> List[WorksheetTaxCorrectionVAT]: """Create one or more worksheet_tax_correction_vat records.""" instances = [] for params in create_params: record = WorksheetTaxCorrectionVAT(**params) instances.append(record) if instances: try: WorksheetTaxCorrectionVAT.bulk_create(instances) except exc.IntegrityError: raise LogicError(error.ERROR_INTEGRITY) else: raise LogicError(error.ERROR_NO_INSTANCES_TO_CREATE) return instances def get_tax_corrections_vat( correction_status: str, correction_statement_period_id: Optional[int] = None, contract_ids: Optional[List[int]] = None, worksheet_tax_correction_vat_ids: Optional[List[int]] = None, limit: Optional[int] = constants.DEFAULT_PAGE_LIMIT, offset: Optional[int] = constants.DEFAULT_PAGE_OFFSET, ) -> dict: """ Get worksheet_tax_correction filtered by some criteria. Args: correction_status (str) correction_statement_period_id (Optional[int]) contract_ids: (Optional[List[int]]) limit: (Optional[int]) offset: (Optional[int]) """ items, total_count = repository.get_filtered_worksheet_tax_corrections_vat( correction_status, correction_statement_period_id, contract_ids, worksheet_tax_correction_vat_ids, limit, offset, ) return {'items': items, 'total_count': total_count} def delete_worksheet_tax_corrections_vat( worksheet_tax_correction_vat_ids: list, ) -> None: """Soft delete worksheet_tax_correction_vat records.""" WorksheetTaxCorrectionVAT.soft_delete_by_ids(worksheet_tax_correction_vat_ids)