diff --git a/addons/account/i18n/account.pot b/addons/account/i18n/account.pot index 1d26e39b823..73c99b50d46 100644 --- a/addons/account/i18n/account.pot +++ b/addons/account/i18n/account.pot @@ -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 diff --git a/addons/account/models/account_bank_statement.py b/addons/account/models/account_bank_statement.py index b300992fbe0..644bff3987b 100644 --- a/addons/account/models/account_bank_statement.py +++ b/addons/account/models/account_bank_statement.py @@ -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): diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index f1054cc1073..3b9ac529ba8 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -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): diff --git a/addons/account/tests/test_account_move_entry.py b/addons/account/tests/test_account_move_entry.py index 450636444aa..e633d218d78 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.button_draft() + next.name = False next.journal_id.sequence_override_regex = r'^(?P\d*)(?P.*?)(?P(\d{4})?)(?P)$' - 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}) 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 f8cc739505c..66dda6b08de 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 @@ -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")