From cb0547b3820748af4ce9c493175c0bf66e022fa0 Mon Sep 17 00:00:00 2001 From: jbeficent Date: Sun, 15 May 2016 16:15:16 +0200 Subject: [PATCH] [IMP] improvements on open invoice report. --- .../report/open_invoice.py | 39 +++- .../report/templates/open_invoice_report.xml | 210 ++++++++++++------ .../static/src/css/report.css | 14 +- .../wizard/open_invoice_wizard.py | 95 ++------ .../wizard/open_invoice_wizard_view.xml | 2 - 5 files changed, 204 insertions(+), 156 deletions(-) diff --git a/account_financial_report_qweb/report/open_invoice.py b/account_financial_report_qweb/report/open_invoice.py index a652d1a0..6f1d0e9c 100644 --- a/account_financial_report_qweb/report/open_invoice.py +++ b/account_financial_report_qweb/report/open_invoice.py @@ -13,17 +13,46 @@ class OpenInvoiceReport(models.AbstractModel): _name = 'report.account_financial_report_qweb.open_invoice_report_qweb' + def _get_domain(self, data): + account_type = ('payable', 'receivable') + if data['form']['result_selection'] == 'customer': + account_type = ('receivable', ) + elif data['form']['result_selection'] == 'supplier': + account_type = ('payable', ) + domain = [ + ('company_id', '=', data['form']['company_id'][0]), + ('move_id.date', '<=', data['form']['at_date']), + ('account_id.user_type_id.type', 'in', account_type) + ] + if data['form']['target_move'] != 'all': + domain.append(('move_id.state', 'in', ('posted', )), ) + if data['form']['partner_ids']: + domain.append(('partner_id', 'in', + [p.id for p in data['form']['partner_ids']]), ) + return domain + + def _query(self, data): + + moves = self.env['account.move.line'].search( + self._get_domain(data), order='date asc') + if not moves: + return True # ----- Show a message here + return moves + @api.multi def render_html(self, data=None): report_obj = self.env['report'] - doc_ids = self._ids + moves = self._query(data) docargs = { 'doc_model': 'account.move.line', - 'doc_ids': doc_ids, - 'sorted': sorted, + 'doc_ids': data['ids'], + 'docs': moves, + 'header': data['header'], + 'account_obj': self.env['account.account'], + 'partner_obj': self.env['res.partner'], + 'currency_obj': self.env['res.currency'], } - if data: - docargs.update(data) + return report_obj.render( 'account_financial_report_qweb.open_invoice_report_qweb', docargs) diff --git a/account_financial_report_qweb/report/templates/open_invoice_report.xml b/account_financial_report_qweb/report/templates/open_invoice_report.xml index 5c010828..0ef4c6fc 100644 --- a/account_financial_report_qweb/report/templates/open_invoice_report.xml +++ b/account_financial_report_qweb/report/templates/open_invoice_report.xml @@ -47,97 +47,163 @@
-
-
-
-
+
+
+
+
- - + + + - - + + + -
-
-
-
Date
-
Entry
-
Journal
-
Partner
-
Reference
-
Label
-
Rec.
-
Due Date
-
Debit
-
Credit
-
Cumul.Bal.
+ + + + + + + + + + + + + + +
+
+
+
Date
+
Entry
+
Journal
+
Partner
+
Reference
+
Label
+
Rec.
+
Due Date
+
Debit
+
Credit
+
Cum. Balance
+ +
Curr. amount
+
Cum. Curr. Bal.
+
+
+
+
+ + +
+
+
+
+
+
+
+ - +
+
+
+ + + + + + + +
+
+
+ +
+
+
+
+
-
- + +
-
-
-
-
-
-
-
-
- - - - - - -
-
-
+
+
+
+
+
+
+
+
+
+
+
+ +
- -
-
-
-
-
-
-
-
-
Comulate Balance on Partner
-
-
-
-
-
-
- -
-
-
-
-
Comulate Balance
-
-
-
-
-
-
+
+ + +
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+ +
+
+
+
+
-
diff --git a/account_financial_report_qweb/static/src/css/report.css b/account_financial_report_qweb/static/src/css/report.css index 96650687..8c959955 100644 --- a/account_financial_report_qweb/static/src/css/report.css +++ b/account_financial_report_qweb/static/src/css/report.css @@ -18,14 +18,14 @@ body, table, td, span, div { .act_as_tbody { display: table-row-group !important; } -.list_table, .data_table { +.list_table, .data_table, .totals_table{ width: 100% !important; table-layout: fixed !important; } .act_as_row.labels { background-color:#F0F0F0 !important; } -.list_table, .data_table, .list_table .act_as_row { +.list_table, .data_table, .totals_table, .list_table .act_as_row { border-left:0px; border-right:0px; text-align:left; @@ -36,18 +36,22 @@ body, table, td, span, div { padding-bottom:2px; border-collapse:collapse; } +.totals_table { + font-weight: bold; + text-align: center; +} .list_table .act_as_row.labels, .list_table .act_as_row.initial_balance, .list_table .act_as_row.lines { border-color:grey !important; border-bottom:1px solid lightGrey !important; } -.data_table .act_as_cell { +.data_table .act_as_cell{ border: 1px solid lightGrey; text-align: center; } -.data_table .act_as_cell, .list_table .act_as_cell { +.data_table .act_as_cell, .list_table .act_as_cell, .totals_table .act_as_cell { word-wrap: break-word; } -.data_table .act_as_row.labels { +.data_table .act_as_row.labels, .totals_table .act_as_row.labels { font-weight: bold; } .initial_balance .act_as_cell { diff --git a/account_financial_report_qweb/wizard/open_invoice_wizard.py b/account_financial_report_qweb/wizard/open_invoice_wizard.py index 3453740c..0b655cc7 100644 --- a/account_financial_report_qweb/wizard/open_invoice_wizard.py +++ b/account_financial_report_qweb/wizard/open_invoice_wizard.py @@ -22,10 +22,6 @@ class OpenInvoiceWizard(models.TransientModel): default=fields.Date.to_string(datetime.today())) partner_ids = fields.Many2many( 'res.partner', string='Filter partners') - amount_currency = fields.Boolean( - "With Currency", help="It adds the currency column") - group_by_currency = fields.Boolean( - "Group Partner by currency", help="It adds the currency column") result_selection = fields.Selection([ ('customer', 'Receivable Accounts'), ('supplier', 'Payable Accounts'), @@ -35,16 +31,6 @@ class OpenInvoiceWizard(models.TransientModel): ('posted', 'All Posted Entries'), ('all', 'All Entries')], 'Target Moves', required=True, default='all') - until_date = fields.Date( - "Clearance date", - help="""The clearance date is essentially a tool used for debtors - provisionning calculation. - By default, this date is equal to the the end date ( - ie: 31/12/2011 if you select fy 2011). - By amending the clearance date, you will be, for instance, - able to answer the question : 'based on my last - year end debtors open invoices, which invoices are still - unpaid today (today is my clearance date)?'""") @api.onchange('at_date') def onchange_atdate(self): @@ -58,64 +44,12 @@ class OpenInvoiceWizard(models.TransientModel): raise UserError( 'Until Date must be equal or greater than At Date') - @staticmethod - def _get_domain(data): - account_type = ('payable', 'receivable') - if data['result_selection'] == 'customer': - account_type = ('receivable', ) - elif data['result_selection'] == 'supplier': - account_type = ('payable', ) - domain = [ - ('company_id', '=', data['company_id'].id), - ('move_id.date', '<=', data['at_date']), - ('account_id.user_type_id.type', 'in', account_type) - ] - if data['target_move'] != 'all': - domain.append(('move_id.state', 'in', ('posted', )), ) - if data['partner_ids']: - domain.append(('partner_id', 'in', [p.id - for p - in data['partner_ids']]), ) - return domain + def _build_contexts(self, data): + result = {} + return result - @staticmethod - def _get_move_line_data(move): - label = move.name - if move.invoice_id: - label = '{label} ({inv_nummber})'.format( - label=label, inv_nummber=move.invoice_id.number) + def _build_header(self): return { - 'date': move.date, - 'entry': move.move_id.name, - 'journal': move.move_id.journal_id.code, - 'reference': move.ref, - 'label': label, - 'rec': move.full_reconcile_id.name, - 'due_date': move.date_maturity, - 'debit': move.debit, - 'credit': move.credit, - } - - @api.multi - def print_report(self): - self.ensure_one() - moves = self.env['account.move.line'].search( - self._get_domain(self), order='date asc') - if not moves: - return True # ----- Show a message here - datas = {} - for move in moves: - account = '{code} - {name}'.format( - code=move.account_id.code, - name=move.account_id.name) - partner = move.partner_id.name - if account not in datas: - datas[account] = {} - if partner not in datas[account]: - datas[account][partner] = [] - datas[account][partner].append( - self._get_move_line_data(move)) - generals = { 'company': self.company_id.name, 'fiscal_year': '', 'at_date': self.at_date, @@ -124,7 +58,24 @@ class OpenInvoiceWizard(models.TransientModel): self.result_selection], 'target_moves': dict( self._columns['target_move'].selection)[self.target_move], - } + } + + def _get_form_fields(self): + return self.read(['company_id', 'at_date', 'partner_ids', + 'result_selection', 'target_move', + 'until_date'])[0] + + @api.multi + def print_report(self): + self.ensure_one() + data = {} + data['ids'] = self.env.context.get('active_ids', []) + data['model'] = self.env.context.get('active_model', 'ir.ui.menu') + data['form'] = self._get_form_fields() + used_context = self._build_contexts(data) + data['form']['used_context'] = dict( + used_context, lang=self.env.context.get('lang', 'en_US')) + data['header'] = self._build_header() return self.env['report'].get_action( self, 'account_financial_report_qweb.open_invoice_report_qweb', - data={'data': datas, 'general': generals}) + data=data) diff --git a/account_financial_report_qweb/wizard/open_invoice_wizard_view.xml b/account_financial_report_qweb/wizard/open_invoice_wizard_view.xml index 261d0561..84c7eb02 100644 --- a/account_financial_report_qweb/wizard/open_invoice_wizard_view.xml +++ b/account_financial_report_qweb/wizard/open_invoice_wizard_view.xml @@ -17,8 +17,6 @@ - -