odoo-await icon indicating copy to clipboard operation
odoo-await copied to clipboard

update with context

Open DonsWayo opened this issue 2 years ago • 4 comments

Hi,

Is posible to update a model with context?

like this:

odoo.update('product.template', 222, {short_description: '3M Hazard Warning Tape ', context: { lang: 'en_GB' }});

I get a true response, but not updated on odoo. Can do in some way?

thanks

DonsWayo avatar Jun 15 '22 15:06 DonsWayo

That's not currently built into the library.

You could try using the execute_kw(model, method, params) method as a work around.

something like:

await odoo.execute_kw('product.template', 'update', [ [222 , {short_description: "3M Hazard Warning Tape"}, { context: { lang: 'en_GB'  } } ] ]

Could you let me know if that works?

vettloffah avatar Jun 15 '22 16:06 vettloffah

Thanks for the suggestion but not working.

I get this error:

TypeError: cannot marshal None unless allow_none is enabled.

I see other examples like this:

api.execute_kw(db, uid, password, 'res.partner', 'write', [[id], {'name': "Atul Arvind"}], {'context' :{'tag': 1}})

When try to do the same.

await odoo.execute_kw('product.template', 'write', [[id], { name: '3M Hazard Warning Tape' }], { context: { lang: 'en_GB' } });

get this response: result = method(recs, *args, **kwargs) TypeError: write() got an unexpected keyword argument 'name' or TypeError: write() got an unexpected keyword argument 'short_description'

Same response with update or write

DonsWayo avatar Jun 16 '22 08:06 DonsWayo

@DonsWayo the "marshal none" error is actually just odoo not returning anything, which is not actually usually an error. It's because the XML RPC settings in odoo by default are set to not allow it to return nothing. You can catch this error and ignore it.

vettloffah avatar Jun 29 '22 12:06 vettloffah

Here is an example I did recently:

 let paymentId = 0;
 try{
        paymentId = await odoo.create("account.payment", payment);
        await odoo.execute_kw("account.payment", "action_post", [[paymentId]]);
        return paymentId;
    }catch(e){
        if(e instanceof Error){
            // Odoo returns an allow_none error, even if it successfully posts.
            // @ts-ignore
            if(e.faultString?.includes("cannot marshal None unless allow_none is enabled")){
                return paymentId;
            }
        }
        // otherwise it's an unknown error
        throw e;
    }

vettloffah avatar Jun 29 '22 12:06 vettloffah