Skip to content

Commit

Permalink
[IMP] add cashbox suport to modules that use payment register
Browse files Browse the repository at this point in the history
closes #514

Signed-off-by: Juan José Scarafía <jjs@adhoc.com.ar>
  • Loading branch information
maq-adhoc committed Aug 7, 2024
1 parent ed71de6 commit 242946c
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 1 deletion.
3 changes: 2 additions & 1 deletion account_cashbox/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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,
Expand Down
1 change: 1 addition & 0 deletions account_cashbox/wizards/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from . import account_cashbox_payment_import
from . import account_payment_register
51 changes: 51 additions & 0 deletions account_cashbox/wizards/account_payment_register.py
Original file line number Diff line number Diff line change
@@ -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'))
20 changes: 20 additions & 0 deletions account_cashbox/wizards/account_payment_register.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="view_account_payment_register_form" model="ir.ui.view">
<field name="name">account.payment.register.form</field>
<field name="model">account.payment.register</field>
<field name="inherit_id" ref="account.view_account_payment_register_form"/>
<field name="arch" type="xml">
<field name="journal_id" position="before">
<field name="requiere_account_cashbox_session" invisible="1"/>
<!-- filtramos por usuario para que a los admin solo les aparezcan en donde estan involucrados. Total siendo admin se pueden agregar en la que quieran -->
<field
name="cashbox_session_id"
domain="[('state', '=', 'opened'), ('company_id', '=', company_id), '|', ('user_ids', '=', uid), ('user_ids', '=', False)]"
attrs="{'required': [('requiere_account_cashbox_session', '=', True)]}"
/>
</field>

</field>
</record>
</odoo>

0 comments on commit 242946c

Please sign in to comment.