Skip to Content
Menu
This question has been flagged

Hello,

I have researched a lot in the forum and I can not find a way to be able to import a csv file with columns whose value is not the name, id and external id of a related field.

Example:
Model 1:

_inherit = "res.partner"

Field1 = fields.Char (string = "Example")


Model 2:

  _name = 'mymodel'

     Field1 = fields.Char (string = "This is an example field")
     Partner = fields.Many2one ('res.partner', string = "Supplier")

I can not find a way to import a column into the csv file and relate it to the "field 1" field in the partner model.

I appreciate any help you can give me with the case.

Thank you very much!

Avatar
Discard
Best Answer

Hi Gabriel,

What does it show while trying to import the CSV file ?

Make sure that the relation field , ie, the field partner in the CSV of  'mymodel' hold the id of the res.partner.

You can refer this doc it will give you some more information .

Thank You



Avatar
Discard
Best Answer

Hi Gabriel


If you have a lot of such imports coming from other systems where you have always had to use a mapping, search for ID/ IDs, use ETL, transform data, clead before import, import with context, import in models and child models, conditional import [import if value or expression is true] etc,.. And also use python methods

I can recommend this powerful tool which is also used for mass importing or even a data connector [CSV, TXT, Excel]

https://braintec.com/r/Pip


With this module, the users can:

- Import data for several related models at the same time from a single file.

- Import data on batches, or select different delimiters or columns. Or define conditions to skip some lines or inactive records.

- Import data based on any field to compare existing records.

- Decide to import data based in another related model records.

- What actions this data needs to perform in the Database.

- Code a few lines in the import to transform the data or add new data before inserting it if needed. Or check that related records already exist in the database to allow the import of the line.

Avatar
Discard
Best Answer

For example when importing "res.partner" from an excel with related fields for state_id (Provence or county), title  you can do it like that => 

Just build a record for your vals_list and do a lookup for the related fields

insert_record = {

...

"is_company": True,              

"title": self.env['res.partner.title'].search( domain=[('name', '=', rec.anrede.strip())],                            limit=1).id,                        "name": rec.name.strip(),                        "street": 

rec.adresse.strip(),                        

"zip": rec.plz.strip(),                        

"city": rec.ort.strip(),         

 "state_id": self.env['res.country.state'].search(domain=[('code', '=', rec.bundesland.strip())],                            limit=1).id                    

}

Avatar
Discard
Author Best Answer

The problem is that I do not have the partner id in the csv file (it is a report that generates another system). I only have the field data "field1" and I want to relate this to the related field for the partner in the csv to import. I do not have the id, external id or the name.

Many thanks in advance for the answer Niyas!

Avatar
Discard

Hi,

Then just add a new column into the csv file reprsenting the field , and give the corresponding values into it.

Related Posts Replies Views Activity
1
Oct 20
3874
3
Jun 20
2088
1
Nov 18
7458
11
Feb 17
60663
2
Mar 15
9128