Skip to content

Commit

Permalink
[IMP] Filter accounts in cashflow report
Browse files Browse the repository at this point in the history
  • Loading branch information
marinaGD committed Jul 25, 2019
1 parent 670aa5c commit c2bc9ac
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
19 changes: 16 additions & 3 deletions account_cash_flow/models/cash_flow_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,22 @@ def _compute_final_amount(self):
"account.cash.flow.line", "cashflow_id",
string=u"Cash Flow Lines")

selected_account_ids = fields.Many2many(
'account.account', string="Contas Contábeis")

@api.multi
def draw_chart(self):
import plotly.graph_objs as go
from plotly.offline.offline import _plot_html
import pandas as pd

diarios = []
bancos = self.line_ids.filtered(lambda x: x.liquidity)
if self.selected_account_ids:
bancos = self.line_ids.filtered(
lambda x: x.liquidity and
x.id in self.selected_account_ids.ids)
else:
bancos = self.line_ids.filtered(lambda x: x.liquidity)
for item in bancos:
diarios.append((item.amount, item.name))

Expand Down Expand Up @@ -146,8 +154,13 @@ def draw_chart(self):

@api.multi
def calculate_liquidity(self):
accs = self.env['account.account'].search(
[('user_type_id.type', '=', 'liquidity')])
if self.selected_account_ids:
accs = self.env['account.account'].search(
[('id', 'in', self.selected_account_ids.ids)]
)
else:
accs = self.env['account.account'].search(
[('user_type_id.type', '=', 'liquidity')])
liquidity_lines = []
for acc in accs:
self.env.cr.execute(
Expand Down
7 changes: 6 additions & 1 deletion account_cash_flow/wizard/cash_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@ class CashFlowWizard(models.TransientModel):
digits=dp.get_precision('Account'))
print_report = fields.Boolean(string="Imprimir")
ignore_outstanding = fields.Boolean(string="Ignorar Vencidos?")
selected_account_ids = fields.Many2many(
'account.account', string="Contas Contábeis",
domain= [('user_type_id.type', '=', 'liquidity')])

@api.multi
def button_calculate(self):
cashflow_id = self.env['account.cash.flow'].create({
'end_date': self.end_date,
'start_amount': self.start_amount,
'ignore_outstanding': self.ignore_outstanding,
'selected_account_ids': [(6, False, self.selected_account_ids.ids)]
})
cashflow_id.action_calculate_report()

Expand All @@ -34,6 +38,7 @@ def button_calculate(self):
dummy, action_id = self.env['ir.model.data'].get_object_reference(
'account_cash_flow', 'account_cash_flow_report_action')
vals = self.env['ir.actions.act_window'].browse(action_id).read()[0]
vals['domain'] = [('cashflow_id', '=', cashflow_id.id)]
vals['domain'] = [
('cashflow_id', '=', cashflow_id.id)]
vals['context'] = {'search_default_cashflow_id': cashflow_id.id}
return vals
1 change: 1 addition & 0 deletions account_cash_flow/wizard/cash_flow.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<group>
<field name="end_date"/>
<field name="start_amount"/>
<field name="selected_account_ids" widget="many2many_tags"/>
<field name="ignore_outstanding"/>
<field name="print_report"/>
</group>
Expand Down

0 comments on commit c2bc9ac

Please sign in to comment.