-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] add cashbox suport to modules that use payment register
closes #514 Signed-off-by: Juan José Scarafía <jjs@adhoc.com.ar>
- Loading branch information
Showing
4 changed files
with
74 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
from . import account_cashbox_payment_import | ||
from . import account_payment_register |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |