Odoo Help

0

0
1 Answer
0
Samo Arko Slovenia
9/11/19, 8:37 AM

In model a you'll need to overide the write method and there check the state and then create the record in model b.

@api.multi
def write(self, vals):
if vals.get('state'):
if vals.get('state') == 'Unit Manager parts approved'     # you should really use something shorter 
lines_dict # here get the lines that you want in a dict formatted for creating record in model b lines
self.env['fundrequest.partsline'].create(lines_dict) # here you pass the dict with vals that you want

return super(ServiceRequest, self).write(vals)
8 Comments
Tabla d.o.o., Samo Arko Slovenia
9/11/19, 8:39 AM

sorry I don't know how to use this new WYSIWYG editor. So that's why the code looks so bad.

Yenthe Van Ginneken Belgium
9/12/19, 2:04 AM

Why not use an onchange on the state field and just do a self.env['your.model'].create() though?

DOMINIC ANYANNA Nigeria
9/17/19, 6:25 PM

Thank You for your answer . i have followed your advice but i now have an error (ValueError: Expected singleton: jobcard.partsline(25, 26) )

Tabla d.o.o., Samo Arko Slovenia
9/18/19, 1:57 AM

That's because you're passing more than one record. You're passing the records with id 25 and 26. You need to pass them one by one. I don't know where this happens but try to do that line with "for rec in self:" (iterate the records one by one in the recordset) and call the method on rec and not on self. Living a like also helps :)

DOMINIC ANYANNA Nigeria
9/18/19, 4:21 AM

Please can you help me with a sample code based on earlier example

Tabla d.o.o., Samo Arko Slovenia
9/18/19, 4:35 AM

I can't because I don't know on what line it throws this error and what are you doing on that line. You're probably calling a method with the self parameter. so the only help I can offer you is like I wrote in the earlier comment you need to use a for loop to iterate trough the objects.

for rec in self:

rec.the_method_that_throws_error()

But I don't know if that's the problem or something else. Edit your question with the code that throws the error.

DOMINIC ANYANNA Nigeria
9/18/19, 6:26 PM

I have edited the question to include the code

Tabla d.o.o., Samo Arko Slovenia
9/19/19, 2:03 AM

I think this line is wrong "'operations': [(6, 0, self.operations.parts_id.ids)]," it needs to be 'operations': [(0, 0, {vals_dict1}), (0, 0, {vals_dict2}), ...]. I normally use (6, 0, [ids]) on many2many fields not one2many. But I might be wrong.

Ask a Question
Keep Informed
1 follower(s)
About This Community

This platform 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.

Register
Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now