server-tools icon indicating copy to clipboard operation
server-tools copied to clipboard

excel_import_export - Apply custom functions to transform values before been imported

Open dalonsoft opened this issue 2 years ago • 2 comments

I'm trying to import a bank statement excel file which contains some values than need to be transformed before been imported in the destination model field. For instance, the account number field in the Excel file contains values that are not the exactly equals to the values saved on my account model so when I try to import it directly to the many2one account field in transactions model it raises an error because this account does not exist.

I suggest that it would be interesting be able to define a custom function for each field in xml template that should be called before saving the value in the destination field. This function would receibe the readed value, do some conversions and return the new value.

Maybe it's possible to use some code block like in Field Cond. but allowing the use of custom functions.

dalonsoft avatar Feb 04 '23 00:02 dalonsoft

I've found the solution.

The response was very easy, maybe the documentation should be improved to clarify this scenario.

Basically it's possible add something like this in the template:

'IMPORT': { '1': { 'HEAD': { 'A2': 'my_field${model.my_function(value)}', }, } },

This way the function my_function declared on the current model will be executed just before the database insert so you will be able to apply any type of conversion and then return the desired value.

dalonsoft avatar Feb 19 '23 00:02 dalonsoft

There hasn't been any activity on this issue in the past 6 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 30 days. If you want this issue to never become stale, please ask a PSC member to apply the "no stale" label.

github-actions[bot] avatar Nov 16 '25 12:11 github-actions[bot]