Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

1

override create function - ERORR

By
Mostafa Mohamed Abdelmonam Abdo
on 4/8/15, 3:19 PM 633 views

Hi there i'm tring to override create fucntion to add records in two table same time but i'm getting errorr


when i try to choose standerd for student the student should be added to many2many field in standerd model but i get an errpr when i try to do so .

here is my fields in student model :


'standard_id': fields.many2one('fci.standard', string='Standard', required=True), 

and here is my fields in standrard table model:


'code': fields.char(size=8, string='Code', required=True),
'name': fields.char(size=32, string='Name', required=True),
'sequence': fields.integer('Sequence'),
'student_ids': fields.many2many('fci.student', 'student_standard_rel', 'fci_student_standard_id', 'standard_id',
string='Student(s)'),


and here is my create function

def create(self, cr, uid, vals, context=None):
context = context or {}
created_id = super(NAME_OF_YOUR_CLASS, self).create(cr, uid, vals, context=context)
if vals.get('standard_id'):
self.pool.get('fci.standard').write(cr, uid, vals['standard_id'],
{'student_ids': [(4, created_id)]}, context=context)
return created_id



i hope i can find help

2

Cyril Gaspard (GEM)

--Cyril Gaspard (GEM)--
4136
| 5 6 8
Paris, France
--Cyril Gaspard (GEM)--

Forum contributor since 2008

Cyril Gaspard (GEM)
On 4/8/15, 7:40 PM

Hi,

I updated your code in your post, just replace NAME_OF_YOUR_CLASS with good value (you do not give the class name of student, please always give at least in your code class name to be more clear for reader)

bye

i tried to override write function too but gives me error i don't know why here is my code def write(self, cr, uid, ids, values, context = None): res = super(fci_student, self).write(cr, uid, ids, values, context = context) if values.get('standard_id'): self.pool.get('fci.standard').write(cr, uid, values['standard_id'], {'student_ids': (0, 0, {values})}, context=context) return res and error says :TypeError: unhashable type: 'dict'

Mostafa Mohamed Abdelmonam Abdo
on 4/8/15, 9:25 PM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 4/8/15, 3:19 PM
Seen: 633 times
Last updated: 4/8/15, 9:29 PM