Search code examples
importodooodoo-12

Automatically Identify related field in importing in Odoo-12


I'm having this problem in odoo while I'm importingenter image description here

How can I prevent those Don't Import and automatically give the Relation field so that the user don't have to select any other relation field

I had already tried modifying my .xlsx file first row where the string of the field is declared to be identical to my fields string(literally copy paste it) but its still didn't automatically set a relation field


Solution

  • When the field name in the header did not match, you will see the 'Don\'t import' placeholder (there is no data to show).

    After you click on Load file and select the XLSX file, Odoo will call the parse_preview from javascript to generate data to show to the user. It will generate a preview of the uploaded file and performs fields-matching between the import's file data and the model's columns.

    The matches are generated in _match_headers which calls _match_header to attempts to match a given header to a field of the imported model. It will check if the header matches with the field name or the field string if not, it will try to check if the translated header matches the field string. If all the previous did not succeed it will check for related fields and if / is not in the header it will return an empty list which means that it did not match otherwise it will iteratively dive into fields tree.

    The fields used to match the header are generated in get_fields method, it will recursively get fields for the provided model (through fields_get) and filter them according to importability.

    The field will be excluded from the importable fields if:

    The field is blacklisted or deprecated.

    The field is readonly and has no states attribute or no condition is defined for readonly attribute in states when the field is readonly.