"""Worksheet tax correction 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 WorksheetTaxCorrection from payment.repository import worksheet_tax_correction as repository def bulk_create( create_params: Iterable[dict], ) -> List[WorksheetTaxCorrection]: """Create one or more worksheet_tax_correction records.""" instances = [] for params in create_params: record = WorksheetTaxCorrection(**params) instances.append(record) if instances: try: WorksheetTaxCorrection.bulk_create(instances) except exc.IntegrityError: raise LogicError(error.ERROR_INTEGRITY) return instances def get_tax_corrections( correction_type: str, correction_status: str, correction_statement_period_id: Optional[int] = None, contract_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_type (str) 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( correction_type, correction_status, correction_statement_period_id, contract_ids, limit, offset, ) return {'items': items, 'total_count': total_count} def delete_worksheet_tax_corrections(worksheet_tax_correction_ids: list) -> None: """Soft delete worksheet_tax_correction records.""" WorksheetTaxCorrection.soft_delete_by_ids(worksheet_tax_correction_ids)