summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulien CHEVREAU (JCU) <jcu@odoo.com>2021-03-29 12:31:08 +0000
committerJulien CHEVREAU (JCU) <jcu@odoo.com>2021-04-09 14:27:22 +0000
commit80c28189ae6b10ad17c4de2a781233a8ffe663a6 (patch)
treee5586be9f62bf720da4a54f277166530673dad7a
parentf0a1bb3692e17334850fed4f22444f47992adb78 (diff)
[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#68837 X-original-commit: 71b82693bb6d62c659483d533be8d25905f3492f Related: odoo/enterprise#17511 Signed-off-by: oco-odoo <oco-odoo@users.noreply.github.com> Signed-off-by: Julien CHEVREAU <Julien-CHEVREAU@users.noreply.github.com>
-rw-r--r--addons/account/i18n/account.pot6
-rw-r--r--addons/account/models/account_bank_statement.py4
-rw-r--r--addons/account/models/account_move.py2
-rw-r--r--addons/account/tests/test_account_move_entry.py5
-rw-r--r--addons/delivery/tests/test_delivery_stock_move.py2
-rw-r--r--addons/point_of_sale/tests/test_point_of_sale_flow.py6
6 files changed, 18 insertions, 7 deletions
diff --git a/addons/account/i18n/account.pot b/addons/account/i18n/account.pot
index cea615b8b5a..521986c0a3f 100644
--- a/addons/account/i18n/account.pot
+++ b/addons/account/i18n/account.pot
@@ -13804,6 +13804,12 @@ 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
msgid "You need to add a line before posting."
msgstr ""
diff --git a/addons/account/models/account_bank_statement.py b/addons/account/models/account_bank_statement.py
index b345d02d605..8b27e6941ff 100644
--- a/addons/account/models/account_bank_statement.py
+++ b/addons/account/models/account_bank_statement.py
@@ -406,7 +406,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):
diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py
index b4d32f3371b..f44cfcc7140 100644
--- a/addons/account/models/account_move.py
+++ b/addons/account/models/account_move.py
@@ -2428,6 +2428,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):
diff --git a/addons/account/tests/test_account_move_entry.py b/addons/account/tests/test_account_move_entry.py
index 0251391c443..b97a968481f 100644
--- a/addons/account/tests/test_account_move_entry.py
+++ b/addons/account/tests/test_account_move_entry.py
@@ -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.journal_id.sequence_override_regex = r'^(?P<seq>\d*)(?P<suffix1>.*?)(?P<year>(\d{4})?)(?P<suffix2>)$'
- next.name = '/'
+ 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.action_post()
self.assertEqual(next.name, '00000877-G 0002/2020') # Pfew, better!
next = self.test_move.copy({'date': self.test_move.date})
diff --git a/addons/delivery/tests/test_delivery_stock_move.py b/addons/delivery/tests/test_delivery_stock_move.py
index dff96b036a1..a9d5b7d5be7 100644
--- a/addons/delivery/tests/test_delivery_stock_move.py
+++ b/addons/delivery/tests/test_delivery_stock_move.py
@@ -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({
diff --git a/addons/point_of_sale/tests/test_point_of_sale_flow.py b/addons/point_of_sale/tests/test_point_of_sale_flow.py
index 04b9b952725..2c9e8c59584 100644
--- a/addons/point_of_sale/tests/test_point_of_sale_flow.py
+++ b/addons/point_of_sale/tests/test_point_of_sale_flow.py
@@ -463,7 +463,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")
@@ -845,7 +846,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")