[MIG] account_financial_report_qweb: Migration to 11.0
* dynamize general ledger
This commit is contained in:
committed by
chaule97
parent
caf8ce9698
commit
554ad61027
9
account_financial_report/wizard/__init__.py
Normal file
9
account_financial_report/wizard/__init__.py
Normal file
@@ -0,0 +1,9 @@
|
||||
|
||||
# Author: Damien Crier
|
||||
# Author: Julien Coux
|
||||
# Copyright 2016 Camptocamp SA
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
from . import aged_partner_balance_wizard
|
||||
from . import general_ledger_wizard
|
||||
from . import open_items_wizard
|
||||
from . import trial_balance_wizard
|
||||
103
account_financial_report/wizard/aged_partner_balance_wizard.py
Normal file
103
account_financial_report/wizard/aged_partner_balance_wizard.py
Normal file
@@ -0,0 +1,103 @@
|
||||
# Author: Damien Crier, Andrea Stirpe, Kevin Graveman, Dennis Sluijk
|
||||
# Author: Julien Coux
|
||||
# Copyright 2016 Camptocamp SA, Onestein B.V.
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from datetime import datetime
|
||||
from odoo import api, fields, models
|
||||
from odoo.tools.safe_eval import safe_eval
|
||||
from odoo.tools import pycompat
|
||||
|
||||
|
||||
class AgedPartnerBalance(models.TransientModel):
|
||||
"""Aged partner balance report wizard."""
|
||||
|
||||
_name = 'aged.partner.balance.wizard'
|
||||
_description = 'Aged Partner Balance Wizard'
|
||||
|
||||
company_id = fields.Many2one(
|
||||
comodel_name='res.company',
|
||||
default=lambda self: self.env.user.company_id,
|
||||
string='Company'
|
||||
)
|
||||
date_at = fields.Date(required=True,
|
||||
default=fields.Date.to_string(datetime.today()))
|
||||
target_move = fields.Selection([('posted', 'All Posted Entries'),
|
||||
('all', 'All Entries')],
|
||||
string='Target Moves',
|
||||
required=True,
|
||||
default='all')
|
||||
account_ids = fields.Many2many(
|
||||
comodel_name='account.account',
|
||||
string='Filter accounts',
|
||||
)
|
||||
receivable_accounts_only = fields.Boolean()
|
||||
payable_accounts_only = fields.Boolean()
|
||||
partner_ids = fields.Many2many(
|
||||
comodel_name='res.partner',
|
||||
string='Filter partners',
|
||||
)
|
||||
show_move_line_details = fields.Boolean()
|
||||
|
||||
@api.onchange('receivable_accounts_only', 'payable_accounts_only')
|
||||
def onchange_type_accounts_only(self):
|
||||
"""Handle receivable/payable accounts only change."""
|
||||
if self.receivable_accounts_only or self.payable_accounts_only:
|
||||
domain = []
|
||||
if self.receivable_accounts_only and self.payable_accounts_only:
|
||||
domain += [('internal_type', 'in', ('receivable', 'payable'))]
|
||||
elif self.receivable_accounts_only:
|
||||
domain += [('internal_type', '=', 'receivable')]
|
||||
elif self.payable_accounts_only:
|
||||
domain += [('internal_type', '=', 'payable')]
|
||||
self.account_ids = self.env['account.account'].search(domain)
|
||||
else:
|
||||
self.account_ids = None
|
||||
|
||||
@api.multi
|
||||
def button_export_html(self):
|
||||
self.ensure_one()
|
||||
action = self.env.ref(
|
||||
'account_financial_report.action_report_aged_partner_balance')
|
||||
vals = action.read()[0]
|
||||
context1 = vals.get('context', {})
|
||||
if isinstance(context1, pycompat.string_types):
|
||||
context1 = safe_eval(context1)
|
||||
model = self.env['report_aged_partner_balance']
|
||||
report = model.create(self._prepare_report_aged_partner_balance())
|
||||
report.compute_data_for_report()
|
||||
|
||||
context1['active_id'] = report.id
|
||||
context1['active_ids'] = report.ids
|
||||
vals['context'] = context1
|
||||
return vals
|
||||
|
||||
@api.multi
|
||||
def button_export_pdf(self):
|
||||
self.ensure_one()
|
||||
report_type = 'qweb-pdf'
|
||||
return self._export(report_type)
|
||||
|
||||
@api.multi
|
||||
def button_export_xlsx(self):
|
||||
self.ensure_one()
|
||||
report_type = 'xlsx'
|
||||
return self._export(report_type)
|
||||
|
||||
def _prepare_report_aged_partner_balance(self):
|
||||
self.ensure_one()
|
||||
return {
|
||||
'date_at': self.date_at,
|
||||
'only_posted_moves': self.target_move == 'posted',
|
||||
'company_id': self.company_id.id,
|
||||
'filter_account_ids': [(6, 0, self.account_ids.ids)],
|
||||
'filter_partner_ids': [(6, 0, self.partner_ids.ids)],
|
||||
'show_move_line_details': self.show_move_line_details,
|
||||
}
|
||||
|
||||
def _export(self, report_type):
|
||||
"""Default export is PDF."""
|
||||
model = self.env['report_aged_partner_balance']
|
||||
report = model.create(self._prepare_report_aged_partner_balance())
|
||||
report.compute_data_for_report()
|
||||
return report.print_report(report_type)
|
||||
@@ -0,0 +1,53 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
|
||||
<!-- AGED PARTNER BALANCE -->
|
||||
<record id="aged_partner_balance_wizard" model="ir.ui.view">
|
||||
<field name="name">Aged Partner Balance</field>
|
||||
<field name="model">aged.partner.balance.wizard</field>
|
||||
<field name="arch" type="xml">
|
||||
<form>
|
||||
<group name="main_info">
|
||||
<field name="company_id" options="{'no_create': True}" groups="base.group_multi_company"/>
|
||||
</group>
|
||||
<group name="filters">
|
||||
<group name="date_range">
|
||||
<field name="date_at"/>
|
||||
</group>
|
||||
<group name="other_filters">
|
||||
<field name="target_move" widget="radio"/>
|
||||
<field name="show_move_line_details"/>
|
||||
</group>
|
||||
</group>
|
||||
<label for="partner_ids"/>
|
||||
<field name="partner_ids" 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}"/>
|
||||
<footer>
|
||||
<button name="button_export_html" string="View"
|
||||
type="object" default_focus="1" class="oe_highlight"/>
|
||||
or
|
||||
<button name="button_export_pdf" string="Export PDF" type="object"/>
|
||||
or
|
||||
<button name="button_export_xlsx" string="Export XLSX" type="object"/>
|
||||
or
|
||||
<button string="Cancel" class="oe_link" special="cancel" />
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<act_window id="action_aged_partner_balance_wizard"
|
||||
name="Aged Partner Balance"
|
||||
res_model="aged.partner.balance.wizard"
|
||||
view_type="form"
|
||||
view_mode="form"
|
||||
view_id="aged_partner_balance_wizard"
|
||||
target="new" />
|
||||
|
||||
</odoo>
|
||||
163
account_financial_report/wizard/general_ledger_wizard.py
Normal file
163
account_financial_report/wizard/general_ledger_wizard.py
Normal file
@@ -0,0 +1,163 @@
|
||||
# Author: Damien Crier
|
||||
# Author: Julien Coux
|
||||
# Author: Jordi Ballester
|
||||
# Copyright 2016 Camptocamp SA
|
||||
# Copyright 2017 Akretion - Alexis de Lattre
|
||||
# Copyright 2017 Eficent Business and IT Consulting Services, S.L.
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
|
||||
from odoo import api, fields, models
|
||||
from odoo.tools.safe_eval import safe_eval
|
||||
from odoo.tools import pycompat
|
||||
|
||||
|
||||
class GeneralLedgerReportWizard(models.TransientModel):
|
||||
"""General ledger report wizard."""
|
||||
|
||||
_name = "general.ledger.report.wizard"
|
||||
_description = "General Ledger Report Wizard"
|
||||
|
||||
company_id = fields.Many2one(
|
||||
comodel_name='res.company',
|
||||
default=lambda self: self.env.user.company_id,
|
||||
string='Company'
|
||||
)
|
||||
date_range_id = fields.Many2one(
|
||||
comodel_name='date.range',
|
||||
string='Date range'
|
||||
)
|
||||
date_from = fields.Date(required=True)
|
||||
date_to = fields.Date(required=True)
|
||||
fy_start_date = fields.Date(compute='_compute_fy_start_date')
|
||||
target_move = fields.Selection([('posted', 'All Posted Entries'),
|
||||
('all', 'All Entries')],
|
||||
string='Target Moves',
|
||||
required=True,
|
||||
default='all')
|
||||
account_ids = fields.Many2many(
|
||||
comodel_name='account.account',
|
||||
string='Filter accounts',
|
||||
)
|
||||
centralize = fields.Boolean(string='Activate centralization',
|
||||
default=True)
|
||||
hide_account_balance_at_0 = fields.Boolean(
|
||||
string='Hide account ending balance at 0',
|
||||
help='Use this filter to hide an account or a partner '
|
||||
'with an ending balance at 0. '
|
||||
'If partners are filtered, '
|
||||
'debits and credits totals will not match the trial balance.'
|
||||
)
|
||||
receivable_accounts_only = fields.Boolean()
|
||||
payable_accounts_only = fields.Boolean()
|
||||
partner_ids = fields.Many2many(
|
||||
comodel_name='res.partner',
|
||||
string='Filter partners',
|
||||
)
|
||||
cost_center_ids = fields.Many2many(
|
||||
comodel_name='account.analytic.account',
|
||||
string='Filter cost centers',
|
||||
)
|
||||
|
||||
not_only_one_unaffected_earnings_account = fields.Boolean(
|
||||
readonly=True,
|
||||
string='Not only one unaffected earnings account'
|
||||
)
|
||||
|
||||
@api.depends('date_from')
|
||||
def _compute_fy_start_date(self):
|
||||
for wiz in self.filtered('date_from'):
|
||||
date = fields.Datetime.from_string(wiz.date_from)
|
||||
res = self.company_id.compute_fiscalyear_dates(date)
|
||||
wiz.fy_start_date = res['date_from']
|
||||
|
||||
@api.onchange('company_id')
|
||||
def onchange_company_id(self):
|
||||
"""Handle company change."""
|
||||
account_type = self.env.ref('account.data_unaffected_earnings')
|
||||
count = self.env['account.account'].search_count(
|
||||
[
|
||||
('user_type_id', '=', account_type.id),
|
||||
('company_id', '=', self.company_id.id)
|
||||
])
|
||||
self.not_only_one_unaffected_earnings_account = count != 1
|
||||
|
||||
@api.onchange('date_range_id')
|
||||
def onchange_date_range_id(self):
|
||||
"""Handle date range change."""
|
||||
self.date_from = self.date_range_id.date_start
|
||||
self.date_to = self.date_range_id.date_end
|
||||
|
||||
@api.onchange('receivable_accounts_only', 'payable_accounts_only')
|
||||
def onchange_type_accounts_only(self):
|
||||
"""Handle receivable/payable accounts only change."""
|
||||
if self.receivable_accounts_only or self.payable_accounts_only:
|
||||
domain = []
|
||||
if self.receivable_accounts_only and self.payable_accounts_only:
|
||||
domain += [('internal_type', 'in', ('receivable', 'payable'))]
|
||||
elif self.receivable_accounts_only:
|
||||
domain += [('internal_type', '=', 'receivable')]
|
||||
elif self.payable_accounts_only:
|
||||
domain += [('internal_type', '=', 'payable')]
|
||||
self.account_ids = self.env['account.account'].search(domain)
|
||||
else:
|
||||
self.account_ids = None
|
||||
|
||||
@api.onchange('partner_ids')
|
||||
def onchange_partner_ids(self):
|
||||
"""Handle partners change."""
|
||||
if self.partner_ids:
|
||||
self.receivable_accounts_only = self.payable_accounts_only = True
|
||||
else:
|
||||
self.receivable_accounts_only = self.payable_accounts_only = False
|
||||
|
||||
@api.multi
|
||||
def button_export_html(self):
|
||||
self.ensure_one()
|
||||
action = self.env.ref(
|
||||
'account_financial_report.action_report_general_ledger')
|
||||
vals = action.read()[0]
|
||||
context1 = vals.get('context', {})
|
||||
if isinstance(context1, pycompat.string_types):
|
||||
context1 = safe_eval(context1)
|
||||
model = self.env['report_general_ledger']
|
||||
report = model.create(self._prepare_report_general_ledger())
|
||||
report.compute_data_for_report()
|
||||
context1['active_id'] = report.id
|
||||
context1['active_ids'] = report.ids
|
||||
vals['context'] = context1
|
||||
return vals
|
||||
|
||||
@api.multi
|
||||
def button_export_pdf(self):
|
||||
self.ensure_one()
|
||||
report_type = 'qweb-pdf'
|
||||
return self._export(report_type)
|
||||
|
||||
@api.multi
|
||||
def button_export_xlsx(self):
|
||||
self.ensure_one()
|
||||
report_type = 'xlsx'
|
||||
return self._export(report_type)
|
||||
|
||||
def _prepare_report_general_ledger(self):
|
||||
self.ensure_one()
|
||||
return {
|
||||
'date_from': self.date_from,
|
||||
'date_to': self.date_to,
|
||||
'only_posted_moves': self.target_move == 'posted',
|
||||
'hide_account_balance_at_0': self.hide_account_balance_at_0,
|
||||
'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_cost_center_ids': [(6, 0, self.cost_center_ids.ids)],
|
||||
'centralize': self.centralize,
|
||||
'fy_start_date': self.fy_start_date,
|
||||
}
|
||||
|
||||
def _export(self, report_type):
|
||||
"""Default export is PDF."""
|
||||
model = self.env['report_general_ledger']
|
||||
report = model.create(self._prepare_report_general_ledger())
|
||||
report.compute_data_for_report()
|
||||
return report.print_report(report_type)
|
||||
@@ -0,0 +1,73 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
|
||||
<!-- GENERAL LEDGER -->
|
||||
<record id="general_ledger_wizard" model="ir.ui.view">
|
||||
<field name="name">General Ledger</field>
|
||||
<field name="model">general.ledger.report.wizard</field>
|
||||
<field name="arch" type="xml">
|
||||
<form>
|
||||
<group name="main_info">
|
||||
<field name="company_id" options="{'no_create': True}" groups="base.group_multi_company"/>
|
||||
</group>
|
||||
<div attrs="{'invisible': [('not_only_one_unaffected_earnings_account', '=', True)]}">
|
||||
<group name="filters">
|
||||
<group name="date_range">
|
||||
<field name="date_range_id" domain="['|',('company_id','=',company_id), ('company_id','=',False)]"/>
|
||||
<field name="date_from"/>
|
||||
<field name="date_to"/>
|
||||
<field name="fy_start_date" invisible="1"/>
|
||||
</group>
|
||||
<group name="other_filters">
|
||||
<field name="target_move" widget="radio"/>
|
||||
<field name="centralize"/>
|
||||
<field name="hide_account_balance_at_0"/>
|
||||
</group>
|
||||
</group>
|
||||
<label for="cost_center_ids" groups="analytic.group_analytic_accounting"/>
|
||||
<field name="cost_center_ids" nolabel="1" options="{'no_create': True}" groups="analytic.group_analytic_accounting"/>
|
||||
<group/>
|
||||
<label for="partner_ids"/>
|
||||
<field name="partner_ids" 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}"/>
|
||||
</div>
|
||||
<div attrs="{'invisible': [('not_only_one_unaffected_earnings_account', '=', False)]}">
|
||||
<field name="not_only_one_unaffected_earnings_account" invisible="1"/>
|
||||
<group/>
|
||||
<h4>General Ledger can be computed only if selected company have only one unaffected earnings account.</h4>
|
||||
<group/>
|
||||
</div>
|
||||
<footer>
|
||||
<div attrs="{'invisible': [('not_only_one_unaffected_earnings_account', '=', True)]}">
|
||||
<button name="button_export_html" string="View"
|
||||
type="object" default_focus="1" class="oe_highlight"/>
|
||||
or
|
||||
<button name="button_export_pdf" string="Export PDF" type="object"/>
|
||||
or
|
||||
<button name="button_export_xlsx" string="Export XLSX" type="object"/>
|
||||
or
|
||||
<button string="Cancel" class="oe_link" special="cancel" />
|
||||
</div>
|
||||
<div attrs="{'invisible': [('not_only_one_unaffected_earnings_account', '=', False)]}">
|
||||
<button string="Cancel" class="oe_link" special="cancel" />
|
||||
</div>
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<act_window id="action_general_ledger_wizard"
|
||||
name="General Ledger"
|
||||
res_model="general.ledger.report.wizard"
|
||||
view_type="form"
|
||||
view_mode="form"
|
||||
view_id="general_ledger_wizard"
|
||||
target="new" />
|
||||
|
||||
</odoo>
|
||||
111
account_financial_report/wizard/open_items_wizard.py
Normal file
111
account_financial_report/wizard/open_items_wizard.py
Normal file
@@ -0,0 +1,111 @@
|
||||
|
||||
# Author: Damien Crier
|
||||
# Author: Julien Coux
|
||||
# Copyright 2016 Camptocamp SA
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from datetime import datetime
|
||||
from odoo import models, fields, api
|
||||
from odoo.tools.safe_eval import safe_eval
|
||||
from odoo.tools import pycompat
|
||||
|
||||
|
||||
class OpenItemsReportWizard(models.TransientModel):
|
||||
"""Open items report wizard."""
|
||||
|
||||
_name = "open.items.report.wizard"
|
||||
_description = "Open Items Report Wizard"
|
||||
|
||||
company_id = fields.Many2one(
|
||||
comodel_name='res.company',
|
||||
default=lambda self: self.env.user.company_id,
|
||||
string='Company'
|
||||
)
|
||||
date_at = fields.Date(required=True,
|
||||
default=fields.Date.to_string(datetime.today()))
|
||||
target_move = fields.Selection([('posted', 'All Posted Entries'),
|
||||
('all', 'All Entries')],
|
||||
string='Target Moves',
|
||||
required=True,
|
||||
default='all')
|
||||
account_ids = fields.Many2many(
|
||||
comodel_name='account.account',
|
||||
string='Filter accounts',
|
||||
domain=[('reconcile', '=', True)],
|
||||
)
|
||||
hide_account_balance_at_0 = fields.Boolean(
|
||||
string='Hide account ending balance at 0',
|
||||
help='Use this filter to hide an account or a partner '
|
||||
'with an ending balance at 0. '
|
||||
'If partners are filtered, '
|
||||
'debits and credits totals will not match the trial balance.'
|
||||
)
|
||||
receivable_accounts_only = fields.Boolean()
|
||||
payable_accounts_only = fields.Boolean()
|
||||
partner_ids = fields.Many2many(
|
||||
comodel_name='res.partner',
|
||||
string='Filter partners',
|
||||
)
|
||||
|
||||
@api.onchange('receivable_accounts_only', 'payable_accounts_only')
|
||||
def onchange_type_accounts_only(self):
|
||||
"""Handle receivable/payable accounts only change."""
|
||||
if self.receivable_accounts_only or self.payable_accounts_only:
|
||||
domain = []
|
||||
if self.receivable_accounts_only and self.payable_accounts_only:
|
||||
domain += [('internal_type', 'in', ('receivable', 'payable'))]
|
||||
elif self.receivable_accounts_only:
|
||||
domain += [('internal_type', '=', 'receivable')]
|
||||
elif self.payable_accounts_only:
|
||||
domain += [('internal_type', '=', 'payable')]
|
||||
self.account_ids = self.env['account.account'].search(domain)
|
||||
else:
|
||||
self.account_ids = None
|
||||
|
||||
@api.multi
|
||||
def button_export_html(self):
|
||||
self.ensure_one()
|
||||
action = self.env.ref(
|
||||
'account_financial_report.action_report_open_items')
|
||||
vals = action.read()[0]
|
||||
context1 = vals.get('context', {})
|
||||
if isinstance(context1, pycompat.string_types):
|
||||
context1 = safe_eval(context1)
|
||||
model = self.env['report_open_items']
|
||||
report = model.create(self._prepare_report_open_items())
|
||||
report.compute_data_for_report()
|
||||
|
||||
context1['active_id'] = report.id
|
||||
context1['active_ids'] = report.ids
|
||||
vals['context'] = context1
|
||||
return vals
|
||||
|
||||
@api.multi
|
||||
def button_export_pdf(self):
|
||||
self.ensure_one()
|
||||
report_type = 'qweb-pdf'
|
||||
return self._export(report_type)
|
||||
|
||||
@api.multi
|
||||
def button_export_xlsx(self):
|
||||
self.ensure_one()
|
||||
report_type = 'xlsx'
|
||||
return self._export(report_type)
|
||||
|
||||
def _prepare_report_open_items(self):
|
||||
self.ensure_one()
|
||||
return {
|
||||
'date_at': self.date_at,
|
||||
'only_posted_moves': self.target_move == 'posted',
|
||||
'hide_account_balance_at_0': self.hide_account_balance_at_0,
|
||||
'company_id': self.company_id.id,
|
||||
'filter_account_ids': [(6, 0, self.account_ids.ids)],
|
||||
'filter_partner_ids': [(6, 0, self.partner_ids.ids)],
|
||||
}
|
||||
|
||||
def _export(self, report_type):
|
||||
"""Default export is PDF."""
|
||||
model = self.env['report_open_items']
|
||||
report = model.create(self._prepare_report_open_items())
|
||||
report.compute_data_for_report()
|
||||
return report.print_report(report_type)
|
||||
53
account_financial_report/wizard/open_items_wizard_view.xml
Normal file
53
account_financial_report/wizard/open_items_wizard_view.xml
Normal file
@@ -0,0 +1,53 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
|
||||
<!-- OPEN ITEMS -->
|
||||
<record id="open_items_wizard" model="ir.ui.view">
|
||||
<field name="name">Open Items</field>
|
||||
<field name="model">open.items.report.wizard</field>
|
||||
<field name="arch" type="xml">
|
||||
<form>
|
||||
<group name="main_info">
|
||||
<field name="company_id" options="{'no_create': True}" groups="base.group_multi_company"/>
|
||||
</group>
|
||||
<group name="filters">
|
||||
<group name="date_range">
|
||||
<field name="date_at"/>
|
||||
</group>
|
||||
<group name="other_filters">
|
||||
<field name="target_move" widget="radio"/>
|
||||
<field name="hide_account_balance_at_0"/>
|
||||
</group>
|
||||
</group>
|
||||
<label for="partner_ids"/>
|
||||
<field name="partner_ids" 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}"/>
|
||||
<footer>
|
||||
<button name="button_export_html" string="View"
|
||||
type="object" default_focus="1" class="oe_highlight"/>
|
||||
or
|
||||
<button name="button_export_pdf" string="Export PDF" type="object"/>
|
||||
or
|
||||
<button name="button_export_xlsx" string="Export XLSX" type="object"/>
|
||||
or
|
||||
<button string="Cancel" class="oe_link" special="cancel" />
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<act_window id="action_open_items_wizard"
|
||||
name="Open Items"
|
||||
res_model="open.items.report.wizard"
|
||||
view_type="form"
|
||||
view_mode="form"
|
||||
view_id="open_items_wizard"
|
||||
target="new" />
|
||||
|
||||
</odoo>
|
||||
155
account_financial_report/wizard/trial_balance_wizard.py
Normal file
155
account_financial_report/wizard/trial_balance_wizard.py
Normal file
@@ -0,0 +1,155 @@
|
||||
|
||||
# Author: Julien Coux
|
||||
# Copyright 2016 Camptocamp SA
|
||||
# Copyright 2017 Akretion - Alexis de Lattre
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from odoo import models, fields, api
|
||||
from odoo.tools.safe_eval import safe_eval
|
||||
from odoo.tools import pycompat
|
||||
|
||||
|
||||
class TrialBalanceReportWizard(models.TransientModel):
|
||||
"""Trial balance report wizard."""
|
||||
|
||||
_name = "trial.balance.report.wizard"
|
||||
_description = "Trial Balance Report Wizard"
|
||||
|
||||
company_id = fields.Many2one(
|
||||
comodel_name='res.company',
|
||||
default=lambda self: self.env.user.company_id,
|
||||
string='Company'
|
||||
)
|
||||
date_range_id = fields.Many2one(
|
||||
comodel_name='date.range',
|
||||
string='Date range'
|
||||
)
|
||||
date_from = fields.Date(required=True)
|
||||
date_to = fields.Date(required=True)
|
||||
fy_start_date = fields.Date(compute='_compute_fy_start_date')
|
||||
target_move = fields.Selection([('posted', 'All Posted Entries'),
|
||||
('all', 'All Entries')],
|
||||
string='Target Moves',
|
||||
required=True,
|
||||
default='all')
|
||||
account_ids = fields.Many2many(
|
||||
comodel_name='account.account',
|
||||
string='Filter accounts',
|
||||
)
|
||||
hide_account_balance_at_0 = fields.Boolean(
|
||||
string='Hide account ending balance at 0',
|
||||
help='Use this filter to hide an account or a partner '
|
||||
'with an ending balance at 0. '
|
||||
'If partners are filtered, '
|
||||
'debits and credits totals will not match the trial balance.'
|
||||
)
|
||||
receivable_accounts_only = fields.Boolean()
|
||||
payable_accounts_only = fields.Boolean()
|
||||
show_partner_details = fields.Boolean()
|
||||
partner_ids = fields.Many2many(
|
||||
comodel_name='res.partner',
|
||||
string='Filter partners',
|
||||
)
|
||||
|
||||
not_only_one_unaffected_earnings_account = fields.Boolean(
|
||||
readonly=True,
|
||||
string='Not only one unaffected earnings account'
|
||||
)
|
||||
|
||||
@api.depends('date_from')
|
||||
def _compute_fy_start_date(self):
|
||||
for wiz in self.filtered('date_from'):
|
||||
date = fields.Datetime.from_string(wiz.date_from)
|
||||
res = self.company_id.compute_fiscalyear_dates(date)
|
||||
wiz.fy_start_date = res['date_from']
|
||||
|
||||
@api.onchange('company_id')
|
||||
def onchange_company_id(self):
|
||||
"""Handle company change."""
|
||||
account_type = self.env.ref('account.data_unaffected_earnings')
|
||||
count = self.env['account.account'].search_count(
|
||||
[
|
||||
('user_type_id', '=', account_type.id),
|
||||
('company_id', '=', self.company_id.id)
|
||||
])
|
||||
self.not_only_one_unaffected_earnings_account = count != 1
|
||||
|
||||
@api.onchange('date_range_id')
|
||||
def onchange_date_range_id(self):
|
||||
"""Handle date range change."""
|
||||
self.date_from = self.date_range_id.date_start
|
||||
self.date_to = self.date_range_id.date_end
|
||||
|
||||
@api.onchange('receivable_accounts_only', 'payable_accounts_only')
|
||||
def onchange_type_accounts_only(self):
|
||||
"""Handle receivable/payable accounts only change."""
|
||||
if self.receivable_accounts_only or self.payable_accounts_only:
|
||||
domain = []
|
||||
if self.receivable_accounts_only and self.payable_accounts_only:
|
||||
domain += [('internal_type', 'in', ('receivable', 'payable'))]
|
||||
elif self.receivable_accounts_only:
|
||||
domain += [('internal_type', '=', 'receivable')]
|
||||
elif self.payable_accounts_only:
|
||||
domain += [('internal_type', '=', 'payable')]
|
||||
self.account_ids = self.env['account.account'].search(domain)
|
||||
else:
|
||||
self.account_ids = None
|
||||
|
||||
@api.onchange('show_partner_details')
|
||||
def onchange_show_partner_details(self):
|
||||
"""Handle partners change."""
|
||||
if self.show_partner_details:
|
||||
self.receivable_accounts_only = self.payable_accounts_only = True
|
||||
else:
|
||||
self.receivable_accounts_only = self.payable_accounts_only = False
|
||||
|
||||
@api.multi
|
||||
def button_export_html(self):
|
||||
self.ensure_one()
|
||||
action = self.env.ref(
|
||||
'account_financial_report.action_report_trial_balance')
|
||||
vals = action.read()[0]
|
||||
context1 = vals.get('context', {})
|
||||
if isinstance(context1, pycompat.string_types):
|
||||
context1 = safe_eval(context1)
|
||||
model = self.env['report_trial_balance']
|
||||
report = model.create(self._prepare_report_trial_balance())
|
||||
report.compute_data_for_report()
|
||||
|
||||
context1['active_id'] = report.id
|
||||
context1['active_ids'] = report.ids
|
||||
vals['context'] = context1
|
||||
return vals
|
||||
|
||||
@api.multi
|
||||
def button_export_pdf(self):
|
||||
self.ensure_one()
|
||||
report_type = 'qweb-pdf'
|
||||
return self._export(report_type)
|
||||
|
||||
@api.multi
|
||||
def button_export_xlsx(self):
|
||||
self.ensure_one()
|
||||
report_type = 'xlsx'
|
||||
return self._export(report_type)
|
||||
|
||||
def _prepare_report_trial_balance(self):
|
||||
self.ensure_one()
|
||||
return {
|
||||
'date_from': self.date_from,
|
||||
'date_to': self.date_to,
|
||||
'only_posted_moves': self.target_move == 'posted',
|
||||
'hide_account_balance_at_0': self.hide_account_balance_at_0,
|
||||
'company_id': self.company_id.id,
|
||||
'filter_account_ids': [(6, 0, self.account_ids.ids)],
|
||||
'filter_partner_ids': [(6, 0, self.partner_ids.ids)],
|
||||
'fy_start_date': self.fy_start_date,
|
||||
'show_partner_details': self.show_partner_details,
|
||||
}
|
||||
|
||||
def _export(self, report_type):
|
||||
"""Default export is PDF."""
|
||||
model = self.env['report_trial_balance']
|
||||
report = model.create(self._prepare_report_trial_balance())
|
||||
report.compute_data_for_report()
|
||||
return report.print_report(report_type)
|
||||
@@ -0,0 +1,70 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
|
||||
<!-- TRIAL BALANCE -->
|
||||
<record id="trial_balance_wizard" model="ir.ui.view">
|
||||
<field name="name">Trial Balance</field>
|
||||
<field name="model">trial.balance.report.wizard</field>
|
||||
<field name="arch" type="xml">
|
||||
<form>
|
||||
<group name="main_info">
|
||||
<field name="company_id" options="{'no_create': True}" groups="base.group_multi_company"/>
|
||||
</group>
|
||||
<div attrs="{'invisible': [('not_only_one_unaffected_earnings_account', '=', True)]}">
|
||||
<group name="filters">
|
||||
<group name="date_range">
|
||||
<field name="date_range_id" domain="['|',('company_id','=',company_id), ('company_id','=',False)]"/>
|
||||
<field name="date_from"/>
|
||||
<field name="date_to"/>
|
||||
<field name="fy_start_date" invisible="1"/>
|
||||
</group>
|
||||
<group name="other_filters">
|
||||
<field name="target_move" widget="radio"/>
|
||||
<field name="hide_account_balance_at_0"/>
|
||||
<field name="show_partner_details"/>
|
||||
</group>
|
||||
</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)]}"/>
|
||||
<group attrs="{'invisible':[('show_partner_details','!=',True)]}"/>
|
||||
<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}"/>
|
||||
</div>
|
||||
<div attrs="{'invisible': [('not_only_one_unaffected_earnings_account', '=', False)]}">
|
||||
<field name="not_only_one_unaffected_earnings_account" invisible="1"/>
|
||||
<group/>
|
||||
<h4>Trial Balance can be computed only if selected company have only one unaffected earnings account.</h4>
|
||||
<group/>
|
||||
</div>
|
||||
<footer>
|
||||
<div attrs="{'invisible': [('not_only_one_unaffected_earnings_account', '=', True)]}">
|
||||
<button name="button_export_html" string="View"
|
||||
type="object" default_focus="1" class="oe_highlight"/>
|
||||
or
|
||||
<button name="button_export_pdf" string="Export PDF" type="object"/>
|
||||
or
|
||||
<button name="button_export_xlsx" string="Export XLSX" type="object"/>
|
||||
or
|
||||
<button string="Cancel" class="oe_link" special="cancel" />
|
||||
</div>
|
||||
<div attrs="{'invisible': [('not_only_one_unaffected_earnings_account', '=', False)]}">
|
||||
<button string="Cancel" class="oe_link" special="cancel" />
|
||||
</div>
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<act_window id="action_trial_balance_wizard"
|
||||
name="Trial Balance"
|
||||
res_model="trial.balance.report.wizard"
|
||||
view_type="form"
|
||||
view_mode="form"
|
||||
view_id="trial_balance_wizard"
|
||||
target="new" />
|
||||
|
||||
</odoo>
|
||||
Reference in New Issue
Block a user