This is in Odoo V13 enterprise.
I have a scheduled action that gets data from Customer Invoices and then creates a new invoice based off of that data. We have multiple companies in our Odoo database and I would like the scheduled action to run for each of the companies, what is the best way to do this?
Example of what I have so far:
For some reason the new invoices can be seen from all the companies and will error if it is opened from the wrong company even though it is visible.
for company in self.env["res.company"].search([]):
# Find all the invoices from the last month
monthly_invoices = (
self.with_context(force_company=company.id)
.env["account.move"]
.sudo()
.search(
[
...
("company_id.id", "=", company.id),
]
)
)
groups = ...
# Create the new invoices from the groups
for customer, invoices in groups.items():
if invoices: # Must have invoices
new_invoice = (
self.with_context(force_company=company.id)
.env["account.move"]
.sudo()
.create(
{
...
"company_id": company.id,
}
)
)
Hint: http://learnopenerp.blogspot.com/2020/05/how-to-create-scheduled-action-in-odoo.html
That does not help with my issue, this is code already run by a scheduled action. My issue isn't that I don't know how to create a scheduled action but I don't know the best way for a scheduled action to affect records in multiple companies cleanly.