"""Schema for Worksheet Account Contract Closing Balance.""" from abacus_common_logic.marshalling.base import PaginationSchema from abacus_common_logic.marshalling.custom_fields import ma from marshmallow import validates, ValidationError from payment.constants.constants import ( DEFAULT_SORT_BY, DEFAULT_SORT_ORDER, WORKSHEET_PAYABLE_BALANCE_AFTER_TAX_SORTABLE_COLUMNS, ) from payment.constants.error import ERROR_INVALID_SORT_BY, ERROR_INVALID_SORT_ORDER class WorksheetPayableBalanceAfterTaxSchema(ma.Schema): """ Schema for Worksheet Account Contract Payable After Tax. This schema defines the structure and validation rules for the Worksheet Account Contract Payable After Tax. It specifies the required fields and their data types. Attributes: worksheet_account_contract_closing_balance_id (int): The ID of the worksheet account contract closing balance. contract_id (int): The ID of the contract. account_id (int): The ID of the account. statement_period_id (int): The ID of the statement period. abacus_event_id (int): The ID of the Abacus event. payable_amount_pre_tax (decimal): The payable amount pre tax. tax_withholding_amount (decimal): The tax withholding amount. vat_amount (decimal): VAT amount. payable_amount_post_tax (decimal): The payable amount post tax. currency_code (str): The currency code. country_of_tax_residence (str): The country of tax residence. country_of_tax_policy (str): The country of tax policy. """ # noqa: E501 worksheet_account_contract_closing_balance_id = ma.NonNegativeInteger(required=True) contract_id = ma.NonNegativeInteger(required=True) account_id = ma.NonNegativeInteger(required=True) statement_period_id = ma.NonNegativeInteger(required=True) abacus_event_id = ma.NonNegativeInteger(required=True) payable_amount_pre_tax = ma.Decimal(as_string=True, required=True) tax_withholding_amount = ma.Decimal(as_string=True, allow_none=True) vat_amount = ma.Decimal(as_string=True, allow_none=True) payable_amount_post_tax = ma.Decimal(as_string=True, required=True) currency_code = ma.NonemptyString(required=True) country_of_tax_residence = ma.NonemptyString(required=True) country_of_tax_policy = ma.NonemptyString() class WorksheetPayableBalanceAfterTaxDetailSchema( WorksheetPayableBalanceAfterTaxSchema ): """ Schema for Worksheet Account Contract Payable After Tax. This schema defines the structure for the Worksheet Account Contract Payable After Tax. It specifies the required fields and their data types for the existing records. Attributes: worksheet_account_contract_payable_after_tax_id (int): The ID ofr the worksheet worksheet_account_contract_closing_balance_id (int): The ID of the worksheet account contract closing balance. contract_id (int): The ID of the contract. account_id (int): The ID of the account. statement_period_id (int): The ID of the statement period. abacus_event_id (int): The ID of the Abacus event. payable_amount_pre_tax (decimal): The payable amount pre tax. tax_withholding_amount (decimal): The tax withholding amount. vat_amount (decimal): VAT amount. payable_amount_post_tax (decimal): The payable amount post tax. currency_code (str): The currency code. country_of_tax_residence (str): The country of tax residence. country_of_tax_policy (str): The country of tax policy. """ # noqa: E501 worksheet_account_contract_payable_after_tax_id = ma.NonNegativeInteger( required=True ) class WorksheetPayableBalanceAfterTaxBulkUpdateSchema(ma.Schema): """ Schema for bulk updating Worksheet Account Contract Payable After Tax. This schema defines the structure for bulk update operations. Only the ID and the fields to be updated are required. Attributes: worksheet_account_contract_payable_after_tax_id (int): The ID of the worksheet. tax_withholding_amount (decimal): The tax withholding amount. vat_amount (decimal): VAT amount. payable_amount_post_tax (decimal): The payable amount post tax. """ worksheet_account_contract_payable_after_tax_id = ma.NonNegativeInteger( required=True ) tax_withholding_amount = ma.Decimal(as_string=True, allow_none=True) vat_amount = ma.Decimal(as_string=True, allow_none=True) payable_amount_post_tax = ma.Decimal(as_string=True, required=True) class WorksheetPayableAfterTaxFilterSchema(PaginationSchema): """ WorksheetPayableAfterTaxFilterSchema query schema. Attributes: contract_ids: list of ints. """ contract_ids = ma.List(ma.NonNegativeInteger(), required=False, allow_none=True) sort_by = ma.String(required=False, allow_none=True) sort_order = ma.String( required=False, allow_none=True, load_default=DEFAULT_SORT_ORDER ) search_term = ma.String(required=False, allow_none=True) @validates('sort_by') def validate_sort_by(self, value): if value.lower() not in WORKSHEET_PAYABLE_BALANCE_AFTER_TAX_SORTABLE_COLUMNS: raise ValidationError(ERROR_INVALID_SORT_BY.format(sort_by=value)) @validates('sort_order') def validate_sort_order(self, value): if value.lower() not in ['asc', 'desc']: raise ValidationError(ERROR_INVALID_SORT_ORDER) class WorksheetPayableBalanceAfterTaxListSchema(ma.Schema): """ WorksheetPayableBalanceAfterTax records list. Attributes: items ([WorksheetPayableBalanceAfterTaxSchema]): list of items. total_count (int): Total count. """ items = ma.Nested(WorksheetPayableBalanceAfterTaxDetailSchema, many=True) total_count = ma.NonNegativeInteger(required=True) class GenericSuccessResponseSchema(ma.Schema): """ Schema for a generic success response. Attributes: message (str): A success message. """ message = ma.String(required=False, load_default='OK') class WorksheetPayableBalanceAfterTaxOverviewSchema(ma.Schema): """ Schema for Worksheet Payable Balance After Tax Aggregated Data. Attributes: payable_amount_pre_tax (decimal): The total payable amount pre tax. tax_withholding_amount (decimal): The total tax withholding amount. vat_amount (decimal): The total VAT amount. payable_amount_post_tax (decimal): The total payable amount post tax. """ payable_amount_pre_tax = ma.Decimal(as_string=True, required=True) tax_withholding_amount = ma.Decimal(as_string=True, required=True) vat_amount = ma.Decimal(as_string=True, required=True) payable_amount_post_tax = ma.Decimal(as_string=True, required=True)