[FIX] account: Check Move Status Before Posting

Beforehand, if two users independently opened a draft
invoice on their respective sessions, then both of them
clicked on the "Post" button, then the invoice was
posted twice.
On a more general aspect, the view currently "prevents" users
from posting moves several times, but technically speaking,
nothing stops users from posting moves several times.

Now, after checking that the user indeed has the right to post
a move, the next check is about verifying that the move is
not already posted.

opw-2479201

closes odoo/odoo#69178

X-original-commit: b7db7db283d7b9d167201b791e6282b022d59c40
Related: odoo/enterprise#17658
Signed-off-by: oco-odoo <oco-odoo@users.noreply.github.com>
Signed-off-by: Julien CHEVREAU <Julien-CHEVREAU@users.noreply.github.com>
This commit is contained in:
Julien CHEVREAU (JCU)
2021-04-14 08:37:32 +00:00
parent fcdbb3c2f8
commit 0cf8df4f3f
6 changed files with 17 additions and 6 deletions
+6
View File
@@ -13861,6 +13861,12 @@ msgid ""
"journal."
msgstr ""
#. module: account
#: code:addons/account/models/account_move.py:0
#, python-format
msgid "The entry %s (id %s) is already posted."
msgstr ""
#. module: account
#: code:addons/account/models/account_move.py:0
#, python-format
@@ -410,7 +410,9 @@ class AccountBankStatement(models.Model):
statement._set_next_sequence()
self.write({'state': 'posted'})
self.line_ids.move_id._post(soft=False)
lines_of_moves_to_post = self.line_ids.filtered(lambda line: line.move_id.state != 'posted')
if lines_of_moves_to_post:
lines_of_moves_to_post.move_id._post(soft=False)
def button_validate(self):
if any(statement.state != 'posted' or not statement.all_lines_reconciled for statement in self):
+2
View File
@@ -2490,6 +2490,8 @@ class AccountMove(models.Model):
if not self.env.su and not self.env.user.has_group('account.group_account_invoice'):
raise AccessError(_("You don't have the access rights to post an invoice."))
for move in to_post:
if move.state == 'posted':
raise UserError(_('The entry %s (id %s) is already posted.') % (move.name, move.id))
if not move.line_ids.filtered(lambda line: not line.display_type):
raise UserError(_('You need to add a line before posting.'))
if move.auto_post and move.date > fields.Date.context_today(self):
@@ -511,8 +511,9 @@ class TestAccountMove(AccountTestInvoicingCommon):
next.action_post()
self.assertEqual(next.name, '00000876-G 0002/2021') # Wait, I didn't want this!
next.button_draft()
next.name = False
next.journal_id.sequence_override_regex = r'^(?P<seq>\d*)(?P<suffix1>.*?)(?P<year>(\d{4})?)(?P<suffix2>)$'
next.name = '/'
next.action_post()
self.assertEqual(next.name, '00000877-G 0002/2020') # Pfew, better!
next = self.test_move.copy({'date': self.test_move.date})
@@ -79,8 +79,6 @@ class StockMoveInvoice(AccountTestInvoicingCommon):
self.invoice.action_post()
# I pay the invoice.
self.invoice = self.sale_prepaid.invoice_ids
self.invoice.action_post()
self.journal = self.AccountJournal.search([('type', '=', 'cash'), ('company_id', '=', self.sale_prepaid.company_id.id)], limit=1)
register_payments = self.env['account.payment.register'].with_context(active_model='account.move', active_ids=self.invoice.ids).create({
@@ -450,7 +450,8 @@ class TestPointOfSaleFlow(TestPointOfSaleCommon):
# I test that the total of the attached invoice is correct
invoice = self.env['account.move'].browse(res['res_id'])
invoice.action_post()
if invoice.state != 'posted':
invoice.action_post()
self.assertAlmostEqual(
invoice.amount_total, self.pos_order_pos1.amount_total, places=2, msg="Invoice not correct")
@@ -832,7 +833,8 @@ class TestPointOfSaleFlow(TestPointOfSaleCommon):
# I test that the total of the attached invoice is correct
invoice = self.env['account.move'].browse(res['res_id'])
invoice.action_post()
if invoice.state != 'posted':
invoice.action_post()
self.assertAlmostEqual(
invoice.amount_total, self.pos_order_pos1.amount_total, places=2, msg="Invoice not correct")