[12.0] account_financial_report: refactor

This commit is contained in:
Joan Sisquella
2020-01-23 17:27:52 +01:00
committed by chaule97
parent b26ee9ff05
commit 1227d53d4f
45 changed files with 5446 additions and 7930 deletions

View File

@@ -4,14 +4,12 @@
# 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 AgedPartnerBalanceWizard(models.TransientModel):
"""Aged partner balance report wizard."""
_name = 'aged.partner.balance.wizard'
_name = 'aged.partner.balance.report.wizard'
_description = 'Aged Partner Balance Wizard'
_inherit = 'account_financial_report_abstract_wizard'
@@ -66,35 +64,36 @@ class AgedPartnerBalanceWizard(models.TransientModel):
@api.onchange('receivable_accounts_only', 'payable_accounts_only')
def onchange_type_accounts_only(self):
"""Handle receivable/payable accounts only change."""
domain = [('company_id', '=', self.company_id.id)]
if self.receivable_accounts_only or self.payable_accounts_only:
domain = [('company_id', '=', self.company_id.id)]
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)
elif not self.receivable_accounts_only and not self.payable_accounts_only:
domain += [('reconcile', '=', True)]
self.account_ids = self.env['account.account'].search(domain)
@api.multi
def _print_report(self, report_type):
self.ensure_one()
data = self._prepare_report_aged_partner_balance()
if report_type == 'xlsx':
report_name = 'a_f_r.report_aged_partner_balance_xlsx'
else:
self.account_ids = None
report_name = 'account_financial_report.aged_partner_balance'
return self.env['ir.actions.report'].search(
[('report_name', '=', report_name),
('report_type', '=', report_type)], limit=1).report_action(
self, data=data)
@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
report_type = 'qweb-html'
return self._export(report_type)
@api.multi
def button_export_pdf(self):
@@ -111,17 +110,15 @@ class AgedPartnerBalanceWizard(models.TransientModel):
def _prepare_report_aged_partner_balance(self):
self.ensure_one()
return {
'wizard_id': self.id,
'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)],
'account_ids': self.account_ids.ids,
'partner_ids': 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)
return self._print_report(report_type)

View File

@@ -4,7 +4,7 @@
<!-- 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="model">aged.partner.balance.report.wizard</field>
<field name="arch" type="xml">
<form>
<group name="main_info">
@@ -50,7 +50,7 @@
<act_window id="action_aged_partner_balance_wizard"
name="Aged Partner Balance"
res_model="aged.partner.balance.wizard"
res_model="aged.partner.balance.report.wizard"
view_type="form"
view_mode="form"
view_id="aged_partner_balance_wizard"

View File

@@ -8,8 +8,6 @@
from odoo import api, fields, models, _
from odoo.tools.safe_eval import safe_eval
from odoo.tools import pycompat
from odoo.exceptions import ValidationError
import time
@@ -203,22 +201,42 @@ class GeneralLedgerReportWizard(models.TransientModel):
else:
self.receivable_accounts_only = self.payable_accounts_only = False
@api.multi
@api.depends('company_id')
def _compute_unaffected_earnings_account(self):
account_type = self.env.ref('account.data_unaffected_earnings')
for record in self:
record.unaffected_earnings_account = self.env[
'account.account'].search(
[
('user_type_id', '=', account_type.id),
('company_id', '=', record.company_id.id)
])
unaffected_earnings_account = fields.Many2one(
comodel_name='account.account',
compute='_compute_unaffected_earnings_account',
store=True
)
@api.multi
def _print_report(self, report_type):
self.ensure_one()
data = self._prepare_report_general_ledger()
if report_type == 'xlsx':
report_name = 'a_f_r.report_general_ledger_xlsx'
else:
report_name = 'account_financial_report.general_ledger'
return self.env['ir.actions.report'].search(
[('report_name', '=', report_name),
('report_type', '=', report_type)], limit=1).report_action(
self, data=data)
@api.multi
def button_export_html(self):
self.ensure_one()
action = self.env.ref(
'account_financial_report.action_report_general_ledger')
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']
report = model.create(self._prepare_report_general_ledger())
report.compute_data_for_report()
context1['active_id'] = report.id
context1['active_ids'] = report.ids
action_data['context'] = context1
return action_data
report_type = 'qweb-html'
return self._export(report_type)
@api.multi
def button_export_pdf(self):
@@ -235,6 +253,7 @@ class GeneralLedgerReportWizard(models.TransientModel):
def _prepare_report_general_ledger(self):
self.ensure_one()
return {
'wizard_id': self.id,
'date_from': self.date_from,
'date_to': self.date_to,
'only_posted_moves': self.target_move == 'posted',
@@ -242,18 +261,22 @@ class GeneralLedgerReportWizard(models.TransientModel):
'foreign_currency': self.foreign_currency,
'show_analytic_tags': self.show_analytic_tags,
'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)],
'filter_analytic_tag_ids': [(6, 0, self.analytic_tag_ids.ids)],
'filter_journal_ids': [(6, 0, self.account_journal_ids.ids)],
'account_ids': self.account_ids.ids,
'partner_ids': self.partner_ids.ids,
'cost_center_ids': self.cost_center_ids.ids,
'analytic_tag_ids': self.analytic_tag_ids.ids,
'journal_ids': self.account_journal_ids.ids,
'centralize': self.centralize,
'fy_start_date': self.fy_start_date,
'unaffected_earnings_account': self.unaffected_earnings_account.id,
}
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)
return self._print_report(report_type)
def _get_atr_from_dict(self, obj_id, data, key):
try:
return data[obj_id][key]
except KeyError:
return data[str(obj_id)][key]

View File

@@ -2,8 +2,6 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import api, fields, models, _
from odoo.tools.safe_eval import safe_eval
from odoo.tools import pycompat
class JournalLedgerReportWizard(models.TransientModel):
@@ -102,26 +100,27 @@ class JournalLedgerReportWizard(models.TransientModel):
('company_id', '=', self.company_id.id)]
return res
@api.multi
def _print_report(self, report_type):
self.ensure_one()
data = self._prepare_report_journal_ledger()
if report_type == 'xlsx':
report_name = 'a_f_r.report_journal_ledger_xlsx'
else:
report_name = 'account_financial_report.journal_ledger'
return self.env['ir.actions.report'].search(
[('report_name', '=', report_name),
('report_type', '=', report_type)], limit=1).report_action(
self, data=data)
@api.multi
def button_export_html(self):
self.ensure_one()
action = self.env.ref(
'account_financial_report.action_report_journal_ledger')
vals = action.read()[0]
context1 = vals.get('context', {})
if isinstance(context1, pycompat.string_types):
context1 = safe_eval(context1)
model = self.env['report_journal_ledger']
report = model.create(self._prepare_report_journal_ledger())
report.compute_data_for_report()
context1['active_id'] = report.id
context1['active_ids'] = report.ids
vals['context'] = context1
return vals
report_type = 'qweb-html'
return self._export(report_type)
@api.multi
def button_export_pdf(self):
self.ensure_one()
report_type = 'qweb-pdf'
return self._export(report_type)
@@ -140,12 +139,13 @@ class JournalLedgerReportWizard(models.TransientModel):
journals = self.env['account.journal'].search(
[('company_id', '=', self.company_id.id)])
return {
'wizard_id': self.id,
'date_from': self.date_from,
'date_to': self.date_to,
'move_target': self.move_target,
'foreign_currency': self.foreign_currency,
'company_id': self.company_id.id,
'journal_ids': [(6, 0, journals.ids)],
'journal_ids': journals.ids,
'sort_option': self.sort_option,
'group_option': self.group_option,
'with_account_name': self.with_account_name,
@@ -154,7 +154,44 @@ class JournalLedgerReportWizard(models.TransientModel):
def _export(self, report_type):
"""Default export is PDF."""
self.ensure_one()
model = self.env['report_journal_ledger']
report = model.create(self._prepare_report_journal_ledger())
report.compute_data_for_report()
return report.print_report(report_type)
return self._print_report(report_type)
@api.model
def _get_ml_tax_description(
self, move_line_data, tax_line_data, move_line_taxes_data):
taxes_description = ''
if move_line_data['tax_line_id']:
taxes_description = tax_line_data['description'] or \
tax_line_data['name']
elif move_line_taxes_data:
tax_names = []
for tax_key in move_line_taxes_data:
tax = move_line_taxes_data[tax_key]
tax_names.append(
tax['description'] or tax['name'])
taxes_description = ','.join(tax_names)
return taxes_description
@api.model
def _get_partner_name(self, partner_id, partner_data):
if str(partner_id) in partner_data.keys():
return partner_data[str(partner_id)]['name']
else:
return ''
@api.model
def _get_atr_from_dict(self, obj_id, data, key):
try:
return data[obj_id][key]
except KeyError:
return data[str(obj_id)][key]
@api.model
def _get_data_from_dict(self, obj_id, data):
if data:
if isinstance(list(data.keys())[0], int):
return data.get(obj_id, False)
else:
return data.get(obj_id(obj_id), False)
else:
return False

View File

@@ -4,8 +4,6 @@
# 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 OpenItemsReportWizard(models.TransientModel):
@@ -23,6 +21,7 @@ class OpenItemsReportWizard(models.TransientModel):
)
date_at = fields.Date(required=True,
default=fields.Date.context_today)
date_from = fields.Date(string='Date From')
target_move = fields.Selection([('posted', 'All Posted Entries'),
('all', 'All Entries')],
string='Target Moves',
@@ -84,35 +83,36 @@ class OpenItemsReportWizard(models.TransientModel):
@api.onchange('receivable_accounts_only', 'payable_accounts_only')
def onchange_type_accounts_only(self):
"""Handle receivable/payable accounts only change."""
domain = [('company_id', '=', self.company_id.id)]
if self.receivable_accounts_only or self.payable_accounts_only:
domain = [('company_id', '=', self.company_id.id)]
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)
elif not self.receivable_accounts_only and not self.payable_accounts_only:
domain += [('reconcile', '=', True)]
self.account_ids = self.env['account.account'].search(domain)
@api.multi
def _print_report(self, report_type):
self.ensure_one()
data = self._prepare_report_open_items()
if report_type == 'xlsx':
report_name = 'a_f_r.report_open_items_xlsx'
else:
self.account_ids = None
report_name = 'account_financial_report.open_items'
return self.env['ir.actions.report'].search(
[('report_name', '=', report_name),
('report_type', '=', report_type)], limit=1).report_action(
self, data=data)
@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
report_type = 'qweb-html'
return self._export(report_type)
@api.multi
def button_export_pdf(self):
@@ -129,18 +129,17 @@ class OpenItemsReportWizard(models.TransientModel):
def _prepare_report_open_items(self):
self.ensure_one()
return {
'date_at': self.date_at,
'wizard_id': self.id,
'date_at': fields.Date.to_string(self.date_at),
'date_from': self.date_from or False,
'only_posted_moves': self.target_move == 'posted',
'hide_account_at_0': self.hide_account_at_0,
'foreign_currency': self.foreign_currency,
'company_id': self.company_id.id,
'filter_account_ids': [(6, 0, self.account_ids.ids)],
'filter_partner_ids': [(6, 0, self.partner_ids.ids)],
'target_move': self.target_move,
'account_ids': self.account_ids.ids,
'partner_ids': self.partner_ids.ids or [],
}
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)
return self._print_report(report_type)

View File

@@ -13,6 +13,7 @@
<group name="filters">
<group name="date_range">
<field name="date_at"/>
<field name="date_from"/>
</group>
<group name="other_filters">
<field name="target_move" widget="radio"/>

View File

@@ -5,8 +5,6 @@
# 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
from odoo.exceptions import UserError, ValidationError
@@ -41,7 +39,7 @@ class TrialBalanceReportWizard(models.TransientModel):
('none', 'No hierarchy')],
string='Hierarchy On',
required=True,
default='computed',
default='none',
help="""Computed Accounts: Use when the account group have codes
that represent prefixes of the actual accounts.\n
Child Accounts: Use when your account groups are hierarchical.\n
@@ -183,25 +181,45 @@ class TrialBalanceReportWizard(models.TransientModel):
if self.show_partner_details:
self.receivable_accounts_only = self.payable_accounts_only = True
else:
self.receivable_accounts_only = self.payable_accounts_only = False
self.receivable_accounts_only = self.\
payable_accounts_only = False
@api.multi
@api.depends('company_id')
def _compute_unaffected_earnings_account(self):
account_type = self.env.ref('account.data_unaffected_earnings')
for record in self:
record.unaffected_earnings_account = self.env[
'account.account'].search(
[
('user_type_id', '=', account_type.id),
('company_id', '=', record.company_id.id)
])
unaffected_earnings_account = fields.Many2one(
comodel_name='account.account',
compute='_compute_unaffected_earnings_account',
store=True
)
@api.multi
def _print_report(self, report_type):
self.ensure_one()
data = self._prepare_report_trial_balance()
if report_type == 'xlsx':
report_name = 'a_f_r.report_trial_balance_xlsx'
else:
report_name = 'account_financial_report.trial_balance'
return self.env['ir.actions.report'].search(
[('report_name', '=', report_name),
('report_type', '=', report_type)], limit=1).report_action(
self, data=data)
@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
report_type = 'qweb-html'
return self._export(report_type)
@api.multi
def button_export_pdf(self):
@@ -218,26 +236,25 @@ class TrialBalanceReportWizard(models.TransientModel):
def _prepare_report_trial_balance(self):
self.ensure_one()
return {
'wizard_id': self.id,
'date_from': self.date_from,
'date_to': self.date_to,
'only_posted_moves': self.target_move == 'posted',
'hide_account_at_0': self.hide_account_at_0,
'foreign_currency': self.foreign_currency,
'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.journal_ids.ids)],
'account_ids': self.account_ids.ids or [],
'partner_ids': self.partner_ids.ids or [],
'journal_ids': self.journal_ids.ids or [],
'fy_start_date': self.fy_start_date,
'hierarchy_on': self.hierarchy_on,
'limit_hierarchy_level': self.limit_hierarchy_level,
'show_hierarchy_level': self.show_hierarchy_level,
'hide_parent_hierarchy_level': self.hide_parent_hierarchy_level,
'show_partner_details': self.show_partner_details,
'unaffected_earnings_account': self.unaffected_earnings_account.id,
}
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)
return self._print_report(report_type)

View File

@@ -23,7 +23,7 @@
<field name="hide_account_at_0"/>
<field name="show_partner_details"/>
<field name="hierarchy_on" widget="radio" attrs="{'invisible':[('show_partner_details','=',True)]}"/>
<field name="limit_hierarchy_level" attrs="{'invisible':['|', ('hierarchy_on','=','none'),('show_partner_details','=',True)]}"/>
<field name="limit_hierarchy_level" attrs="{'invisible':['|', ('hierarchy_on','in',['none', 'computed']),('show_partner_details','=',True)]}"/>
<field name="show_hierarchy_level" attrs="{'invisible':[('limit_hierarchy_level','=', False)]}"/>
<field name="hide_parent_hierarchy_level" attrs="{'invisible':[('limit_hierarchy_level','=', False)]}"/>
<field name="foreign_currency"/>

View File

@@ -2,8 +2,6 @@
# 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
from odoo.exceptions import ValidationError
@@ -62,22 +60,24 @@ class VATReportWizard(models.TransientModel):
_('The Company in the Vat Report Wizard and in '
'Date Range must be the same.'))
@api.multi
def _print_report(self, report_type):
self.ensure_one()
data = self._prepare_vat_report()
if report_type == 'xlsx':
report_name = 'a_f_r.report_vat_report_xlsx'
else:
report_name = 'account_financial_report.vat_report'
return self.env['ir.actions.report'].search(
[('report_name', '=', report_name),
('report_type', '=', report_type)], limit=1).report_action(
self, data=data)
@api.multi
def button_export_html(self):
self.ensure_one()
action = self.env.ref(
'account_financial_report.action_report_vat_report')
vals = action.read()[0]
context1 = vals.get('context', {})
if isinstance(context1, pycompat.string_types):
context1 = safe_eval(context1)
model = self.env['report_vat_report']
report = model.create(self._prepare_vat_report())
report.compute_data_for_report()
context1['active_id'] = report.id
context1['active_ids'] = report.ids
vals['context'] = context1
return vals
report_type = 'qweb-html'
return self._export(report_type)
@api.multi
def button_export_pdf(self):
@@ -94,6 +94,7 @@ class VATReportWizard(models.TransientModel):
def _prepare_vat_report(self):
self.ensure_one()
return {
'wizard_id': self.id,
'company_id': self.company_id.id,
'date_from': self.date_from,
'date_to': self.date_to,
@@ -103,7 +104,4 @@ class VATReportWizard(models.TransientModel):
def _export(self, report_type):
"""Default export is PDF."""
model = self.env['report_vat_report']
report = model.create(self._prepare_vat_report())
report.compute_data_for_report()
return report.print_report(report_type)
return self._print_report(report_type)