Fix bank movement get and process
Some checks failed
Update odoo 18 / update (push) Has been cancelled
Some checks failed
Update odoo 18 / update (push) Has been cancelled
This commit is contained in:
parent
9a4ba18ff8
commit
0561c3a324
3
.env
3
.env
@ -14,6 +14,5 @@ DBUSER="odoo"
|
|||||||
PASSWORD="odoo"
|
PASSWORD="odoo"
|
||||||
ADDONS="--addons-path=/opt/odoo/addons/,/opt/odoo/customaddons/$CUSTOMADDONS_DIR"
|
ADDONS="--addons-path=/opt/odoo/addons/,/opt/odoo/customaddons/$CUSTOMADDONS_DIR"
|
||||||
# ARGS=""
|
# ARGS=""
|
||||||
# ARGS="-d bross"
|
ARGS="-d bross_hms_dev -u bross_hms,exely_integration,bross_bank_management"
|
||||||
ARGS="-d cybro_hms -u bross_hms,exely_integration,bross_bank_management"
|
|
||||||
# DEBUG="-m debugpy --listen 0.0.0.0:5678 --wait-for-client"
|
# DEBUG="-m debugpy --listen 0.0.0.0:5678 --wait-for-client"
|
||||||
|
|||||||
@ -77,72 +77,74 @@ class BankMovements(models.Model):
|
|||||||
today_formatted_date = datetime.now().strftime('%Y-%m-%dT00:00:00.000')
|
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)
|
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']))
|
pages = math.ceil(int(res['data']['pager']['totalcount']) / int(res['data']['pager']['pagesize']))
|
||||||
if pages > 1:
|
if pages > 1:
|
||||||
for page in range(1, pages):
|
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)
|
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):
|
def process_movements(self):
|
||||||
to_process_movements = self.env['bank.raw.movements'].search([])
|
to_process_movements = self.env['bank.raw.movements'].search([])
|
||||||
for info in to_process_movements:
|
for rec in to_process_movements:
|
||||||
data = json.loads(info.json_data)
|
movement = json.loads(rec.json_data)
|
||||||
|
|
||||||
for movement in data['data']['movements']:
|
account_number = movement['accountNumber']
|
||||||
account_number = movement['accountNumber']
|
account_name = movement['accountName']
|
||||||
account_name = movement['accountName']
|
amount = movement['amount']['amount']
|
||||||
amount = movement['amount']['amount']
|
currency = movement['amount']['currency']
|
||||||
currency = movement['amount']['currency']
|
iban_code = account_number[4:6]
|
||||||
iban_code = account_number[4:6]
|
description = movement['description']
|
||||||
description = movement['description']
|
comment = movement['additionalInformation']
|
||||||
comment = movement['additionalInformation']
|
partner_name = movement['partnerName']
|
||||||
partner_name = movement['partnerName']
|
taxpayer_name = movement['taxpayerName']
|
||||||
taxpayer_name = movement['taxpayerName']
|
|
||||||
|
|
||||||
if movement['debitCredit'] == '0':
|
if movement['debitCredit'] == '0':
|
||||||
amount = float(amount) * -1
|
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:
|
if found_bank:
|
||||||
bank_id = found_bank.id
|
bank_id = found_bank.id
|
||||||
else:
|
else:
|
||||||
bank_id = self.env['brosse.bank'].create({
|
bank_id = self.env['brosse.bank'].create({
|
||||||
'name': BANKS[iban_code]['name'],
|
'name': BANKS[iban_code]['name'],
|
||||||
'bank_code': BANKS[iban_code]['code'],
|
'bank_code': BANKS[iban_code]['code'],
|
||||||
'iban_code': iban_code
|
'iban_code': iban_code
|
||||||
}).id
|
}).id
|
||||||
|
|
||||||
found_bank_account = self.env['brosse.bank.account'].search([
|
found_bank_account = self.env['brosse.bank.account'].search([
|
||||||
('account_number', '=', account_number),
|
('account_number', '=', account_number),
|
||||||
('currency_id', '=', currency_id.id)])
|
('currency_id', '=', currency_id.id)])
|
||||||
|
|
||||||
if found_bank_account:
|
if found_bank_account:
|
||||||
bank_account_id = found_bank_account.id
|
bank_account_id = found_bank_account.id
|
||||||
else:
|
else:
|
||||||
bank_account_id = self.env['brosse.bank.account'].create({
|
bank_account_id = self.env['brosse.bank.account'].create({
|
||||||
'bank_ids': [(4, bank_id)],
|
'bank_ids': [(4, bank_id)],
|
||||||
'holder_name': account_name,
|
'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,
|
|
||||||
'currency_id': currency_id.id,
|
'currency_id': currency_id.id,
|
||||||
'description': description,
|
'account_number': account_number,
|
||||||
'comment': comment,
|
}).id
|
||||||
'partner_name': partner_name,
|
|
||||||
'taxpayer_name': taxpayer_name
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
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'
|
# movement_id = '013762510743.2'
|
||||||
# movements_by_id = client.get_account_movements_by_id('111111', movement_id)
|
# movements_by_id = client.get_account_movements_by_id('111111', movement_id)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user