"""Reference Tax Withholding model.""" from abacus_common_logic.connectors.database import db from abacus_common_logic.models.base import BaseModel from sqlalchemy import select class ReferenceTaxWithholding(BaseModel): """Reference Tax Withholding model.""" __tablename__ = 'reference_tax_withholding' reference_tax_withholding_id = db.Column(db.Integer, primary_key=True) country_of_withholding = db.Column(db.String(3), nullable=False) country_of_tax_residence = db.Column(db.String(3), nullable=False) tax_rate = db.Column(db.Numeric(5, 2), nullable=False) is_resource_provisioned = db.Column(db.Boolean, nullable=True) @classmethod def get_all(cls, country_of_withholding=None, country_of_tax_residence=None): """Retrieve all tax withholding entries ordered by id.""" stmt = select(cls).order_by(cls.reference_tax_withholding_id) if country_of_withholding: stmt = stmt.where(cls.country_of_withholding == country_of_withholding) if country_of_tax_residence: stmt = stmt.where(cls.country_of_tax_residence == country_of_tax_residence) return db.session.execute(stmt).scalars().all()