This question has been flagged
1 Reply
1783 Views

Hi There,


I'm trying to get all the invoices that are in the accounting of two companies (CompanyXYZ Inc. and CompanyXYZ SA). In the UI, I do have first to select the company and then navigate to the Accounting module and select the Sales book (landing in the model account.invoice).


In my python code, when I submit the following code:

models.execute_kw(db, uid, password, 'account.invoice, 'search_read', {}

I either get the list of invoices belonging to the INC or to the SA but not both. Also, I noticed that I get the list from company I last logged in in the web interface. (Say I log in and select "Company Inc", and then I run my python code, I'll get the invoices from the INC. If I then switch the SA, and run the same Python code again, then I'll get the invoices from the SA.


What am I missing? Is there a way to provide a parameter in the XMLRPC request to indicate which company I'm connecting to?


Thanks,

François

Avatar
Discard

Which Odoo version ?

Author

Thanks for your response Alessandro. It makes total sense. I tried the following ro update the company: models.execute_kw(db, uid, password, 'res.partner', 'write', [[1786],{'company_id','=',[1,'Company XYZ SA']}]) but got the following error message: TypeError: unhashable type: 'list' Not sure what I'm doing wrong but it looks like companyId is a list

Author

Please ignore my previous comment. Thank you SO much Alessandro! The correct syntax to switch companies is: models.execute_kw(db, uid, password, 'res.users', 'write', [[uid],{'company_id':1}])

Author

Version 12

Best Answer

You can first call the write method on the res.users model for the uid used for the connection writing in the company_id field the id of the company you want to work with in subsequent methods.

This is the same operation that the web ui does when changing the active company .

Avatar
Discard