Gist · 1 / URL: https://repo.truf-kin.com/_admin/gists/1
Public Gist
example dataclass
Expires: Never
st - created 5 years and 7 months ago
updated file: HistDataClass
HistDataClass.py
@dataclass
class HistItem:
    id: str
    operation_date: date
    total_amount: dict
    trans_amount: dict
    fee_data: list
    amount: Decimal
    category: str
    template: str
    description: str
    service: dict
    location: dict
    payment_type: str
    payee: str

    def __post_init__(self):
        if 'Salary' in self.description and not self.category:
            self.category = 'Salary'
            self.payee = 'Allied'
        elif 'Deposit' in self.description and not self.category:
            self.category = 'Deposit'
            self.payee = '01 MICB Account Deposit'
        elif 'Cash-In' in self.description and not self.category:
            self.category = 'Cash-In'
            self.payee = '01 MICB Account Deposit'
        elif 'MEGOGO' in self.description and not self.category:
            self.category = 'Bills > TV'
        elif 'PETRO' in self.description and not self.category:
            self.category = 'Petroleum'

        if self.service:
            self.payee = self.service['name']
            self.payment_type = "онлайн перевод"

        if self.location:
            self.payee = self.location['merchant']

        if ('ALIEXPRESS' or 'aliexpress.com' or 'AliExpress') in self.payee:
            self.payee = 'ALIEXPRESS'
            self.category = 'Shopping > Online > Aliexpress'

        if self.payee == 'Orange' or self.payee == 'Moldcell':
            phnumber = self.service['shortFields']['CUSTOM_IDT']
            self.description = f"{phnumber} : {self.description}"

        if not self.total_amount:
            self.amount = Decimal(self.trans_amount['value']).quantize(Decimal('.01'), rounding=ROUND_UP)
            self.currency = self.trans_amount['currency']
        else:
            self.amount = Decimal(self.total_amount['value']).quantize(Decimal('.01'), rounding=ROUND_UP)
            self.currency = self.total_amount['currency']

        if self.fee_data:
            fee_unit = self.fee_data['totalFee']['currency']
            fee_amount = self.fee_data['totalFee']['value']
            fee_string = f" fee: {fee_unit} {fee_amount}"
            if self.trans_amount and self.total_amount:
                if self.trans_amount['currency'] != self.total_amount['currency']:
                    trans_unit = self.trans_amount['currency']
                    trans_amount = self.trans_amount['value']
                    self.description = f"({trans_unit} {trans_amount}{fee_string}) {self.description}"

        self.description = self.description.replace(',', '').replace('"', '')