Browse Source

inherit the account module aging report while limiting to a partner

pull/9/head
Vincent Vinet 11 years ago
committed by Maxime Chambreuil
parent
commit
9ff170c3ea
  1. 4
      account_partner_aged_statement_webkit/__openerp__.py
  2. 1
      account_partner_aged_statement_webkit/partner_aged_statement.py
  3. 4
      account_partner_aged_statement_webkit/partner_aged_statement_data.xml
  4. 19
      account_partner_aged_statement_webkit/partner_aged_statement_report.xml
  5. 111
      account_partner_aged_statement_webkit/report/partner_aged_statement_report.py

4
account_partner_aged_statement_webkit/__openerp__.py

@ -26,10 +26,8 @@
'author': 'Savoir-faire Linux', 'author': 'Savoir-faire Linux',
'website': 'http://www.savoirfairelinux.com', 'website': 'http://www.savoirfairelinux.com',
'depends': [ 'depends': [
'account_financial_report_webkit_xls',
'report_webkit',
'base_headers_webkit',
'mail', 'mail',
'account',
], ],
'category': 'Accounting', 'category': 'Accounting',
'description': """ 'description': """

1
account_partner_aged_statement_webkit/partner_aged_statement.py

@ -20,7 +20,6 @@
# #
############################################################################### ###############################################################################
import time
from openerp.osv import orm from openerp.osv import orm

4
account_partner_aged_statement_webkit/partner_aged_statement_data.xml

@ -2,7 +2,7 @@
<openerp> <openerp>
<!-- Mail template is done in a NOUPDATE block <!-- Mail template is done in a NOUPDATE block
so users can freely customize/delete them --> so users can freely customize/delete them -->
<data noupdate="1">
<data noupdate="0">
<!--Email template --> <!--Email template -->
<record id="email_template_aged_statement" model="email.template"> <record id="email_template_aged_statement" model="email.template">
@ -13,10 +13,8 @@
<field name="model_id" <field name="model_id"
ref="account.model_res_partner"/> ref="account.model_res_partner"/>
<field name="auto_delete" eval="True"/> <field name="auto_delete" eval="True"/>
<!--
<field name="report_template" <field name="report_template"
ref="partner_aged_statement_report"/> ref="partner_aged_statement_report"/>
-->
<field name="report_name"> <field name="report_name">
${(object.name or '').replace('/','_')} ${(object.name or '').replace('/','_')}
</field> </field>

19
account_partner_aged_statement_webkit/partner_aged_statement_report.xml

@ -2,26 +2,15 @@
<openerp> <openerp>
<data> <data>
<!--
<report <report
auto="False" auto="False"
id="partner_aged_statement_report" id="partner_aged_statement_report"
model="res.partner" model="res.partner"
name="webkit.partner_aged_statement_report"
file="account_partner_aged_statement_webkit/report/partner_aged_statement.mako"
name="account.aged_trial_balance_partner"
file="account/report/account_aged_partner_balance.rml"
string="Partner Aged Statement" string="Partner Aged Statement"
webkit_header="base_headers_webkit.base_reports_portrait_header"
report_type="webkit"/>
-->
<report
auto="False"
id="partner_aged_statement_report"
model="res.partner"
name="webkit.partner_aged_statement_report"
file="account_partner_aged_statement_webkit/report/partner_aged_statement.mako"
string="Partner Aged Statement"
webkit_header="base_headers_webkit.base_reports_portrait_header"
report_type="webkit"/>
report_type="pdf"
/>
</data> </data>
</openerp> </openerp>

111
account_partner_aged_statement_webkit/report/partner_aged_statement_report.py

@ -19,35 +19,104 @@
import time import time
import operator
import itertools
from datetime import datetime
from dateutil.relativedelta import relativedelta
from openerp import pooler from openerp import pooler
from openerp.osv import orm
from openerp.report import report_sxw 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): 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_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")
Loading…
Cancel
Save