Browse Source

[ADD] 11.0 account_financial_report: add filter by journals

To general ledger
pull/749/head
mpanarin 6 years ago
committed by João Marques
parent
commit
2a7e16c57f
  1. 18
      account_financial_report/i18n/account_financial_report.pot
  2. 58
      account_financial_report/report/general_ledger.py
  3. 2
      account_financial_report/report/trial_balance.py
  4. 13
      account_financial_report/wizard/general_ledger_wizard.py
  5. 4
      account_financial_report/wizard/general_ledger_wizard_view.xml
  6. 4
      account_financial_report/wizard/trial_balance_wizard.py
  7. 2
      account_financial_report/wizard/trial_balance_wizard_view.xml

18
account_financial_report/i18n/account_financial_report.pot

@ -398,7 +398,7 @@ msgid "Centralized"
msgstr ""
#. module: account_financial_report
#: code:addons/account_financial_report/report/general_ledger.py:1218
#: code:addons/account_financial_report/report/general_ledger.py:1233
#, python-format
msgid "Centralized Entries"
msgstr ""
@ -957,6 +957,12 @@ msgstr ""
msgid "Filter Cost Center"
msgstr ""
#. module: account_financial_report
#: model:ir.model.fields,field_description:account_financial_report.field_report_general_ledger_filter_journal_ids
#: model:ir.model.fields,field_description:account_financial_report.field_report_trial_balance_filter_journal_ids
msgid "Filter Journal"
msgstr ""
#. module: account_financial_report
#: model:ir.model.fields,field_description:account_financial_report.field_report_aged_partner_balance_filter_partner_ids
#: model:ir.model.fields,field_description:account_financial_report.field_report_general_ledger_filter_partner_ids
@ -978,6 +984,11 @@ msgstr ""
msgid "Filter cost centers"
msgstr ""
#. module: account_financial_report
#: model:ir.model.fields,field_description:account_financial_report.field_general_ledger_report_wizard_account_journal_ids
msgid "Filter journals"
msgstr ""
#. module: account_financial_report
#: model:ir.model.fields,field_description:account_financial_report.field_aged_partner_balance_wizard_partner_ids
#: model:ir.model.fields,field_description:account_financial_report.field_general_ledger_report_wizard_partner_ids
@ -1251,6 +1262,7 @@ msgstr ""
#: model:ir.model.fields,field_description:account_financial_report.field_report_journal_ledger_journal_ids
#: model:ir.model.fields,field_description:account_financial_report.field_report_journal_ledger_journal_journal_id
#: model:ir.model.fields,field_description:account_financial_report.field_report_open_items_move_line_journal
#: model:ir.model.fields,field_description:account_financial_report.field_trial_balance_report_wizard_journal_ids
#: model:ir.ui.view,arch_db:account_financial_report.report_aged_partner_balance_move_lines
#: model:ir.ui.view,arch_db:account_financial_report.report_general_ledger_lines
#: model:ir.ui.view,arch_db:account_financial_report.report_open_items_lines
@ -1499,8 +1511,8 @@ msgid "No group"
msgstr ""
#. module: account_financial_report
#: code:addons/account_financial_report/report/general_ledger.py:681
#: code:addons/account_financial_report/report/general_ledger.py:978
#: code:addons/account_financial_report/report/general_ledger.py:684
#: code:addons/account_financial_report/report/general_ledger.py:981
#: code:addons/account_financial_report/report/open_items.py:302
#: code:addons/account_financial_report/report/open_items.py:551
#, python-format

58
account_financial_report/report/general_ledger.py

@ -36,6 +36,9 @@ class GeneralLedgerReport(models.TransientModel):
filter_cost_center_ids = fields.Many2many(
comodel_name='account.analytic.account'
)
filter_journal_ids = fields.Many2many(
comodel_name='account.journal',
)
centralize = fields.Boolean()
# Flag fields, used for report display
@ -1104,6 +1107,11 @@ AND
AND
rp.partner_id IS NULL
"""
if self.filter_journal_ids:
query_inject_move_line += """
AND
j.id IN %s
"""
if is_account_line:
query_inject_move_line += """
ORDER BY
@ -1138,6 +1146,10 @@ ORDER BY
self.date_from,
self.date_to,
)
if self.filter_journal_ids:
query_inject_move_line_params += (tuple(
self.filter_journal_ids.ids,
),)
self.env.cr.execute(
query_inject_move_line,
query_inject_move_line_params
@ -1161,7 +1173,8 @@ WITH
SUM(ml.debit) AS debit,
SUM(ml.credit) AS credit,
SUM(ml.balance) AS balance,
ml.currency_id AS currency_id
ml.currency_id AS currency_id,
ml.journal_id as journal_id
FROM
report_general_ledger_account ra
INNER JOIN
@ -1194,7 +1207,7 @@ WITH
"""
query_inject_move_line_centralized += """
GROUP BY
ra.id, ml.account_id, a.code, 2, ml.currency_id
ra.id, ml.account_id, a.code, 2, ml.currency_id, ml.journal_id
)
INSERT INTO
report_general_ledger_move_line
@ -1204,6 +1217,7 @@ INSERT INTO
create_date,
date,
account,
journal,
label,
debit,
credit,
@ -1215,6 +1229,7 @@ SELECT
NOW() AS create_date,
ml.date,
a.code AS account,
j.code AS journal,
'""" + _('Centralized Entries') + """' AS label,
ml.debit AS debit,
ml.credit AS credit,
@ -1228,12 +1243,21 @@ INNER JOIN
move_lines ml ON ra.account_id = ml.account_id
INNER JOIN
account_account a ON ml.account_id = a.id
INNER JOIN
account_journal j ON ml.journal_id = j.id
LEFT JOIN
res_currency c ON ml.currency_id = c.id
WHERE
ra.report_id = %s
AND
(a.centralized IS NOT NULL AND a.centralized = TRUE)
"""
if self.filter_journal_ids:
query_inject_move_line_centralized += """
AND
j.id in %s
"""
query_inject_move_line_centralized += """
ORDER BY
a.code, ml.date
"""
@ -1250,6 +1274,10 @@ ORDER BY
self.env.uid,
self.id,
)
if self.filter_journal_ids:
query_inject_move_line_centralized_params += (tuple(
self.filter_journal_ids.ids,
),)
self.env.cr.execute(
query_inject_move_line_centralized,
query_inject_move_line_centralized_params
@ -1289,7 +1317,13 @@ ORDER BY
sub_subquery_sum_amounts += """
WHERE
a.company_id = %(company_id)s
AND a.id IN %(unaffected_earnings_account_ids)s
AND
a.id IN %(unaffected_earnings_account_ids)s
"""
if self.filter_journal_ids:
sub_subquery_sum_amounts += """
AND
ml.journal_id in %(filter_journal_ids)s
"""
return sub_subquery_sum_amounts
@ -1326,10 +1360,16 @@ ORDER BY
AND aa.id IN %(cost_center_ids)s
"""
sub_subquery_sum_amounts += """
WHERE
a.company_id = %(company_id)s
AND a.id IN %(unaffected_earnings_account_ids)s
"""
WHERE
a.company_id = %(company_id)s
AND
a.id IN %(unaffected_earnings_account_ids)s
"""
if self.filter_journal_ids:
sub_subquery_sum_amounts += """
AND
ml.journal_id in %(filter_journal_ids)s
"""
return sub_subquery_sum_amounts
def _inject_unaffected_earnings_account_values(self):
@ -1406,6 +1446,10 @@ ORDER BY
query_inject_account_params['report_id'] = self.id
query_inject_account_params['user_id'] = self.env.uid
if self.filter_journal_ids:
query_inject_account_params['filter_journal_ids'] = (tuple(
self.filter_journal_ids.ids,
),)
# Fetch the profit and loss accounts
query_unaffected_earnings_account_ids = """
SELECT a.id

2
account_financial_report/report/trial_balance.py

@ -28,6 +28,7 @@ class TrialBalanceReport(models.TransientModel):
company_id = fields.Many2one(comodel_name='res.company')
filter_account_ids = fields.Many2many(comodel_name='account.account')
filter_partner_ids = fields.Many2many(comodel_name='res.partner')
filter_journal_ids = fields.Many2many(comodel_name='account.journal')
show_partner_details = fields.Boolean()
hierarchy_on = fields.Selection([('computed', 'Computed Accounts'),
('relation', 'Child Accounts')],
@ -187,6 +188,7 @@ class TrialBalanceReportCompute(models.TransientModel):
'company_id': self.company_id.id,
'filter_account_ids': [(6, 0, account_ids.ids)],
'filter_partner_ids': [(6, 0, self.filter_partner_ids.ids)],
'filter_journal_ids': [(6, 0, self.filter_journal_ids.ids)],
'fy_start_date': self.fy_start_date,
}

13
account_financial_report/wizard/general_ledger_wizard.py

@ -54,6 +54,10 @@ class GeneralLedgerReportWizard(models.TransientModel):
comodel_name='res.partner',
string='Filter partners',
)
account_journal_ids = fields.Many2many(
comodel_name='account.journal',
string='Filter journals',
)
cost_center_ids = fields.Many2many(
comodel_name='account.analytic.account',
string='Filter cost centers',
@ -122,8 +126,8 @@ class GeneralLedgerReportWizard(models.TransientModel):
self.ensure_one()
action = self.env.ref(
'account_financial_report.action_report_general_ledger')
vals = action.read()[0]
context1 = vals.get('context', {})
action_data = action.read()[0]
context1 = action_data.get('context', {})
if isinstance(context1, pycompat.string_types):
context1 = safe_eval(context1)
model = self.env['report_general_ledger']
@ -131,8 +135,8 @@ class GeneralLedgerReportWizard(models.TransientModel):
report.compute_data_for_report()
context1['active_id'] = report.id
context1['active_ids'] = report.ids
vals['context'] = context1
return vals
action_data['context'] = context1
return action_data
@api.multi
def button_export_pdf(self):
@ -158,6 +162,7 @@ class GeneralLedgerReportWizard(models.TransientModel):
'filter_account_ids': [(6, 0, self.account_ids.ids)],
'filter_partner_ids': [(6, 0, self.partner_ids.ids)],
'filter_cost_center_ids': [(6, 0, self.cost_center_ids.ids)],
'filter_journal_ids': [(6, 0, self.account_journal_ids.ids)],
'centralize': self.centralize,
'fy_start_date': self.fy_start_date,
}

4
account_financial_report/wizard/general_ledger_wizard_view.xml

@ -30,13 +30,15 @@
<group/>
<label for="partner_ids"/>
<field name="partner_ids" nolabel="1" options="{'no_create': True}"/>
<label for="account_journal_ids"/>
<field name="account_journal_ids" widget="many2many_tags" nolabel="1" options="{'no_create': True}"/>
<group/>
<label for="account_ids"/>
<group col="4">
<field name="receivable_accounts_only"/>
<field name="payable_accounts_only"/>
</group>
<field name="account_ids" widget="many2many_tags" nolabel="1" options="{'no_create': True}"/>
<field name="account_ids" widget="many2many_tags" nolabel="1" options="{'no_create': True}"/>
</div>
<div attrs="{'invisible': [('not_only_one_unaffected_earnings_account', '=', False)]}">
<field name="not_only_one_unaffected_earnings_account" invisible="1"/>

4
account_financial_report/wizard/trial_balance_wizard.py

@ -54,6 +54,9 @@ class TrialBalanceReportWizard(models.TransientModel):
comodel_name='res.partner',
string='Filter partners',
)
journal_ids = fields.Many2many(
comodel_name="account.journal",
)
not_only_one_unaffected_earnings_account = fields.Boolean(
readonly=True,
@ -157,6 +160,7 @@ class TrialBalanceReportWizard(models.TransientModel):
'company_id': self.company_id.id,
'filter_account_ids': [(6, 0, self.account_ids.ids)],
'filter_partner_ids': [(6, 0, self.partner_ids.ids)],
'filter_journal_ids': [(6, 0, self.partner_ids.ids)],
'fy_start_date': self.fy_start_date,
'hierarchy_on': self.hierarchy_on,
'show_partner_details': self.show_partner_details,

2
account_financial_report/wizard/trial_balance_wizard_view.xml

@ -28,6 +28,8 @@
</group>
<label for="partner_ids" attrs="{'invisible':[('show_partner_details','!=',True)]}"/>
<field name="partner_ids" nolabel="1" options="{'no_create': True}" attrs="{'invisible':[('show_partner_details','!=',True)]}"/>
<label for="journal_ids"/>
<field name="journal_ids" widget="many2many_tags" nolabel="1" options="{'no_create': True}"/>
<group attrs="{'invisible':[('show_partner_details','!=',True)]}"/>
<label for="account_ids"/>
<group col="4">

Loading…
Cancel
Save