access statement from payment

16-gn-cash-refactor
Florian Roger 2 months ago
parent 0fb063da14
commit 932dcff807

@ -21,7 +21,7 @@ It is based on modules:
- [x] loss/profit validation
- [x] use predefined cash units
- [x] sequencing on statement gen
- [] add button on payment to access statement if is_matched
- [x] add button on payment to access statement if is_matched
- [] check all reconciled before closing loss/profit
- [] What to do when statement line generated has no label
- [] report cashbox to next statement

@ -1,6 +1,6 @@
{
'name': "Gn Cash",
'version': '16.0.0.0.4',
'version': '16.0.0.0.5',
'author': 'Garage Numérique',
'category': 'Accounting',
'description': """
@ -15,6 +15,7 @@
'views/account_journal_ConfigForm_view.xml',
'views/account_cash_statement_views.xml',
'views/account_journal_dashboard_view.xml',
'views/account_payment_views.xml',
],
'translate': True,
'installable': True,

@ -1,3 +1,3 @@
# -*- coding: utf-8 -*-
from . import cash_statement, account_journal_dashboard
from . import cash_statement, account_journal_dashboard, account_payment

@ -0,0 +1,47 @@
from odoo import models, api, _, fields
from odoo.exceptions import ValidationError
import logging
_logger = logging.getLogger(__name__)
class AccountPayment(models.Model):
_inherit = "account.payment"
reconciled_statement_ids = fields.Many2many(
comodel_name='account.bank.statement',
string="Reconciled Statements",
compute='_compute_stat_statement_button',
help="Statements matched to this payment",
)
reconciled_statement_count = fields.Integer(
string="# Reconciled Statement",
compute="_compute_stat_statement_button",
)
@api.depends('reconciled_statement_line_ids')
def _compute_stat_statement_button(self):
for pay in self:
#statement_ids = { line.statement_id.id for line in pay.reconciled_statement_line_ids }
statement_ids = {line.statement_id.id for line in pay.reconciled_statement_line_ids if line.statement_id}
pay.reconciled_statement_ids = [(6, 0, list(statement_ids))]
pay.reconciled_statement_count = len(statement_ids)
def button_open_statements(self):
self.ensure_one()
action = {
'name': _("Statements"),
'type': 'ir.actions.act_window',
'res_model': 'account.bank.statement',
'context': {'create': False, 'journal_type': 'cash'},
}
if len(self.reconciled_statement_ids) == 1:
action.update({
'views': [[self.env.ref('gn_cash.view_cash_statement_form').id, "form"]],
'res_id': self.reconciled_statement_ids.id,
})
else:
action.update({
'views': [[False, "list"], [self.env.ref('gn_cash.view_cash_statement_form').id, "form"]],
'domain': [('id', 'in', self.reconciled_statement_ids.ids)],
})
return action

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<record id="gn_cash.view_account_payment_form" model="ir.ui.view">
<field name="name">gn_cash.account.payment.form</field>
<field name="inherit_id" ref="account.view_account_payment_form"/>
<field name="model">account.payment</field>
<field name="priority">100</field>
<field name="arch" type="xml">
<xpath expr="//button[@name='button_open_statement_lines']" position="before">
<button name="button_open_statements" type="object" class="oe_stat_button" icon="fa-bars" attrs="{'invisible': [('is_matched','=', False)]}">
<div class="o_form_field o_stat_info">
<field name="reconciled_statement_count"/>
<span> Relevé</span>
</div>
</button>
</xpath>
</field>
</record>
</data>
</odoo>
Loading…
Cancel
Save