2

When adding the CSV file with multiple parent_id to the hr.profession.category model this error appears:

Exception: Module loading ptplus_hr_payroll failed: file ptplus_hr_payroll/data/hr.profession.category.csv could not be processed: No matching record found for name 'Oficiais das Forças Armadas' in field 'Parent Category'

The data file contains the following table:

id,name,parent_id

hr_profession_category_1,Profissões das Forças Armadas,

hr_profession_category_2,Oficiais das Forças Armadas,Profissões das Forças Armadas

hr_profession_category_3,Oficial de Marinha,Oficiais das Forças Armadas

The model code for hr.profession.category looks like this:

class HrProfessionCategory(models.Model):
    _name = "hr.profession.category"
    _description = "Hr Profession Category"
    _parent_name = "parent_id"
    _parent_store = True
    _rec_name = 'complete_name'
    _order = 'complete_name'

    name = fields.Char('Name', index=True, required=True)
    complete_name = fields.Char(
        'Complete Name', compute='_compute_complete_name',
        store=True)
    parent_id = fields.Many2one('hr.profession.category', 'Parent Category', index=True, ondelete='cascade')
    parent_path = fields.Char(index=True)
    child_id = fields.One2many('hr.profession.category', 'parent_id', 'Child Categories')

    @api.depends('name', 'parent_id.complete_name')
    def _compute_complete_name(self):
        for category in self:
            if category.parent_id:
                category.complete_name = '%s / %s' % (category.parent_id.complete_name, category.name)
            else:
                category.complete_name = category.name

Can anyone help me decipher the problem?

1 Answers1

0

When trying to import the CSV file, Odoo will call the name_search function using the = operator to find the DB id of the provided category name and if the following condition

not (name == '' and operator == 'ilike')

Is satisfied, Odoo will append the following search criteria to the search args:

 (self._rec_name, operator, name)
 

Which will be evaluated to (You set the _rec_name to complete_name):

 ('complete_name', '=', 'Oficiais das Forças Armadas')

and because 'Oficiais das Forças Armadas' category has a parent categorty, the complete name should be:

Profissões das Forças Armadas / Oficiais das Forças Armadas

If you use this as a parent field value Odoo should import the csv file without any error.

Kenly
  • 24,317
  • 7
  • 44
  • 60