Search code examples
odooodoo-8openerp-8

Auto Populate a Grid in Odoo and Error


Odoo do an Auto Populate a Grid when a user Creating a new information with One2many relations fields?

this is my Example Auto Populate

def getCheckListId(self):
    self.env.cr.execute("select 1 employee_id,1 PARAM1,1 PARAM2,1 PARAM3,1 PARAM3,1 PARAM4 from hr_employee_checklist  ")
    checklistTemplates = self.env.cr.fetchall()
    return checklistTemplates

And this function will be used as a default in One2ManyFields

employee_checklists = fields.One2many('hr.employee_checklist','employee_id', readonly=False,copy=False, default = getCheckListId)

But I have an error the error is

AttributeError: 'str' object has no attribute 'iteritems'

Can someone help me with this problem or other ways to populate Grid in Odoo


Solution

  • One2many

    One2many field; the value of such a field is the recordset of all the records in comodel_name such that the field inverse_name is equal to the current record.

    Parameters

    • comodel_name -- name of the target model (string)
    • inverse_name -- name of the inverse Many2one field in comodel_name (string)
    • domain -- an optional domain to set on candidate values on the client side (domain or string)
    • context -- an optional context to use on the client side when handling that field (dictionary)
    • auto_join -- whether JOINs are generated upon search through that field (boolean, by default False)
    • limit -- optional limit to use upon read (integer)

    So, One2many fields always contains comodel's reference value, you just need to give ids of that relational field, remaining things will maintain by odoo engine it self.

    @api.model
    def getCheckListId(self):
        return self.env['hr.employee.checklist'].search([]).ids