[ADD]import_chart_of_accounts

This commit is contained in:
2024-05-29 15:45:34 +02:00
parent 57f898450d
commit ee4340ed60

View File

@@ -30,17 +30,20 @@ class ImportCoaWizard(models.TransientModel):
for record_data in data_to_import: for record_data in data_to_import:
existing_line = self.env['account.account'].search([('code', '=', record_data['code'])], limit=1) existing_line = self.env['account.account'].search([('code', '=', record_data['code'])], limit=1)
if existing_line: if existing_line:
existing_line.name = record_data['name'] #Do not use write() fonction because it's compute 'reconcile' field existing_line.name = record_data['name']
else: else:
closest_account = self.find_closest_account(record_data['code'][:3]) closest_account = self.find_closest_account(record_data['code'][:3])
new_account = self.env['account.account'].create(record_data)
if closest_account : if closest_account :
new_account.account_type = closest_account.account_type record_data['account_type'] = closest_account.account_type
new_account.reconcile = closest_account.reconcile record_data['reconcile'] = closest_account.reconcile
new_account = self.env['account.account'].create(record_data)
#return {'type': 'ir.actions.act_window_close'} return {
return False "type": "ir.actions.act_window",
"res_model": "account.account",
"view_mode": "list"
}
def find_closest_account(self, code_prefix): def find_closest_account(self, code_prefix):
# retourne le premier compte comptable commencant par les 3 memes premiers chiffres # return first code with first tree caracters identical
return self.env['account.account'].search([('code', 'like', f'{code_prefix}___')],limit=1) return self.env['account.account'].search([('code', '=like', f'{code_prefix}%')],limit=1)