From 9ff170c3ea39299b2b796ffde8f04f8ecba7159b Mon Sep 17 00:00:00 2001 From: Vincent Vinet Date: Tue, 5 Aug 2014 17:54:09 -0400 Subject: [PATCH] inherit the account module aging report while limiting to a partner --- .../__openerp__.py | 4 +- .../partner_aged_statement.py | 1 - .../partner_aged_statement_data.xml | 4 +- .../partner_aged_statement_report.xml | 19 +-- .../report/partner_aged_statement_report.py | 111 ++++++++++++++---- 5 files changed, 96 insertions(+), 43 deletions(-) diff --git a/account_partner_aged_statement_webkit/__openerp__.py b/account_partner_aged_statement_webkit/__openerp__.py index 59b0370b..7ee8c585 100644 --- a/account_partner_aged_statement_webkit/__openerp__.py +++ b/account_partner_aged_statement_webkit/__openerp__.py @@ -26,10 +26,8 @@ 'author': 'Savoir-faire Linux', 'website': 'http://www.savoirfairelinux.com', 'depends': [ - 'account_financial_report_webkit_xls', - 'report_webkit', - 'base_headers_webkit', 'mail', + 'account', ], 'category': 'Accounting', 'description': """ diff --git a/account_partner_aged_statement_webkit/partner_aged_statement.py b/account_partner_aged_statement_webkit/partner_aged_statement.py index 80ef5991..509f7383 100644 --- a/account_partner_aged_statement_webkit/partner_aged_statement.py +++ b/account_partner_aged_statement_webkit/partner_aged_statement.py @@ -20,7 +20,6 @@ # ############################################################################### -import time from openerp.osv import orm diff --git a/account_partner_aged_statement_webkit/partner_aged_statement_data.xml b/account_partner_aged_statement_webkit/partner_aged_statement_data.xml index 75673424..3a6aa819 100644 --- a/account_partner_aged_statement_webkit/partner_aged_statement_data.xml +++ b/account_partner_aged_statement_webkit/partner_aged_statement_data.xml @@ -2,7 +2,7 @@ - + @@ -13,10 +13,8 @@ - ${(object.name or '').replace('/','_')} diff --git a/account_partner_aged_statement_webkit/partner_aged_statement_report.xml b/account_partner_aged_statement_webkit/partner_aged_statement_report.xml index 9e7762c0..0b51f364 100644 --- a/account_partner_aged_statement_webkit/partner_aged_statement_report.xml +++ b/account_partner_aged_statement_webkit/partner_aged_statement_report.xml @@ -2,26 +2,15 @@ - - + report_type="pdf" + /> diff --git a/account_partner_aged_statement_webkit/report/partner_aged_statement_report.py b/account_partner_aged_statement_webkit/report/partner_aged_statement_report.py index f954697c..1e234bb8 100644 --- a/account_partner_aged_statement_webkit/report/partner_aged_statement_report.py +++ b/account_partner_aged_statement_webkit/report/partner_aged_statement_report.py @@ -19,35 +19,104 @@ import time -import operator -import itertools + +from datetime import datetime +from dateutil.relativedelta import relativedelta from openerp import pooler -from openerp.osv import orm from openerp.report import report_sxw -from openerp.tools.translate import _ -from openerp.addons.account_financial_report_webkit.report.aged_partner_balance import ( # noqa - AccountAgedTrialBalanceWebkit +from openerp.addons.account.report.account_aged_partner_balance import ( + aged_trial_report ) -class PartnerAgedStatementReport(report_sxw.rml_parse): +class PartnerAgedTrialReport(aged_trial_report): + _partner = None + def __init__(self, cr, uid, name, context): - super(PartnerAgedStatementReport, self).__init__(cr, uid, name, - context=context) - self.localcontext.update({ - 'time': time, - }) + super(PartnerAgedTrialReport, self).__init__(cr, uid, name, context) + current_user = self.localcontext["user"] + self._company = current_user.company_id + if self.localcontext.get("active_model", "") == "res.partner": + self._partner = self.localcontext["active_id"] + + def _get_fiscalyear(self, data): + now = data['form']['date_from'] + domain = [ + ('company_id', '=', self._company.id), + ('date_start', '<', now), + ('date_stop', '>', now), + ] + fiscalyears_obj = pooler.get_pool(self.cr.dbname).get('account.fiscalyear') + fiscalyears = fiscalyears_obj.search(self.cr, self.uid, domain, limit=1) + if fiscalyears: + return fiscalyears_obj.browse( + self.cr, self.uid, fiscalyears[0], context=self.localcontext + ).name + else: + return '' + + def _get_account(self, data): + account_obj = pooler.get_pool(self.cr.dbname).get('account.account') + accounts = account_obj.search( + self.cr, self.uid, + [('parent_id', '=', False), ('company_id', '=', self._company.id)], + limit=1, + ) + if accounts: + return account_obj.browse( + self.cr, self.uid, accounts[0], context=self.localcontext + ).name + else: + return '' + + def _get_company(self, data): + return self._company.name + + def _get_journal(self, data): + codes = [] + if data.get('form', False) and data['form'].get('journal_ids', False): + self.cr.execute('select code from account_journal where id IN %s', (tuple(data['form']['journal_ids']),)) + codes = [x for x, in self.cr.fetchall()] + return codes + + def _get_currency(self, data): + return self._company.currency_id.symbol + + def set_context(self, objects, data, ids, report_type=None): + period_length = 30 + form = { + "direction_selection": "past", + "period_length": period_length, + "result_selection": "customer", + "date_from": time.strftime("%Y-%m-%d"), + } + # Taken from 'account/wizard/account_report_aged_partner_balance.py + # which sets data from the form + start = datetime.now() + for i in range(4, -1, -1): + stop = start - relativedelta(days=period_length) + form[str(i)] = { + 'name': (i != 0 and "{0}-{1}".format( + 5 - (i + 1), (5 - i) * period_length, + ) or '+{0}'.format(4 * period_length)), + 'stop': start.strftime('%Y-%m-%d'), + 'start': (i != 0 and stop.strftime('%Y-%m-%d') or False), + } + start = stop - relativedelta(days=1) + + data["form"] = form + res = super(PartnerAgedTrialReport, self).set_context( + objects, data, ids, report_type=report_type) + if self._partner is not None: + self.query = "{0} AND l.partner_id = {1}".format(self.query, self._partner) + return res report_sxw.report_sxw( - 'report.webkit.partner_aged_statement_report', - 'account.account', - ('addons/' - 'account_partner_aged_statement_webkit/' - 'report/' - 'partner_aged_statement.mako'), - parser=PartnerAgedStatementReport) - -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: + 'report.account.aged_trial_balance_partner', + 'res.partner', + 'addons/account/report/account_aged_partner_balance.rml', + parser=PartnerAgedTrialReport, + header="internal landscape")