diff --git a/account_financial_report_qweb/static/src/js/account_financial_report_qweb_widgets.js b/account_financial_report_qweb/static/src/js/account_financial_report_qweb_widgets.js
index 53ba2816..36412a06 100644
--- a/account_financial_report_qweb/static/src/js/account_financial_report_qweb_widgets.js
+++ b/account_financial_report_qweb/static/src/js/account_financial_report_qweb_widgets.js
@@ -47,7 +47,7 @@ odoo.define('account_financial_report_qweb.account_financial_report_widget', fun
boundLinkMonetary: function (e) {
var res_model = $(e.target).data('res-model');
var res_id = $(e.target).data('active-id');
- // check if we call on appropriate element, amount been wrapped in
+ // Check if we call on appropriate element, amount been wrapped in
// a span by a monetary widget
if (e.target.localName === 'span' ) {
res_model = $(e.target.parentElement).data('res-model');
@@ -64,7 +64,7 @@ odoo.define('account_financial_report_qweb.account_financial_report_widget', fun
boundLinkMonetarymulti: function (e) {
var res_model = $(e.target).data('res-model');
var domain = $(e.target).data('domain');
- // check if we call on appropriate element, amount been wrapped in
+ // Check if we call on appropriate element, amount been wrapped in
// a span by a monetary widget
if (e.target.localName === 'span' ) {
res_model = $(e.target.parentElement).data('res-model');
diff --git a/account_financial_report_qweb/tests/test_general_ledger.py b/account_financial_report_qweb/tests/test_general_ledger.py
index f280015d..91a3d204 100644
--- a/account_financial_report_qweb/tests/test_general_ledger.py
+++ b/account_financial_report_qweb/tests/test_general_ledger.py
@@ -4,6 +4,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
import time
+from odoo.api import Environment
from odoo.tests import common
from . import abstract_test_foreign_currency as a_t_f_c
@@ -499,3 +500,55 @@ class TestGeneralLedgerReport(common.TransactionCase):
self.assertEqual(lines['unaffected'].final_debit, 500)
self.assertEqual(lines['unaffected'].final_credit, 0)
self.assertEqual(lines['unaffected'].final_balance, 500)
+
+ def test_partner_filter(self):
+ partner_1 = self.env.ref('base.res_partner_1')
+ partner_2 = self.env.ref('base.res_partner_2')
+ partner_3 = self.env.ref('base.res_partner_3')
+ partner_4 = self.env.ref('base.res_partner_4')
+ partner_1.write({'is_company': False,
+ 'parent_id': partner_2.id})
+ partner_3.write({'is_company': False})
+
+ expected_list = [partner_2.id, partner_3.id, partner_4.id]
+ context = {'active_ids': [
+ partner_1.id, partner_2.id, partner_3.id, partner_4.id
+ ],
+ 'active_model': 'res.partner'}
+
+ wizard = self.env["general.ledger.report.wizard"].with_context(context)
+ self.assertEqual(wizard._default_partners(), expected_list)
+
+ def test_validate_date(self):
+ company_id = self.env.ref('base.main_company')
+ company_id.write({
+ 'fiscalyear_last_day': 31,
+ 'fiscalyear_last_month': 12,
+ })
+ cr = self.registry.cursor()
+ user = self.env.ref('base.user_root').with_context({
+ 'company_id': company_id.id})
+ env = Environment(cr, user.id, {})
+ wizard = env["general.ledger.report.wizard"]
+ self.assertEqual(wizard._init_date_from(),
+ time.strftime('%Y') + '-01-01')
+
+ def test_validate_date_range(self):
+ type = self.env['date.range.type'].create({
+ 'name': 'Fiscal year',
+ 'company_id': False,
+ 'allow_overlap': False
+ })
+
+ dr = self.env['date.range'].create({
+ 'name': 'FS2015',
+ 'date_start': '2018-01-01',
+ 'date_end': '2018-12-31',
+ 'type_id': type.id,
+ })
+
+ wizard = self.env["general.ledger.report.wizard"].create({
+ 'date_range_id': dr.id})
+ wizard.onchange_date_range_id()
+ self.assertEqual(wizard.date_from, '2018-01-01')
+ self.assertEqual(wizard.date_to, '2018-12-31')
diff --git a/account_financial_report_qweb/tests/test_open_items.py b/account_financial_report_qweb/tests/test_open_items.py
index 66b0d151..e6636b90 100644
--- a/account_financial_report_qweb/tests/test_open_items.py
+++ b/account_financial_report_qweb/tests/test_open_items.py
@@ -40,3 +40,21 @@ class TestOpenItems(a_t_f_c.AbstractTestForeignCurrency):
{'hide_account_at_0': True},
{'only_posted_moves': True, 'hide_account_at_0': True},
]
+
+ def test_partner_filter(self):
+ partner_1 = self.env.ref('base.res_partner_1')
+ partner_2 = self.env.ref('base.res_partner_2')
+ partner_3 = self.env.ref('base.res_partner_3')
+ partner_4 = self.env.ref('base.res_partner_4')
+ partner_1.write({'is_company': False,
+ 'parent_id': partner_2.id})
+ partner_3.write({'is_company': False})
+
+ expected_list = [partner_2.id, partner_3.id, partner_4.id]
+ context = {'active_ids': [
+ partner_1.id, partner_2.id, partner_3.id, partner_4.id
+ ],
+ 'active_model': 'res.partner'}
+
+ wizard = self.env["open.items.report.wizard"].with_context(context)
+ self.assertEqual(wizard._default_partners(), expected_list)
diff --git a/account_financial_report_qweb/wizard/general_ledger_wizard.py b/account_financial_report_qweb/wizard/general_ledger_wizard.py
index 3c3db78a..78ea585f 100644
--- a/account_financial_report_qweb/wizard/general_ledger_wizard.py
+++ b/account_financial_report_qweb/wizard/general_ledger_wizard.py
@@ -9,6 +9,8 @@ from odoo import api, fields, models, _
from odoo.tools.safe_eval import safe_eval
from odoo.exceptions import ValidationError
+import time
+
class GeneralLedgerReportWizard(models.TransientModel):
"""General ledger report wizard."""
@@ -26,8 +28,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')],
@@ -55,6 +59,7 @@ class GeneralLedgerReportWizard(models.TransientModel):
partner_ids = fields.Many2many(
comodel_name='res.partner',
string='Filter partners',
+ default=lambda self: self._default_partners(),
)
journal_ids = fields.Many2many(
comodel_name="account.journal",
@@ -71,6 +76,7 @@ class GeneralLedgerReportWizard(models.TransientModel):
)
foreign_currency = fields.Boolean(
string='Show foreign currency',
+ default=lambda self: self._default_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.'
@@ -80,6 +86,36 @@ class GeneralLedgerReportWizard(models.TransientModel):
string='Filter accounts',
)
+ def _default_foreign_currency(self):
+ if self.env.user.has_group('base.group_multi_currency'):
+ return True
+
+ 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)
+
+ 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 = int(fields.Date.from_string(today).strftime('%m'))
+ cur_day = int(fields.Date.from_string(today).strftime('%d'))
+ 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')
+
@api.depends('date_from')
def _compute_fy_start_date(self):
for wiz in self.filtered('date_from'):
@@ -147,8 +183,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')
diff --git a/account_financial_report_qweb/wizard/general_ledger_wizard_view.xml b/account_financial_report_qweb/wizard/general_ledger_wizard_view.xml
index 2a7a8132..81a6d1ff 100644
--- a/account_financial_report_qweb/wizard/general_ledger_wizard_view.xml
+++ b/account_financial_report_qweb/wizard/general_ledger_wizard_view.xml
@@ -86,4 +86,16 @@
view_id="general_ledger_wizard"
target="new" />
+
+
diff --git a/account_financial_report_qweb/wizard/open_items_wizard.py b/account_financial_report_qweb/wizard/open_items_wizard.py
index 54df699b..1a5a0f84 100644
--- a/account_financial_report_qweb/wizard/open_items_wizard.py
+++ b/account_financial_report_qweb/wizard/open_items_wizard.py
@@ -44,9 +44,11 @@ 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',
+ default=lambda self: self._default_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.'
@@ -79,6 +81,24 @@ class OpenItemsReportWizard(models.TransientModel):
('parent_id', '=', False)]
return res
+ def _default_foreign_currency(self):
+ if self.env.user.has_group('base.group_multi_currency'):
+ return True
+
+ 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('receivable_accounts_only', 'payable_accounts_only')
def onchange_type_accounts_only(self):
"""Handle receivable/payable accounts only change."""
diff --git a/account_financial_report_qweb/wizard/open_items_wizard_view.xml b/account_financial_report_qweb/wizard/open_items_wizard_view.xml
index 974a4834..09f6c52a 100644
--- a/account_financial_report_qweb/wizard/open_items_wizard_view.xml
+++ b/account_financial_report_qweb/wizard/open_items_wizard_view.xml
@@ -58,4 +58,16 @@
view_id="open_items_wizard"
target="new" />
+
+