Odoo Help


1 Risposta
Samo Arko Slovenia
11/09/19, 08:37

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

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 Commenti
Tabla d.o.o., Samo Arko Slovenia
11/09/19, 08:39

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

Oocademy, Yenthe Van Ginneken Belgio
12/09/19, 02:04

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

17/09/19, 18:25

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
18/09/19, 01:57

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 :)

18/09/19, 04:21

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

Tabla d.o.o., Samo Arko Slovenia
18/09/19, 04:35

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:


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

18/09/19, 18:26

I have edited the question to include the code

Tabla d.o.o., Samo Arko Slovenia
19/09/19, 02:03

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.

Fai una domanda
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.

Odoo Training Center

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

Test it now