1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
@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('"', '')