diff --git a/.env b/.env index e947011..62ceeb9 100644 --- a/.env +++ b/.env @@ -14,6 +14,5 @@ DBUSER="odoo" PASSWORD="odoo" ADDONS="--addons-path=/opt/odoo/addons/,/opt/odoo/customaddons/$CUSTOMADDONS_DIR" # ARGS="" -# ARGS="-d bross" -ARGS="-d cybro_hms -u bross_hms,exely_integration,bross_bank_management" +ARGS="-d bross_hms_dev -u bross_hms,exely_integration,bross_bank_management" # DEBUG="-m debugpy --listen 0.0.0.0:5678 --wait-for-client" diff --git a/bross_bank_management/models/bank_models.py b/bross_bank_management/models/bank_models.py index 7f240da..e00c934 100644 --- a/bross_bank_management/models/bank_models.py +++ b/bross_bank_management/models/bank_models.py @@ -77,72 +77,74 @@ class BankMovements(models.Model): today_formatted_date = datetime.now().strftime('%Y-%m-%dT00:00:00.000') res = client.get_account_movements_by_date_range('111111', '2024-01-01T00:00:00.000', today_formatted_date) - self.create_or_update_raw_data(res, 'bank.raw.movements', res['data']) + + if not res['data']: + raise UserError(_('No data found for movements')) + + for movement in res['data']['movements']: + self.create_or_update_raw_data(movement, 'bank.raw.movements', movement['movementId']) + pages = math.ceil(int(res['data']['pager']['totalcount']) / int(res['data']['pager']['pagesize'])) if pages > 1: for page in range(1, pages): res = client.get_account_movements_by_date_range_next_page('111111', page, 700, '2024-01-01T00:00:00.000', today_formatted_date) - self.create_or_update_raw_data(res, 'bank.raw.movements', res['data']) + for movement in res['data']['movements']: + self.create_or_update_raw_data(movement, 'bank.raw.movements', movement['movementId']) def process_movements(self): to_process_movements = self.env['bank.raw.movements'].search([]) - for info in to_process_movements: - data = json.loads(info.json_data) + for rec in to_process_movements: + movement = json.loads(rec.json_data) - for movement in data['data']['movements']: - account_number = movement['accountNumber'] - account_name = movement['accountName'] - amount = movement['amount']['amount'] - currency = movement['amount']['currency'] - iban_code = account_number[4:6] - description = movement['description'] - comment = movement['additionalInformation'] - partner_name = movement['partnerName'] - taxpayer_name = movement['taxpayerName'] + account_number = movement['accountNumber'] + account_name = movement['accountName'] + amount = movement['amount']['amount'] + currency = movement['amount']['currency'] + iban_code = account_number[4:6] + description = movement['description'] + comment = movement['additionalInformation'] + partner_name = movement['partnerName'] + taxpayer_name = movement['taxpayerName'] - if movement['debitCredit'] == '0': - amount = float(amount) * -1 + if movement['debitCredit'] == '0': + amount = float(amount) * -1 - currency_id = self.env['res.currency'].search([('name', '=', currency)]) + currency_id = self.env['res.currency'].search([('name', '=', currency)]) - found_bank = self.env['brosse.bank'].search([('iban_code', '=', iban_code)]) + found_bank = self.env['brosse.bank'].search([('iban_code', '=', iban_code)]) - if found_bank: - bank_id = found_bank.id - else: - bank_id = self.env['brosse.bank'].create({ - 'name': BANKS[iban_code]['name'], - 'bank_code': BANKS[iban_code]['code'], - 'iban_code': iban_code - }).id + if found_bank: + bank_id = found_bank.id + else: + bank_id = self.env['brosse.bank'].create({ + 'name': BANKS[iban_code]['name'], + 'bank_code': BANKS[iban_code]['code'], + 'iban_code': iban_code + }).id - found_bank_account = self.env['brosse.bank.account'].search([ - ('account_number', '=', account_number), - ('currency_id', '=', currency_id.id)]) + found_bank_account = self.env['brosse.bank.account'].search([ + ('account_number', '=', account_number), + ('currency_id', '=', currency_id.id)]) - if found_bank_account: - bank_account_id = found_bank_account.id - else: - bank_account_id = self.env['brosse.bank.account'].create({ - 'bank_ids': [(4, bank_id)], - 'holder_name': account_name, - 'currency_id': currency_id.id, - 'account_number': account_number, - }).id - - self.env['brosse.bank.deposits'].create({ - 'bank_account_id': bank_account_id, - 'amount': amount, + if found_bank_account: + bank_account_id = found_bank_account.id + else: + bank_account_id = self.env['brosse.bank.account'].create({ + 'bank_ids': [(4, bank_id)], + 'holder_name': account_name, 'currency_id': currency_id.id, - 'description': description, - 'comment': comment, - 'partner_name': partner_name, - 'taxpayer_name': taxpayer_name - }) - - - + 'account_number': account_number, + }).id + self.env['brosse.bank.deposits'].create({ + 'bank_account_id': bank_account_id, + 'amount': amount, + 'currency_id': currency_id.id, + 'description': description, + 'comment': comment, + 'partner_name': partner_name, + 'taxpayer_name': taxpayer_name + }) # movement_id = '013762510743.2' # movements_by_id = client.get_account_movements_by_id('111111', movement_id)