Odoo Ayuda


1 Respuesta
Samo Arko Eslovenia
11/9/19 8: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 Comentarios
Tabla d.o.o., Samo Arko Eslovenia
11/9/19 8: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 Bélgica
12/9/19 2:04

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

17/9/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 Eslovenia
18/9/19 1: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/9/19 4:21

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

Tabla d.o.o., Samo Arko Eslovenia
18/9/19 4: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/9/19 18:26

I have edited the question to include the code

Tabla d.o.o., Samo Arko Eslovenia
19/9/19 2: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.

Realizar una pregunta
Keep Informed
1 seguidor(es)
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