From 242946c249cc19b7a206a8f2d67af581563298ae Mon Sep 17 00:00:00 2001 From: Martin Quinteros Date: Mon, 5 Aug 2024 19:29:21 +0000 Subject: [PATCH] [IMP] add cashbox suport to modules that use payment register MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit closes ingadhoc/account-payment#514 Signed-off-by: Juan José Scarafía --- account_cashbox/__manifest__.py | 3 +- account_cashbox/wizards/__init__.py | 1 + .../wizards/account_payment_register.py | 51 +++++++++++++++++++ .../wizards/account_payment_register.xml | 20 ++++++++ 4 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 account_cashbox/wizards/account_payment_register.py create mode 100644 account_cashbox/wizards/account_payment_register.xml diff --git a/account_cashbox/__manifest__.py b/account_cashbox/__manifest__.py index 73ca4f92a..b9914af04 100755 --- a/account_cashbox/__manifest__.py +++ b/account_cashbox/__manifest__.py @@ -4,7 +4,7 @@ { "name": "Cashbox management", "summary": "Introduces concept cashbox and accounting journal sessions", - "version": "16.0.1.3.1", + "version": "16.0.1.4.0", "category": "Accounting", "website": "www.adhoc.com.ar", "author": "juanpgarza, ADHOC SA", @@ -28,6 +28,7 @@ 'views/account_payment.xml', 'views/menuitem.xml', 'wizards/account_cashbox_payment_import.xml', + 'wizards/account_payment_register.xml', ], "installable": True, "application": False, diff --git a/account_cashbox/wizards/__init__.py b/account_cashbox/wizards/__init__.py index 576b6cd48..e69d05ecc 100644 --- a/account_cashbox/wizards/__init__.py +++ b/account_cashbox/wizards/__init__.py @@ -1 +1,2 @@ from . import account_cashbox_payment_import +from . import account_payment_register diff --git a/account_cashbox/wizards/account_payment_register.py b/account_cashbox/wizards/account_payment_register.py new file mode 100644 index 000000000..a7fdf06da --- /dev/null +++ b/account_cashbox/wizards/account_payment_register.py @@ -0,0 +1,51 @@ +from odoo import models, api, fields, _ + + +class AccountPaymentRegister(models.TransientModel): + """ + Si bien cashbox depende de account_payment_group y deshabilitamos los wizards de pago + Modulos como hr_expenses continuan utilizando el wizard. por eso agregamos la logica de + las seciones de caja tambien al wizard + """ + + _inherit = 'account.payment.register' + + cashbox_session_id = fields.Many2one( + 'account.cashbox.session', + string='POP Session', + compute="_compute_cashbox_session_id", + readonly=False, + store=True + ) + requiere_account_cashbox_session = fields.Boolean( + compute='_compute_requiere_account_cashbox_session', + compute_sudo=False, + ) + + @api.depends_context('uid') + # dummy depends para que se compute(no estamos seguros porque solo con el depends_context no computa) + @api.depends('journal_id') + def _compute_requiere_account_cashbox_session(self): + self.requiere_account_cashbox_session = self.env.user.requiere_account_cashbox_session + + def _compute_cashbox_session_id(self): + for rec in self: + session_ids = self.env['account.cashbox.session'].search([ + ('state', '=', 'opened'), + '|', + ('user_ids', '=', self.env.uid), + ('user_ids', '=', False) + ]) + if len(session_ids) == 1: + rec.cashbox_session_id = session_ids.id + else: + rec.cashbox_session_id = False + + @api.depends('payment_type', 'cashbox_session_id') + def _compute_available_journal_ids(self): + super()._compute_available_journal_ids() + for pay in self.filtered('cashbox_session_id'): + # hacemos dominio sobre los line_ids y no los diarios del pop config porque + # puede ser que sea una sesion vieja y que el setting pop config cambie + pay.available_journal_ids = pay.available_journal_ids._origin.filtered( + lambda x: x in pay.cashbox_session_id.line_ids.mapped('journal_id')) diff --git a/account_cashbox/wizards/account_payment_register.xml b/account_cashbox/wizards/account_payment_register.xml new file mode 100644 index 000000000..baffd3055 --- /dev/null +++ b/account_cashbox/wizards/account_payment_register.xml @@ -0,0 +1,20 @@ + + + + account.payment.register.form + account.payment.register + + + + + + + + + + +