[FIX] account: correctly use job count on cron
The cron "send invoices automatically" was not properly using the job_count parameter because the to_process invoices were now pulled from a read_group. The limit parameter on read_group only limits the number of groups and it was being grouped by company. This meant if there was less than job_count number of companies this was not doing anything. And if one company had a large amount of invoices this would time out and repeat the same invoices the next time it was attempted because no progress is saved until the batch is over. Changing the read_group to a search. opw-3765192 Part-of: odoo/odoo#158035
This commit is contained in:
committed by
Claire Bretton (clbr)
parent
6efbcae063
commit
d11d4081bc
@@ -4254,17 +4254,16 @@ class AccountMove(models.Model):
|
||||
]
|
||||
|
||||
limit = job_count + 1
|
||||
to_process = self.env['account.move']._read_group(
|
||||
to_process = self.env['account.move'].search(
|
||||
[('send_and_print_values', '!=', False)],
|
||||
groupby=['company_id'],
|
||||
aggregates=['id:recordset'],
|
||||
limit=limit,
|
||||
)
|
||||
need_retrigger = len(to_process) > job_count
|
||||
if not to_process:
|
||||
return
|
||||
|
||||
for _company, moves in to_process[:job_count]:
|
||||
all_moves = to_process[:job_count]
|
||||
for _company, moves in all_moves.grouped('company_id').items():
|
||||
try:
|
||||
# Lock moves
|
||||
with self.env.cr.savepoint(flush=False):
|
||||
|
||||
@@ -1039,16 +1039,18 @@ class TestAccountMoveSend(TestAccountMoveSendCommon):
|
||||
order='id desc',
|
||||
limit=1,
|
||||
)
|
||||
self.assertEqual(json.loads(bus_1.message)['payload']['type'], 'success')
|
||||
self.assertEqual(json.loads(bus_1.message)['payload']['action_button']['res_ids'], invoices_success.ids)
|
||||
payload_1 = json.loads(bus_1.message)['payload']
|
||||
self.assertEqual(payload_1['type'], 'success')
|
||||
self.assertEqual(sorted(payload_1['action_button']['res_ids']), invoices_success.ids)
|
||||
|
||||
bus_2 = self.env['bus.bus'].sudo().search(
|
||||
[('channel', 'like', f'"res.partner",{sp_partner_2.id}')],
|
||||
order='id desc',
|
||||
limit=1,
|
||||
)
|
||||
self.assertEqual(json.loads(bus_2.message)['payload']['type'], 'warning')
|
||||
self.assertEqual(json.loads(bus_2.message)['payload']['action_button']['res_ids'], invoices_error.ids)
|
||||
payload_2 = json.loads(bus_2.message)['payload']
|
||||
self.assertEqual(payload_2['type'], 'warning')
|
||||
self.assertEqual(sorted(payload_2['action_button']['res_ids']), invoices_error.ids)
|
||||
|
||||
def test_send_and_print_only(self):
|
||||
invoice = self.init_invoice("out_invoice", amounts=[1000], post=True)
|
||||
|
||||
Reference in New Issue
Block a user