|
|
@ -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,6 +183,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 |
|
|
|
|
|
|
|