diff --git a/account_usability/__manifest__.py b/account_usability/__manifest__.py index 83210c03..f5b89a9c 100644 --- a/account_usability/__manifest__.py +++ b/account_usability/__manifest__.py @@ -36,6 +36,7 @@ 'wizard/account_invoice_mark_sent_view.xml', 'wizard/account_group_generate_view.xml', 'wizard/account_payment_register_views.xml', + 'wizard/account_move_reversal.xml', 'security/ir.model.access.csv', 'report/invoice_report.xml', ], diff --git a/account_usability/i18n/account_usability.pot b/account_usability/i18n/account_usability.pot index 94784f5f..c76b7d82 100644 --- a/account_usability/i18n/account_usability.pot +++ b/account_usability/i18n/account_usability.pot @@ -21,6 +21,13 @@ msgid "" " generate account groups from scratch." msgstr "" +#. module: account_usability +#. odoo-python +#: code:addons/account_usability/wizard/account_move_reversal.py:0 +#, python-format +msgid "%s reversed by %s" +msgstr "" + #. module: account_usability #: model:ir.model,name:account_usability.model_account_account msgid "Account" @@ -679,6 +686,13 @@ msgstr "" msgid "View Journal Entry Form" msgstr "" +#. module: account_usability +#: model_terms:ir.ui.view,arch_db:account_usability.view_account_move_reversal +msgid "" +"You are about to reverse entries that have already been reversed or partially reversed (refund). Make sure it is intented.\n" +" Already reversed entries are the following :" +msgstr "" + #. module: account_usability #: model:ir.model.fields,help:account_usability.field_account_bank_statement__hide_bank_statement_balance #: model:ir.model.fields,help:account_usability.field_account_journal__hide_bank_statement_balance diff --git a/account_usability/i18n/fr.po b/account_usability/i18n/fr.po index e887d11c..194cb8f7 100644 --- a/account_usability/i18n/fr.po +++ b/account_usability/i18n/fr.po @@ -26,6 +26,14 @@ msgstr "" "%d des groupes de comptes existent déjà dans la société '%s'. Cet " "assistant est conçu pour créer des groupes de comptes à partir de zéro." +#. module: account_usability +#. odoo-python +#: code:addons/account_usability/wizard/account_move_reversal.py:0 +#, python-format +msgid "%s reversed by %s" +msgstr "%s extourné par %s" + + #. module: account_usability #: model:ir.model,name:account_usability.model_account_account msgid "Account" @@ -727,6 +735,14 @@ msgstr "Voir la pièce comptable" msgid "View Journal Entry Form" msgstr "Voir la pièce comptable en vue formulaire" +#. module: account_usability +#: model_terms:ir.ui.view,arch_db:account_usability.view_account_move_reversal +msgid "" +"You are about to reverse entries that have already been reversed or partially reversed (refund). Make sure it is intented.\n" +" Already reversed entries are the following :" +msgstr "Vous êtes sur le point d'extourner une pièce comptable déjà extournée, ou partiellement extournée (avoir). Vérifiez que c'est bien ce que vous souhaitez faire.\n" +" Les pièces comptables déjà extournées sont les suivantes :" + #. module: account_usability #: model:ir.model.fields,help:account_usability.field_account_bank_statement__hide_bank_statement_balance #: model:ir.model.fields,help:account_usability.field_account_journal__hide_bank_statement_balance diff --git a/account_usability/wizard/account_move_reversal.py b/account_usability/wizard/account_move_reversal.py index 21ade38d..fd419611 100644 --- a/account_usability/wizard/account_move_reversal.py +++ b/account_usability/wizard/account_move_reversal.py @@ -2,17 +2,32 @@ # @author: Alexis de Lattre # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import api, models, _ +from odoo import api, fields, models, _ from dateutil.relativedelta import relativedelta -from odoo.exceptions import UserError class AccountMoveReversal(models.TransientModel): _inherit = 'account.move.reversal' + already_reversed_warning = fields.Text(compute="_compute_already_reversed_warning") + + @api.depends("move_ids") + def _compute_already_reversed_warning(self): + for wizard in self: + moves = wizard.move_ids or self.env["account.move"].browse(self._context['active_ids']) + reversed_moves = self.env["account.move"].search([('reversed_entry_id', 'in', moves.ids)]) + warning = "" + for already_reversed_move in reversed_moves.reversed_entry_id: + if warning: + warning += "\n" + reversed_by = " ; ".join(already_reversed_move.reversal_move_id.mapped("display_name")) + move_detail = _("%s reversed by %s") % (already_reversed_move.display_name, reversed_by) + warning += move_detail + wizard.already_reversed_warning = warning or False + + # Set default reversal date to original move + 1 day # and raise error if original move has already been reversed - # WARNING: this wizard is also used to generate refunds @api.model def default_get(self, fields_list): res = super().default_get(fields_list) @@ -21,10 +36,4 @@ def default_get(self, fields_list): moves = amo.browse(self._context['active_ids']) if len(moves) == 1 and moves.move_type not in ('out_invoice', 'in_invoice'): res['date'] = moves.date + relativedelta(days=1) - reversed_move = amo.search([('reversed_entry_id', 'in', moves.ids)], limit=1) - if reversed_move: - raise UserError(_( - "Move '%s' has already been reversed by move '%s'.") % ( - reversed_move.reversed_entry_id.display_name, - reversed_move.display_name)) - return res + return res \ No newline at end of file diff --git a/account_usability/wizard/account_move_reversal.xml b/account_usability/wizard/account_move_reversal.xml new file mode 100644 index 00000000..e54b3b2a --- /dev/null +++ b/account_usability/wizard/account_move_reversal.xml @@ -0,0 +1,24 @@ + + + + + account.move.reversal + + + + + + + + + \ No newline at end of file diff --git a/sale_usability/models/account_move.py b/sale_usability/models/account_move.py index 04fcfeeb..ef5c201c 100644 --- a/sale_usability/models/account_move.py +++ b/sale_usability/models/account_move.py @@ -11,9 +11,9 @@ class AccountMove(models.Model): # sale_ids is kind of the symetric field of invoice_ids on sale.order sale_ids = fields.Many2many( - 'sale.order', string='Sale Orders', compute="_compute_sale_ids") + 'sale.order', string='Sale Orders', compute="_compute_sale_ids", store=True) sale_count = fields.Integer( - string='Sale Order Count', compute='_compute_sale_ids') + string='Sale Order Count', compute='_compute_sale_ids', store=True) @api.depends('invoice_line_ids.sale_line_ids') def _compute_sale_ids(self):