[IMP] account_financial_reports: Several improvements:
* Move to less files to compile variables * hide contacts on partner * Add reports to res partner actions * initialize wizard from context * initialize wizard by current fiscal year
This commit is contained in:
committed by
chaule97
parent
0817cf3c4d
commit
8b43ea4758
@@ -60,8 +60,10 @@ class AgedPartnerBalanceWizard(models.TransientModel):
|
||||
res['domain']['account_ids'] += [
|
||||
('company_id', '=', self.company_id.id)]
|
||||
res['domain']['partner_ids'] += [
|
||||
'&',
|
||||
'|', ('company_id', '=', self.company_id.id),
|
||||
('company_id', '=', False)]
|
||||
('company_id', '=', False),
|
||||
('parent_id', '=', False)]
|
||||
return res
|
||||
|
||||
@api.onchange('receivable_accounts_only', 'payable_accounts_only')
|
||||
|
||||
@@ -11,6 +11,7 @@ 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
|
||||
|
||||
|
||||
class GeneralLedgerReportWizard(models.TransientModel):
|
||||
@@ -29,8 +30,10 @@ class GeneralLedgerReportWizard(models.TransientModel):
|
||||
comodel_name='date.range',
|
||||
string='Date range'
|
||||
)
|
||||
date_from = fields.Date(required=True)
|
||||
date_to = fields.Date(required=True)
|
||||
date_from = fields.Date(required=True,
|
||||
default=lambda self: self._init_date_from())
|
||||
date_to = fields.Date(required=True,
|
||||
default=fields.Date.context_today)
|
||||
fy_start_date = fields.Date(compute='_compute_fy_start_date')
|
||||
target_move = fields.Selection([('posted', 'All Posted Entries'),
|
||||
('all', 'All Entries')],
|
||||
@@ -58,6 +61,7 @@ class GeneralLedgerReportWizard(models.TransientModel):
|
||||
partner_ids = fields.Many2many(
|
||||
comodel_name='res.partner',
|
||||
string='Filter partners',
|
||||
default=lambda self: self._default_partners(),
|
||||
)
|
||||
analytic_tag_ids = fields.Many2many(
|
||||
comodel_name='account.analytic.tag',
|
||||
@@ -80,9 +84,38 @@ class GeneralLedgerReportWizard(models.TransientModel):
|
||||
string='Show foreign currency',
|
||||
help='Display foreign currency for move lines, unless '
|
||||
'account currency is not setup through chart of accounts '
|
||||
'will display initial and final balance in that currency.'
|
||||
'will display initial and final balance in that currency.',
|
||||
default=lambda self: self._default_foreign_currency(),
|
||||
)
|
||||
|
||||
def _init_date_from(self):
|
||||
"""set start date to begin of current year if fiscal year running"""
|
||||
today = fields.Date.context_today(self)
|
||||
cur_month = fields.Date.from_string(today).month
|
||||
cur_day = fields.Date.from_string(today).day
|
||||
last_fsc_month = self.env.user.company_id.fiscalyear_last_month
|
||||
last_fsc_day = self.env.user.company_id.fiscalyear_last_day
|
||||
|
||||
if cur_month < last_fsc_month \
|
||||
or cur_month == last_fsc_month and cur_day <= last_fsc_day:
|
||||
return time.strftime('%Y-01-01')
|
||||
|
||||
def _default_foreign_currency(self):
|
||||
return self.env.user.has_group('base.group_multi_currency')
|
||||
|
||||
def _default_partners(self):
|
||||
context = self.env.context
|
||||
|
||||
if context.get('active_ids') and context.get('active_model') \
|
||||
== 'res.partner':
|
||||
partner_ids = context['active_ids']
|
||||
corp_partners = self.env['res.partner'].browse(partner_ids). \
|
||||
filtered(lambda p: p.parent_id)
|
||||
|
||||
partner_ids = set(partner_ids) - set(corp_partners.ids)
|
||||
partner_ids |= set(corp_partners.mapped('parent_id.id'))
|
||||
return list(partner_ids)
|
||||
|
||||
@api.depends('date_from')
|
||||
def _compute_fy_start_date(self):
|
||||
for wiz in self.filtered('date_from'):
|
||||
@@ -135,8 +168,10 @@ class GeneralLedgerReportWizard(models.TransientModel):
|
||||
res['domain']['account_journal_ids'] += [
|
||||
('company_id', '=', self.company_id.id)]
|
||||
res['domain']['partner_ids'] += [
|
||||
'&',
|
||||
'|', ('company_id', '=', self.company_id.id),
|
||||
('company_id', '=', False)]
|
||||
('company_id', '=', False),
|
||||
('parent_id', '=', False)]
|
||||
res['domain']['cost_center_ids'] += [
|
||||
('company_id', '=', self.company_id.id)]
|
||||
res['domain']['date_range_id'] += [
|
||||
@@ -147,8 +182,9 @@ class GeneralLedgerReportWizard(models.TransientModel):
|
||||
@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
|
||||
if self.date_range_id:
|
||||
self.date_from = self.date_range_id.date_start
|
||||
self.date_to = self.date_range_id.date_end
|
||||
|
||||
@api.multi
|
||||
@api.constrains('company_id', 'date_range_id')
|
||||
|
||||
@@ -85,4 +85,17 @@
|
||||
view_id="general_ledger_wizard"
|
||||
target="new" />
|
||||
|
||||
<!--Add to res.partner action-->
|
||||
<act_window id="act_action_general_ledger_wizard_partner_relation"
|
||||
name="General Ledger"
|
||||
res_model="general.ledger.report.wizard"
|
||||
src_model="res.partner"
|
||||
view_mode="form"
|
||||
context="{
|
||||
'default_receivable_accounts_only':1,
|
||||
'default_payable_accounts_only':1,
|
||||
}"
|
||||
key2="client_action_multi"
|
||||
target="new" />
|
||||
|
||||
</odoo>
|
||||
|
||||
@@ -44,14 +44,32 @@ class OpenItemsReportWizard(models.TransientModel):
|
||||
partner_ids = fields.Many2many(
|
||||
comodel_name='res.partner',
|
||||
string='Filter partners',
|
||||
default=lambda self: self._default_partners(),
|
||||
)
|
||||
foreign_currency = fields.Boolean(
|
||||
string='Show foreign currency',
|
||||
help='Display foreign currency for move lines, unless '
|
||||
'account currency is not setup through chart of accounts '
|
||||
'will display initial and final balance in that currency.'
|
||||
'will display initial and final balance in that currency.',
|
||||
default=lambda self: self._default_foreign_currency(),
|
||||
)
|
||||
|
||||
def _default_foreign_currency(self):
|
||||
return self.env.user.has_group('base.group_multi_currency')
|
||||
|
||||
def _default_partners(self):
|
||||
context = self.env.context
|
||||
|
||||
if context.get('active_ids') and context.get('active_model') \
|
||||
== 'res.partner':
|
||||
partner_ids = context['active_ids']
|
||||
corp_partners = self.env['res.partner'].browse(partner_ids). \
|
||||
filtered(lambda p: p.parent_id)
|
||||
|
||||
partner_ids = set(partner_ids) - set(corp_partners.ids)
|
||||
partner_ids |= set(corp_partners.mapped('parent_id.id'))
|
||||
return list(partner_ids)
|
||||
|
||||
@api.onchange('company_id')
|
||||
def onchange_company_id(self):
|
||||
"""Handle company change."""
|
||||
@@ -73,8 +91,10 @@ class OpenItemsReportWizard(models.TransientModel):
|
||||
res['domain']['account_ids'] += [
|
||||
('company_id', '=', self.company_id.id)]
|
||||
res['domain']['partner_ids'] += [
|
||||
'&',
|
||||
'|', ('company_id', '=', self.company_id.id),
|
||||
('company_id', '=', False)]
|
||||
('company_id', '=', False),
|
||||
('parent_id', '=', False)]
|
||||
return res
|
||||
|
||||
@api.onchange('receivable_accounts_only', 'payable_accounts_only')
|
||||
|
||||
@@ -58,4 +58,17 @@
|
||||
view_id="open_items_wizard"
|
||||
target="new" />
|
||||
|
||||
<!--Add to res.partner action-->
|
||||
<act_window id="act_action_open_items_wizard_partner_relation"
|
||||
name="Open Items Partner"
|
||||
res_model="open.items.report.wizard"
|
||||
src_model="res.partner"
|
||||
view_mode="form"
|
||||
context="{
|
||||
'default_receivable_accounts_only':1,
|
||||
'default_payable_accounts_only':1,
|
||||
}"
|
||||
key2="client_action_multi"
|
||||
target="new" />
|
||||
|
||||
</odoo>
|
||||
|
||||
@@ -138,8 +138,10 @@ class TrialBalanceReportWizard(models.TransientModel):
|
||||
res['domain']['account_ids'] += [
|
||||
('company_id', '=', self.company_id.id)]
|
||||
res['domain']['partner_ids'] += [
|
||||
'&',
|
||||
'|', ('company_id', '=', self.company_id.id),
|
||||
('company_id', '=', False)]
|
||||
('company_id', '=', False),
|
||||
('parent_id', '=', False)]
|
||||
res['domain']['date_range_id'] += [
|
||||
'|', ('company_id', '=', self.company_id.id),
|
||||
('company_id', '=', False)]
|
||||
|
||||
Reference in New Issue
Block a user