Browse Source

[ADD] initialize wizard by current fiscal year

pull/512/head
Iryna Vushnevska 6 years ago
committed by Iryna Vyshnevska
parent
commit
3e0da15199
  1. 39
      account_financial_report/tests/test_general_ledger.py
  2. 5
      account_financial_report/tests/test_open_items.py
  3. 20
      account_financial_report/wizard/general_ledger_wizard.py

39
account_financial_report/tests/test_general_ledger.py

@ -4,6 +4,7 @@
import time
from odoo.api import Environment
from odoo.tests import common
from . import abstract_test_foreign_currency as a_t_f_c
@ -504,9 +505,43 @@ class TestGeneralLedgerReport(common.TransactionCase):
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],
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,
})
user = self.env.ref('base.user_root').with_context(
company_id=company_id.id)
wizard = self.env["general.ledger.report.wizard"].with_context(
user=user.id
)
self.assertEqual(wizard._init_date_from(),
time.strftime('%Y') + '-01-01')
def test_validate_date_range(self):
data_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': data_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')

5
account_financial_report/tests/test_open_items.py

@ -39,6 +39,7 @@ 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')
@ -49,8 +50,8 @@ class TestOpenItems(a_t_f_c.AbstractTestForeignCurrency):
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],
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)

20
account_financial_report/wizard/general_ledger_wizard.py

@ -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')],
@ -85,6 +88,18 @@ class GeneralLedgerReportWizard(models.TransientModel):
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')
@ -167,6 +182,7 @@ class GeneralLedgerReportWizard(models.TransientModel):
@api.onchange('date_range_id')
def onchange_date_range_id(self):
"""Handle date range change."""
if self.date_range_id:
self.date_from = self.date_range_id.date_start
self.date_to = self.date_range_id.date_end

Loading…
Cancel
Save