mirror of
https://github.com/OCA/account-financial-tools.git
synced 2025-02-02 12:47:26 +02:00
[IMP] Remove unneeded bare commits to respect transactions
This commit is contained in:
committed by
Iryna Vushnevska
parent
4380d982e5
commit
fa6a0afa2e
@@ -3,7 +3,7 @@
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
{
|
||||
'name': "Account Move Batch Validate",
|
||||
'version': '11.0.1.0.0',
|
||||
'version': '11.0.1.0.1',
|
||||
'author': "Camptocamp, Odoo Community Association (OCA)",
|
||||
'website': 'https://github.com/OCA/account-financial-tools',
|
||||
'category': 'Finance',
|
||||
|
||||
@@ -22,13 +22,14 @@ class AccountMove(models.Model):
|
||||
help="Check this box to mark the move for batch posting")
|
||||
post_job_uuid = fields.Char(string="UUID of the Job to approve this move")
|
||||
|
||||
@api.multi
|
||||
@job(default_channel='root.account_move_batch_validate')
|
||||
def validate_one_move(self, move_id):
|
||||
move = self.browse(move_id)
|
||||
if move.exists():
|
||||
move.post()
|
||||
def validate_one_move(self):
|
||||
if self.exists():
|
||||
self.post()
|
||||
return _("Move has been posted successfully.")
|
||||
else:
|
||||
return _("Nothing to do because the record has been deleted")
|
||||
return _("Nothing to do because the record has been deleted.")
|
||||
|
||||
@api.model
|
||||
def _delay_post_marked(self, eta=None):
|
||||
@@ -36,27 +37,30 @@ class AccountMove(models.Model):
|
||||
Create a job for every move marked for posting.
|
||||
If some moves already have a job, they are skipped.
|
||||
"""
|
||||
AccountMoveObj = self.env[self._name]
|
||||
|
||||
moves = self.search([
|
||||
('to_post', '=', True),
|
||||
('post_job_uuid', '=', False),
|
||||
('state', '=', 'draft'),
|
||||
])
|
||||
|
||||
# maybe not creating too many dictionaries will make us a bit faster
|
||||
values = {'post_job_uuid': None}
|
||||
moves_job_mapping = []
|
||||
_logger.info(
|
||||
"%s jobs for posting moves have been created.", len(moves))
|
||||
"Creating %s jobs for posting moves.", len(moves))
|
||||
|
||||
for move in moves:
|
||||
new_job = AccountMoveObj.with_delay(eta=eta).validate_one_move(
|
||||
move.id)
|
||||
values['post_job_uuid'] = new_job.uuid
|
||||
move.write(values)
|
||||
# Explicit committing is done for the capability of tracking
|
||||
# created jobs in live, during creation process
|
||||
self.env.cr.commit() # pylint:disable=invalid-commit
|
||||
job = move.with_delay(eta=eta).validate_one_move()
|
||||
moves_job_mapping.append((move.id, job.uuid))
|
||||
self._update_moves_with_job_uuid(moves_job_mapping)
|
||||
|
||||
@api.model
|
||||
def _update_moves_with_job_uuid(self, moves_job_mapping):
|
||||
sql = """
|
||||
UPDATE account_move AS am
|
||||
SET post_job_uuid = v.job_uuid
|
||||
FROM (VALUES %s ) AS v (move_id, job_uuid)
|
||||
WHERE am.id = v.move_id;
|
||||
"""
|
||||
self.env.cr.execute(sql, tuple(moves_job_mapping))
|
||||
|
||||
@api.model
|
||||
def _cancel_post_jobs(self):
|
||||
@@ -88,15 +92,7 @@ class AccountMove(models.Model):
|
||||
moves_count = len(self)
|
||||
_logger.info("%s moves marked for posting.", moves_count)
|
||||
|
||||
values = {'to_post': True}
|
||||
|
||||
for index in range(0, moves_count, BLOCK_SIZE):
|
||||
moves = self[index:index + BLOCK_SIZE]
|
||||
moves.write(values)
|
||||
# Explicit committing is done for the capability of tracking
|
||||
# created jobs in live, during creation process
|
||||
# users like to see the flag sooner rather than later
|
||||
self.env.cr.commit() # pylint:disable=invalid-commit
|
||||
self.write({'to_post': True})
|
||||
self._delay_post_marked(eta=eta)
|
||||
|
||||
@api.multi
|
||||
|
||||
@@ -30,7 +30,7 @@ class TestAccountMoveBatchValidate(SingleTransactionCase):
|
||||
})
|
||||
self.account_sale = self.AccountObj.create({
|
||||
'code': 'SALET',
|
||||
'name': "Receivable (sale)",
|
||||
'name': "Revenue (sale)",
|
||||
'reconcile': True,
|
||||
'user_type_id': self.account_type_rev.id,
|
||||
})
|
||||
@@ -81,12 +81,11 @@ class TestAccountMoveBatchValidate(SingleTransactionCase):
|
||||
'active_ids': [move.id],
|
||||
'automated_test_execute_now': True,
|
||||
}).validate_move()
|
||||
|
||||
move.invalidate_cache()
|
||||
job_uuid = move.post_job_uuid
|
||||
|
||||
self.assertTrue(
|
||||
move.to_post, msg="Move should be marked as 'to post'.")
|
||||
|
||||
self.assertTrue(
|
||||
bool(job_uuid), msg="A job should have been assigned to the move.")
|
||||
|
||||
@@ -108,7 +107,7 @@ class TestAccountMoveBatchValidate(SingleTransactionCase):
|
||||
'active_ids': [move.id],
|
||||
'automated_test_execute_now': True,
|
||||
}).validate_move()
|
||||
|
||||
move.invalidate_cache()
|
||||
job_uuid = move.post_job_uuid
|
||||
|
||||
self.assertTrue(
|
||||
@@ -121,7 +120,7 @@ class TestAccountMoveBatchValidate(SingleTransactionCase):
|
||||
|
||||
self.assertEqual(
|
||||
post_job.result,
|
||||
'Nothing to do because the record has been deleted')
|
||||
'Nothing to do because the record has been deleted.')
|
||||
|
||||
def test_03_mark_and_unmark(self):
|
||||
"""
|
||||
@@ -135,7 +134,7 @@ class TestAccountMoveBatchValidate(SingleTransactionCase):
|
||||
'active_ids': [move.id],
|
||||
'automated_test_execute_now': True,
|
||||
}).validate_move()
|
||||
|
||||
move.invalidate_cache()
|
||||
mark_job_uuid = move.post_job_uuid
|
||||
|
||||
self.assertTrue(move.to_post)
|
||||
|
||||
Reference in New Issue
Block a user