Aide

0

Create order_line from code

Avatar
Ali Ammar

I have a field linked with  Vehicle_id this  Vehicle had a product 

when I chose any  Vehicle I need to add it to the order line

when I save the record i got it "

Missing required fields on accountable sale order line.

my code :

@api.onchange('vehicle_id')

    def_add_product(self):

        lines=[]

        vals={}

        forrecinself:

            ifrec.vehicle_id:

                product=self.env['fleet.vehicle'].search([('id' , '=' ,rec.vehicle_id.id)]) 

               print('product >>>' + str(product.product))

                asd=product.product 

               vals = { 

                      'product_id' : asd.id 

,                     'order_id': id,
                    'name': asd['name'],
                    'product_uom_qty':  1,
                    'price_unit': 1,

                     'product_uom_qty' : 1

              }    

                lines.append((0,0,vals))

                rec.order_line = lines

 


 


Avatar
Annuler
1Réponse
1

Hi Ali Ammar,

Please add  product_uom (Unit of Measure) in the order line dictionary.  As you are creating the sale order line, then you must have a value of product and UOM in the line.

Hope it will help you.

1Commentaires
Avatar
Annuler
Avatar
Ali Ammar
-

Thanx
It work now