python 2.7 - Adding new line on a one2many computed field with inverse odoo -
i have one2many computed field want users able add new line of records into. added inverse field it, thing allow existing records modified
@api.one def accumulate_files(self): documents = self.env['document.customer'] document_gotten = documents.search([('name','=', self.name)]) docs in document_gotten: self.res_line_ids |= docs.customer_line_ids @api.one def edit_accumulate_files(self): documents = self.env['document.customer'] lines in documents.customer_line_ids: lines.write(self.res_line_ids)
i did workaround, not sure how can values of one2many field in inverse method, in new api, in old api. works me
@api.multi def _save_telefone(self): partner in self: phone in partner.phone_number_ids: try: # write on exisiting record int(phone.id) # write possible values phone.write({'partner_id': partner.id}) except: # create new record possible values phone.create({ 'partner_id': partner.id, 'type_id': phone.type_id.id, 'status_id': phone.status_id.id, 'sequence': phone.sequence, 'graph_value': phone.graph_value, 'name': phone.name, }) return true
basically, create record if doesn't exist otherwise write on it. how know if record exists in db? if id integer exists, otherwise have id "odoo.model.newid" means id hasn't been assigned yet record in memory yet.
Comments
Post a Comment