Skip to content

Commit

Permalink
temp rebasing PR 369 (a1943f7)
Browse files Browse the repository at this point in the history
  • Loading branch information
roboadhoc committed Apr 24, 2024
2 parents 07427df + a1943f7 commit b67bf6a
Show file tree
Hide file tree
Showing 6 changed files with 173 additions and 0 deletions.
65 changes: 65 additions & 0 deletions 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.
5 changes: 5 additions & 0 deletions 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
42 changes: 42 additions & 0 deletions 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
{
'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,
}
5 changes: 5 additions & 0 deletions 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
41 changes: 41 additions & 0 deletions 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'})
15 changes: 15 additions & 0 deletions account_batch_payment_ux/views/account_batch_payment.xml
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>

<record id="view_batch_payment_form_inherit" model="ir.ui.view">
<field name="name">account.batch.payment.form.inherit</field>
<field name="model">account.batch.payment</field>
<field name="inherit_id" ref="account_batch_payment.view_batch_payment_form"/>
<field name="arch" type="xml">
<button name="print_batch_payment" position="after">
<button name="action_draft" class="btn btn-secondary" confirm="Payments will be returned to draft and marked as unsent and unreconciled." data-hotkey="w" string="Reset To Draft" type='object' invisible="state != 'sent'"/>
</button>
</field>
</record>

</odoo>

0 comments on commit b67bf6a

Please sign in to comment.