diff --git a/account_financial_report_qweb/__openerp__.py b/account_financial_report_qweb/__openerp__.py index 8d60cdf2..fb8b7ce0 100644 --- a/account_financial_report_qweb/__openerp__.py +++ b/account_financial_report_qweb/__openerp__.py @@ -24,13 +24,14 @@ 'report_menus.xml', 'wizard/balance_common_wizard_view.xml', 'views/report_menus.xml', + 'menuitems.xml', + 'reports.xml', + 'wizard/general_ledger_wizard.xml', + # 'wizard/partner_ledger_wizard.xml', + 'report/templates/ledger_general.xml', ], 'test': [ ], - 'demo': [ - ], - 'qweb': [ - ], 'installable': True, 'application': True, 'auto_install': False, diff --git a/account_financial_report_qweb/menuitems.xml b/account_financial_report_qweb/menuitems.xml new file mode 100644 index 00000000..f6ca1245 --- /dev/null +++ b/account_financial_report_qweb/menuitems.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + diff --git a/account_financial_report_qweb/models/__init__.py b/account_financial_report_qweb/models/__init__.py index 28867113..b8a98686 100644 --- a/account_financial_report_qweb/models/__init__.py +++ b/account_financial_report_qweb/models/__init__.py @@ -2,3 +2,5 @@ # Author: Damien Crier # Copyright 2016 Camptocamp SA # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import account diff --git a/account_financial_report_qweb/models/account.py b/account_financial_report_qweb/models/account.py new file mode 100644 index 00000000..27ab9463 --- /dev/null +++ b/account_financial_report_qweb/models/account.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +# © 2011 Guewen Baconnier (Camptocamp) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).- +from openerp import models, fields + + +class AccountAccount(models.Model): + _inherit = 'account.account' + + centralized = fields.Boolean( + 'Centralized', + default=False, + help="If flagged, no details will be displayed in " + "the General Ledger report (the webkit one only), " + "only centralized amounts per period.") diff --git a/account_financial_report_qweb/report/__init__.py b/account_financial_report_qweb/report/__init__.py index 28867113..231ff56b 100644 --- a/account_financial_report_qweb/report/__init__.py +++ b/account_financial_report_qweb/report/__init__.py @@ -1,4 +1,6 @@ # -*- coding: utf-8 -*- -# Author: Damien Crier -# Copyright 2016 Camptocamp SA -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +# © 2015 Yannick Vaucher (Camptocamp) +# © 2016 Damien Crier (Camptocamp) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).- +from . import common +from . import general_ledger diff --git a/account_financial_report_qweb/report/common.py b/account_financial_report_qweb/report/common.py new file mode 100644 index 00000000..d4226236 --- /dev/null +++ b/account_financial_report_qweb/report/common.py @@ -0,0 +1,113 @@ +# -*- encoding: utf-8 -*- +# © 2015 Yannick Vaucher +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from openerp import models, fields, api + + +class FinancialReportLine(models.AbstractModel): + """Rappresentation of a report line.""" + + _name = 'financial.report.line' + _description = "Financial report line" + + _order = 'account_id, date' + # TODO order by account_id.code + + name = fields.Char() + ref = fields.Char() + date = fields.Date() + month = fields.Char() + partner_name = fields.Char() + partner_ref = fields.Char() + account_id = fields.Many2one('account.account') + account_code = fields.Char() + journal_id = fields.Many2one('account.journal') + + currency_id = fields.Many2one('res.currency') + currency_code = fields.Char() + init_credit = fields.Float() + init_debit = fields.Float() + debit = fields.Float() + credit = fields.Float() + balance = fields.Float() + amount_currency = fields.Float() + + cumul_credit = fields.Float() + cumul_debit = fields.Float() + cumul_balance = fields.Float() + cumul_balance_curr = fields.Float() + + init_credit = fields.Float() + init_debit = fields.Float() + init_balance = fields.Float() + init_balance_curr = fields.Float() + + debit_centralized = fields.Float() + credit_centralized = fields.Float() + balance_centralized = fields.Float() + balance_curr_centralized = fields.Float() + + init_credit_centralized = fields.Float() + init_debit_centralized = fields.Float() + init_balance_centralized = fields.Float() + init_balance_curr_centralized = fields.Float() + + move_name = fields.Char() + move_state = fields.Char() + invoice_number = fields.Char() + + centralized = fields.Boolean() + + +class CommonFinancialReport(models.AbstractModel): + _name = 'account.report.common' + + start_date = fields.Date() + end_date = fields.Date() + + fiscalyear = fields.Many2one('account.fiscalyear') + + centralize = fields.Boolean() + target_move = fields.Char() + + filter = fields.Selection( + [('filter_no', 'No Filters'), + ('filter_date', 'Date'), + ('filter_opening', 'Opening Only')], + "Filter by", + required=False, + help='Filter by date: no opening balance will be displayed. ' + '(opening balance can only be computed based on period to be ' + 'correct).' + ) + + @api.multi + def _get_moves_from_dates_domain(self): + """ Prepare domain for `_get_moves_from_dates` """ + domain = [] + if self.centralize: + domain = [('centralized', '=', False)] + start_date = self.start_date + end_date = self.end_date + if self.fiscalyear: + start_date = self.fiscalyear.start_date + end_date = self.fiscalyear.end_date + if start_date: + domain += [('date', '>=', start_date)] + if end_date: + domain += [('date', '<=', end_date)] + + if self.target_move == 'posted': + domain += [('move_state', '=', 'posted')] + + if self.account_ids: + domain += [('account_id', 'in', self.account_ids.ids)] + + domain += [('journal_id', 'in', self.journal_ids.ids)] + return domain + + @api.multi + def _get_moves_from_fiscalyear(self, account, fiscalyear, + target_move): + return self._get_moves_from_dates( + account, fiscalyear.date_start, fiscalyear.date_end, target_move) diff --git a/account_financial_report_qweb/report/general_ledger.py b/account_financial_report_qweb/report/general_ledger.py new file mode 100644 index 00000000..404f8fbb --- /dev/null +++ b/account_financial_report_qweb/report/general_ledger.py @@ -0,0 +1,210 @@ +# -*- coding: utf-8 -*- +# © 2015 Yannick Vaucher (Camptocamp) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from openerp import models, fields, api +from openerp import tools + + +class FinancialReportLine(models.Model): + _inherit = 'financial.report.line' + _name = 'general.ledger.line' + _description = "General Ledger report" + + _auto = False + _order = 'account_id, date' + + @api.depends('invoice_number', 'name') + def _get_label(self): + for rec in self: + invoice_number = '' + if rec.invoice_number: + invoice_number = ' (rec.invoice_number)' + rec.label = u'%(line_name)s%(invoice_number)s' % { + 'line_name': rec.name, + 'invoice_number': invoice_number} + + label = fields.Char(compute='_get_label', readonly=True, store=False) + + def init(self, cr): + report_name = self._name.replace('.', '_') + tools.drop_view_if_exists(cr, report_name) + query = """ +CREATE OR REPLACE VIEW %(report_name)s AS ( + SELECT + acc.id AS account_id, + acc.code AS account_code, + acc.centralized, + ml.id, + ml.name, + ml.ref, + ml.date, + date_part('year', ml.date) || '-' || date_part('month', ml.date) + AS month, + part.ref AS partner_ref, + part.name AS partner_name, + ml.journal_id, + ml.currency_id, + cur.name AS currency_code, + ml.debit, + ml.credit, + ml.debit - ml.credit AS balance, + ml.amount_currency, + + SUM(amount_currency) OVER w_account AS balance_curr, + SUM(debit) OVER w_account AS cumul_debit, + SUM(credit) OVER w_account AS cumul_credit, + SUM(debit - credit) OVER w_account AS cumul_balance, + SUM(amount_currency) OVER w_account AS cumul_balance_curr, + + SUM(debit) OVER w_account - debit AS init_debit, + SUM(credit) OVER w_account - credit AS init_credit, + SUM(debit - credit) OVER w_account - (debit - credit) AS init_balance, + SUM(amount_currency) OVER w_account - (amount_currency) + AS init_balance_curr, + + SUM(debit) OVER w_account_centralized AS debit_centralized, + SUM(credit) OVER w_account_centralized AS credit_centralized, + SUM(debit - credit) OVER w_account_centralized AS balance_centralized, + SUM(amount_currency) OVER w_account_centralized + AS balance_curr_centralized, + + SUM(debit) OVER w_account - SUM(debit) + OVER w_account_centralized AS init_debit_centralized, + SUM(credit) OVER w_account - SUM(credit) + OVER w_account_centralized AS init_credit_centralized, + SUM(debit - credit) OVER w_account - SUM(debit - credit) + OVER w_account_centralized AS init_balance_centralized, + SUM(amount_currency) OVER w_account - SUM(amount_currency) + OVER w_account_centralized AS init_balance_curr_centralized, + + m.name AS move_name, + m.state AS move_state, + i.number AS invoice_number + FROM + account_account AS acc + LEFT JOIN account_move_line AS ml ON (ml.account_id = acc.id) + INNER JOIN res_partner AS part ON (ml.partner_id = part.id) + INNER JOIN account_move AS m ON (ml.move_id = m.id) + LEFT JOIN account_invoice AS i ON (m.id = i.move_id) + LEFT JOIN res_currency AS cur ON (ml.currency_id = cur.id) + WINDOW w_account AS (PARTITION BY acc.code ORDER BY ml.date, ml.id), + w_account_centralized AS ( + PARTITION BY acc.code, + date_part('year', ml.date), + date_part('month', ml.date), + ml.journal_id, + ml.partner_id + ORDER BY ml.date, ml.journal_id, ml.id) +) + """ % {'report_name': report_name} + cr.execute(query) + + +class GeneralLedgerReport(models.TransientModel): + + _name = 'report.account.report_generalledger_qweb' + _inherit = 'account.report.common' + + @api.multi + def _get_account_ids(self): + res = False + context = self.env.context + if (context.get('active_model') == 'account.account' and + context.get('active_ids')): + res = context['active_ids'] + return res + + name = fields.Char() + initial_balance = fields.Integer() + account_ids = fields.Many2many( + 'account.account', + string='Filter on accounts', + default=_get_account_ids, + help="Only selected accounts will be printed. Leave empty to " + "print all accounts.") + journal_ids = fields.Many2many( + 'account.journal', + string='Filter on jourvals', + help="Only selected journals will be printed. Leave empty to " + "print all journals.") + balance_mode = fields.Selection( + [('initial_balance', 'Initial balance'), + ('opening_balance', 'Opening balance')] + ) + display_account = fields.Char() + display_ledger_lines = fields.Boolean() + display_initial_balance = fields.Boolean() + + MAPPING = { + 'date_from': 'start_date', + 'date_to': 'end_date', + } + + @api.model + def _get_values_from_wizard(self, data): + """ Get values from wizard """ + values = {} + for key, val in data.iteritems(): + if key in self.MAPPING: + values[self.MAPPING[key]] = val + elif key == 'fiscalyear': + if val: + values[key] = val[0] + elif key == 'journal_ids': + if val: + values[key] = [(6, 0, val)] + else: + values[key] = val + return values + + @api.multi + def _get_centralized_move_ids(self, domain): + """ Get last line of each selected centralized accounts """ + # inverse search on centralized boolean to finish the search to get the + # ids of last lines of centralized accounts + # XXX USE DISTINCT to speed up ? + domain = domain[:] + centralize_index = domain.index(('centralized', '=', False)) + domain[centralize_index] = ('centralized', '=', True) + + gl_lines = self.env['general.ledger.line'].search(domain) + accounts = gl_lines.mapped('account_id') + + line_ids = [] + for acc in accounts: + acc_lines = gl_lines.filtered(lambda rec: rec.account_id == acc) + line_ids.append(acc_lines[-1].id) + return line_ids + + @api.multi + def _get_moves_from_dates(self): + domain = self._get_moves_from_dates_domain() + if self.centralize: + centralized_ids = self._get_centralized_move_ids(domain) + if centralized_ids: + domain.insert(0, '|') + domain.append(('id', 'in', centralized_ids)) + return self.env['general.ledger.line'].search(domain) + + @api.multi + def render_html(self, data=None): + report_name = 'account.report_generalledger_qweb' + if data is None: + return + values = self._get_values_from_wizard(data['form']) + report = self.create(values) + + report_lines = report._get_moves_from_dates() + # TODO warning if no report_lines + self.env['report']._get_report_from_name(report_name) + + docargs = { + 'doc_ids': report.ids, + 'doc_model': self._name, + 'report_lines': report_lines, + 'docs': report, + # XXX + 'has_currency': True + } + return self.env['report'].render(report_name, docargs) diff --git a/account_financial_report_qweb/report/templates/general_ledger.xml b/account_financial_report_qweb/report/templates/general_ledger.xml new file mode 100644 index 00000000..55c19c0b --- /dev/null +++ b/account_financial_report_qweb/report/templates/general_ledger.xml @@ -0,0 +1,293 @@ + + + + + + diff --git a/account_financial_report_qweb/reports.xml b/account_financial_report_qweb/reports.xml new file mode 100644 index 00000000..25d38d78 --- /dev/null +++ b/account_financial_report_qweb/reports.xml @@ -0,0 +1,15 @@ + + + + + + + + diff --git a/account_financial_report_qweb/wizard/general_ledger_wizard.xml b/account_financial_report_qweb/wizard/general_ledger_wizard.xml new file mode 100644 index 00000000..0c54a422 --- /dev/null +++ b/account_financial_report_qweb/wizard/general_ledger_wizard.xml @@ -0,0 +1,52 @@ + + + + + + + General Ledger + ledger.report.wizard + +
+ + + + + + + + + + + + + + + + + + + +
+ + + General Ledger + ir.actions.act_window + ledger.report.wizard + form + form + + new + + +
+
diff --git a/account_financial_report_qweb/wizard/ledger_report_wizard.py b/account_financial_report_qweb/wizard/ledger_report_wizard.py index 73f410d1..4237d9ae 100644 --- a/account_financial_report_qweb/wizard/ledger_report_wizard.py +++ b/account_financial_report_qweb/wizard/ledger_report_wizard.py @@ -8,7 +8,7 @@ from openerp import models, fields, api class LedgerReportWizard(models.TransientModel): _name = "ledger.report.wizard" - _description = "Ledger Report" + _description = "Ledger Report Wizard" company_id = fields.Many2one(comodel_name='res.company') # date_range = ?? @@ -40,5 +40,5 @@ class LedgerReportWizard(models.TransientModel): ) @api.multi - def check_report(self): + def button_print(self): return True diff --git a/account_financial_report_qweb/wizard/ledger_report_wizard_view.xml b/account_financial_report_qweb/wizard/partner_ledger_wizard.xml similarity index 51% rename from account_financial_report_qweb/wizard/ledger_report_wizard_view.xml rename to account_financial_report_qweb/wizard/partner_ledger_wizard.xml index 5b317626..f00141de 100644 --- a/account_financial_report_qweb/wizard/ledger_report_wizard_view.xml +++ b/account_financial_report_qweb/wizard/partner_ledger_wizard.xml @@ -2,58 +2,6 @@ - - - Ledger - ledger.report.wizard - -
- - - - - - - - - - - - - - - - - - - -
- - - Ledger - ir.actions.act_window - ledger.report.wizard - form - form - - new - - - - - Partner Ledger @@ -84,7 +32,7 @@