I've been using the Python Flask framework to write APIs from Odoo and I've come across an issue and got stuck there. The issue is while creating a rental order where when I'm creating a rental order the Model for the form is sale.order and I'm able to save the data using the API with this code. createRental = models.execute_kw(db, uid, password, 'sale.order', 'create', [rentalObj]) Here 'rentalObj' is the JSON object of all the data.

This is the model 'sale.order'

but if I have to add the Pickup Date, Return Date, Lot number after selecting the product in the Order Line it's giving me a popup modal where I have to fill it, but that popup is having the model name of rental.wizard and I've been trying to fill the data parallelly to both sale.order & rental.wizard but I'm not able to as I can only create data in one model at a time.

This is the model 'rental.wizard'

It'd be very helpful if you can help me solve this issue as I'm not getting answers on the internet.

So please provide me with a sample code in Python or a way to add data to both the models and link them to each other. Thanks in advance.

I've tried writing this code.

rentalObj = {
                'name': data['woo_commerce_order_id'],
                'partner_id': customer_data[0]['id'],
                'validity_date': modified_date_str, #Expiry Date
                'pricelist_id': 1,  # ID of the pricelist
                'is_rental_order': 1, #Is it Rental order or Sale order
                'order_line': [
                    (0, 0, {  
                        'product_id': 864,
                        'product_uom_qty': int(quantity[1])
                    }),
                ],
            }
            createRental = models.execute_kw(db, uid, password, 'sale.order', 'create', [rentalObj])

            wizard_vals = {
                'product_id': createRental,
                'pickup_date': '2023-05-10',
                'return_date': '2023-05-20',
                'quantity': 1.0
            }
            wizard_id = models.execute_kw(db, uid, password, 'rental.wizard', 'create', [wizard_vals])
            models.execute_kw(db, uid, password, 'sale.order', 'write', [[createRental], {'wizard_id': wizard_id}])

But I'm getting the error "ValueError: Invalid field wizard_id on model sale.order"

0

There are 0 best solutions below