diff --git a/account_batch_payment_ux/README.rst b/account_batch_payment_ux/README.rst new file mode 100644 index 00000000..3fa69738 --- /dev/null +++ b/account_batch_payment_ux/README.rst @@ -0,0 +1,65 @@ +.. |company| replace:: ADHOC SA + +.. |company_logo| image:: https://raw.githubusercontent.com/ingadhoc/maintainer-tools/master/resources/adhoc-logo.png + :alt: ADHOC SA + :target: https://www.adhoc.com.ar + +.. |icon| image:: https://raw.githubusercontent.com/ingadhoc/maintainer-tools/master/resources/adhoc-icon.png + +.. image:: https://img.shields.io/badge/license-AGPL--3-blue.png + :target: https://www.gnu.org/licenses/agpl + :alt: License: AGPL-3 + +===================== +Accounting Reports UX +===================== +This module adds validations on batch payment operations: + +#. Restrict unlink payments linked to the batch payment if the batch is not on draft state. +#. Restrict delete an account batch payment if it's not on draft state. +#. Restrict set batch payments to draft if any associated payment line is reconciled. + +Installation +============ + +To install this module, you need to: + +#. Only need to install the module + +Configuration +============= + +To configure this module, you need to: + +#. Nothing to configure + +Usage +===== + +To use this module, you need to: + +#. Go to ... + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: http://runbot.adhoc.com.ar/ + +Credits +======= + +Images +------ + +* |company| |icon| + +Contributors +------------ + +Maintainer +---------- + +|company_logo| + +This module is maintained by the |company|. + +To contribute to this module, please visit https://www.adhoc.com.ar. diff --git a/account_batch_payment_ux/__init__.py b/account_batch_payment_ux/__init__.py new file mode 100644 index 00000000..d0337769 --- /dev/null +++ b/account_batch_payment_ux/__init__.py @@ -0,0 +1,5 @@ +############################################################################## +# For copyright and license notices, see __manifest__.py file in module root +# directory +############################################################################## +from . import models diff --git a/account_batch_payment_ux/__manifest__.py b/account_batch_payment_ux/__manifest__.py new file mode 100644 index 00000000..4b0b2c77 --- /dev/null +++ b/account_batch_payment_ux/__manifest__.py @@ -0,0 +1,42 @@ +############################################################################## +# +# Copyright (C) 2024 ADHOC SA (http://www.adhoc.com.ar) +# All Rights Reserved. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +{ + 'name': 'Account Batch Payment UX', + 'version': "17.0.0.1.0", + 'category': 'Accounting', + 'sequence': 14, + 'summary': '', + 'author': 'ADHOC SA', + 'website': 'www.adhoc.com.ar', + 'license': 'AGPL-3', + 'images': [ + ], + 'depends': [ + 'account_batch_payment', + ], + 'data': [ + 'views/account_batch_payment.xml', + ], + 'demo': [ + ], + 'installable': True, + 'auto_install': True, + 'application': False, +} diff --git a/account_batch_payment_ux/models/__init__.py b/account_batch_payment_ux/models/__init__.py new file mode 100644 index 00000000..295c8d91 --- /dev/null +++ b/account_batch_payment_ux/models/__init__.py @@ -0,0 +1,5 @@ +############################################################################## +# For copyright and license notices, see __manifest__.py file in module root +# directory +############################################################################## +from . import account_batch_payment diff --git a/account_batch_payment_ux/models/account_batch_payment.py b/account_batch_payment_ux/models/account_batch_payment.py new file mode 100644 index 00000000..962ed3be --- /dev/null +++ b/account_batch_payment_ux/models/account_batch_payment.py @@ -0,0 +1,41 @@ +from odoo import models, fields, api, _ +from odoo.exceptions import UserError, RedirectWarning + + +class AccountBatchPayment(models.Model): + _inherit = 'account.batch.payment' + + @api.depends('payment_ids') + def verify_unlinked_payments_from_batch(self): + """donĀ“t allow to unlink payments linked to the batch payment if the batch is not on draft state""" + if (self._origin.filtered(lambda x: x.state != 'draft') and len(self._origin.payment_ids) != len(self.payment_ids)): + raise UserError(_("You are not allowed to delete payments from a batch payment if the batch is not on draft state.")) + + def unlink(self): + """This method don't allow to delete an account batch payment if it's not on draft state""" + if self.filtered(lambda x: x.state != 'draft'): + raise UserError(_("You are not allowed to delete a batch payment if is not on draft state.")) + return super().unlink() + + def action_draft(self): + """Only sent batch payments can be changed to draft state""" + matched_entries = self.payment_ids.filtered('is_matched') + if matched_entries: + error_msg = ("The following payments are reconciled and cannot be reset to draft state: \n") + for entry in matched_entries: + error_msg += f"{entry.name} \n" + action_error = { + 'view_mode': 'tree', + 'name': _('Matched Entries'), + 'res_model': 'account.bank.statement.line', + 'type': 'ir.actions.act_window', + 'domain': [('id', 'in', matched_entries.mapped('reconciled_statement_line_ids').ids)], + 'views': [ + (self.env.ref('account_accountant.view_bank_statement_line_kanban_bank_rec_widget').id, 'kanban'), + (self.env.ref('account_accountant.view_bank_statement_line_tree_bank_rec_widget').id, 'list'), + ] + } + raise RedirectWarning(error_msg, action_error, _('Show matched entries')) + + self.payment_ids.is_move_sent = False + self.write({'state': 'draft'}) diff --git a/account_batch_payment_ux/views/account_batch_payment.xml b/account_batch_payment_ux/views/account_batch_payment.xml new file mode 100644 index 00000000..3a9a4099 --- /dev/null +++ b/account_batch_payment_ux/views/account_batch_payment.xml @@ -0,0 +1,15 @@ + + + + + account.batch.payment.form.inherit + account.batch.payment + + + + + + +