"""Worksheet Payment Custom logic.""" from decimal import Decimal from typing import List, Optional from payment.constants import constants from payment.models import WorksheetPaymentCustom from payment.repository import worksheet_payment_custom as repository def create_worksheet_payment_custom( account_id: int, contract_id: int, currency_code: str, amount: Decimal, activity_statement_period_id: int, statement_period_id: int, payment_name: str, amount_after_withholding_and_vat: Decimal, withholding_tax_amount: Decimal, vat_amount: Decimal, withholding_tax_rate: Decimal, vat_rate: Decimal, ) -> WorksheetPaymentCustom: """ Create Worksheet Payment Custom instance. Args: account_id(int): account ID contract_id(int): contract ID currency_code(str): currency code amount(Decimal): amount activity_statement_period_id(int): activity statement period ID statement_period_id(int): statement period ID payment_name(str): payment name amount_after_withholding_and_vat(Decimal): amount after withholding and VAT withholding_tax_amount(Decimal): withholding tax amount (optional) vat_amount(Decimal): VAT amount (optional) withholding_tax_rate(Decimal): withholding tax rate (optional) vat_rate(Decimal): VAT rate (optional) Returns: WorksheetPaymentCustom instance """ return WorksheetPaymentCustom.create( account_id=account_id, contract_id=contract_id, currency_code=currency_code, amount=amount, withholding_tax_amount=withholding_tax_amount, withholding_tax_rate=withholding_tax_rate, vat_amount=vat_amount, vat_rate=vat_rate, amount_after_withholding_and_vat=amount_after_withholding_and_vat, activity_statement_period_id=activity_statement_period_id, statement_period_id=statement_period_id, payment_name=payment_name, ) def get_worksheet_payment_custom_list( limit: Optional[int] = constants.DEFAULT_PAGE_LIMIT, offset: Optional[int] = constants.DEFAULT_PAGE_OFFSET, worksheet_payment_custom_ids: Optional[List[int]] = None, ) -> dict[str, object]: """ Get a list of WorksheetPaymentCustom records. Args: limit(Optional[int]): pagination limit offset(Optional[int]): pagination offset worksheet_payment_custom_ids(Optional[List[int]]): filter by IDs Returns: Response with items list and total_count """ items, total_count = repository.get_filtered_worksheet_payment_customs( worksheet_payment_custom_ids, limit, offset, ) return {'items': items, 'total_count': total_count} def get_worksheet_payment_custom_by_id( worksheet_payment_custom_id: int, ) -> WorksheetPaymentCustom: """ Get a single WorksheetPaymentCustom record by ID. Args: worksheet_payment_custom_id(int): worksheet payment custom ID Returns: WorksheetPaymentCustom instance Raises: Exception: if the record is not found or is deleted """ return WorksheetPaymentCustom.get_by_id_or_error(worksheet_payment_custom_id) def delete_worksheet_payment_custom(worksheet_payment_custom_id: int) -> None: """ Soft delete a WorksheetPaymentCustom record by ID. Args: worksheet_payment_custom_id(int): worksheet payment custom ID Raises: Exception: if the record is not found, is deleted, or is already sent """ WorksheetPaymentCustom.delete_by_id_or_error(worksheet_payment_custom_id)