Created
April 17, 2020 08:47
-
-
Save strufkin/db4cad12fc0634c9e35f960df979c479 to your computer and use it in GitHub Desktop.
dataclass example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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('"', '') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment