diff --git a/account_partner_aged_statement_webkit/__openerp__.py b/account_partner_aged_statement_webkit/__openerp__.py index 7ee8c585..969710ae 100644 --- a/account_partner_aged_statement_webkit/__openerp__.py +++ b/account_partner_aged_statement_webkit/__openerp__.py @@ -26,6 +26,8 @@ 'author': 'Savoir-faire Linux', 'website': 'http://www.savoirfairelinux.com', 'depends': [ + 'report_webkit', + 'base_headers_webkit', 'mail', 'account', ], @@ -36,16 +38,20 @@ Print & Send Partner Aged Statement by email This module adds in the system : * a new mail template "Aged Statement Letter"; - * the abitlity to print the partner aged statement; - * a button "Send by email" in the pricelist form view which load the template - and attache the pricelist to the email. + * the ability to print the partner aged statement; + * a button "Send by email" in the partner form view which load the template + and attach the statement to the email. -So far the module does not drill down through pricelist items that are -based on another pricelist or based on purchase pricelists. +Comparing to 'Overdue Payment' report provided with OpenERP, this one adds more +informations : + * the summary per period + * the list of invoices per period + * the invoices are also shown with the foreign currency Contributors ------------ * Marc Cassuto (marc.cassuto@savoirfairelinux.com) +* Vincent Vinet (vincent.vinet@savoirfairelinux.com) """, 'data': [ 'partner_aged_statement_report.xml', 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 3a6aa819..9c6c7b54 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 @@ - + @@ -10,11 +10,9 @@ ${(user.email or '')|safe} ${object.company_id.name} - Your aged balance ${object.id or ''|safe} - + - + ${(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 0b51f364..439a803e 100644 --- a/account_partner_aged_statement_webkit/partner_aged_statement_report.xml +++ b/account_partner_aged_statement_webkit/partner_aged_statement_report.xml @@ -6,11 +6,16 @@ auto="False" id="partner_aged_statement_report" model="res.partner" - name="account.aged_trial_balance_partner" - file="account/report/account_aged_partner_balance.rml" string="Partner Aged Statement" - report_type="pdf" + name="webkit.partner_aged_statement_report" + file="account_partner_aged_statement_webkit/report/partner_aged_statement.mako" + report_type="webkit" + webkit_header="base_headers_webkit.base_reports_portrait_header" /> + + diff --git a/account_partner_aged_statement_webkit/report/partner_aged_statement.mako b/account_partner_aged_statement_webkit/report/partner_aged_statement.mako index 7bc1cc1a..472b06fc 100644 --- a/account_partner_aged_statement_webkit/report/partner_aged_statement.mako +++ b/account_partner_aged_statement_webkit/report/partner_aged_statement.mako @@ -25,14 +25,10 @@ .classif_title { text-align:right; } -<%doc> - .classif{ - width: ${700/len(ranges)}px; - } - .total{ font-weight:bold; } + ${css} @@ -43,122 +39,144 @@ return text.replace('-', '‑') %> - <%setLang(user.lang)%> - -
-
-
${_('Chart of Account')}
-
${_('Fiscal Year')}
- <%doc> -
- %if filter_form(data) == 'filter_date': - ${_('Dates Filter')} - %else: - ${_('Periods Filter')} - %endif -
- - -
${_('Clearance Date')}
-
${_('Accounts Filter')}
-
${_('Target Moves')}
- -
- - <%doc> -
-
${ chart_account.name }
-
${ fiscalyear.name if fiscalyear else '-' }
-
- ${_('From:')} - %if filter_form(data) == 'filter_date': - ${formatLang(start_date, date=True) if start_date else u'' } - %else: - ${start_period.name if start_period else u''} - %endif - ${_('To:')} - %if filter_form(data) == 'filter_date': - ${ formatLang(stop_date, date=True) if stop_date else u'' } - %else: - ${stop_period.name if stop_period else u'' } - %endif -
-
${ formatLang(date_until, date=True) }
-
- %if partner_ids: - ${_('Custom Filter')} - %else: - ${ display_partner_account(data) } - %endif -
-
${ display_target_move(data) }
-
-
- %for acc in objects: - %if acc.aged_lines: -
${acc.code} - ${acc.name}
- - - -
-
-
- ## partner -
${_('Partner')}
- ## code -
${_('code')}
- ## balance -
${_('balance')}
- ## Classifications - %for title in ranges_titles: -
${title}
- %endfor -
-
-
- %for partner_name, p_id, p_ref, p_name in acc.partners_order: - %if acc.aged_lines.get(p_id): -
- <%line = acc.aged_lines[p_id]%> - <%percents = acc.aged_percents%> - <%totals = acc.aged_totals%> -
${partner_name}
-
${p_ref or ''}
- -
${formatLang(line.get('balance') or 0.0) | amount}
- %for classif in ranges: -
- ${formatLang(line['aged_lines'][classif] or 0.0) | amount} -
- %endfor -
- %endif - %endfor -
-
${_('Total')}
-
-
${formatLang(totals['balance']) | amount}
- %for classif in ranges: -
${formatLang(totals[classif]) | amount}
- %endfor -
- -
-
${_('Percents')}
-
-
- %for classif in ranges: -
${formatLang(percents[classif]) | amount}%
- %endfor -
-
-
- - %endif - %endfor - - - -
+ %for partner in objects: + <%setLang(partner.lang)%> +
+
+ <%from datetime import date %> + ${_('Date')}: ${formatLang(str(date.today()), date=True)} +
+ ${_('Partner')}: ${partner.name} +
+ ${_('Subject')}: ${_('Overdue Statement')} +
+
+ %for message_line in message(partner, company): +

+ ${message_line} +

+ %endfor +
+ ${user.name} +
+
+ %if (partner.credit + partner.debit == 0) : +
${_('Nothing due for this partner')}
+ %else: +
${_('Aged Balance')}
+
+ %for l in get_lines(data['form']): + %if l: + + + + + + + + + + + + + + + + + + + +
${_('Not Due')}${_('0-30')}${_('30-60')}${_('60-90')}${_('90-120')}${_('+120')}${_('Total')}
${ formatLang(l['direction'], currency_obj=company.currency_id) }${ formatLang(l['4'], currency_obj=company.currency_id) }${ formatLang(l['3'], currency_obj=company.currency_id) }${ formatLang(l['2'], currency_obj=company.currency_id) }${ formatLang(l['1'], currency_obj=company.currency_id) }${ formatLang(l['0'], currency_obj=company.currency_id) }${ formatLang(l['total'], currency_obj=company.currency_id) }
+ %endif ## if l + %endfor ## for l in get_lines(data['form']) +
+
+
${_('List of Due Invoices')}
+
+ %if getLines30(partner): +
${_('0-30')}
+ + + + + + + + + + + + %for line in getLines30(partner): + + + + + + + + + + + %endfor ## for line in getLines30(partner) +
${_('Date')}${_('Description')}${_('Reference')}${_('Due date')}${_('Amount')}${_('Paid')}${_('Total')}
(${company.currency_id.name})
${_('Total')}
(fgn. cur.)
${ formatLang(line.date, date=True) }${ line.name }${ line.ref }${ line.date_maturity and formatLang(line.date_maturity,date=True) or '' }${ formatLang(line.debit) or 0 }${ formatLang(line.credit) or 0 }${ formatLang(line.debit - line.credit, currency_obj = company.currency_id) }${ line.amount_currency and formatLang(line.amount_currency, currency_obj = line.currency_id) or '' }
+ %endif ## if getLines30(partner) +
+ %if getLines3060(partner): +
${_('30-60')}
+ + + + + + + + + + + + %for line in getLines3060(partner): + + + + + + + + + + + %endfor ## for line in getLines3060(partner) +
${_('Date')}${_('Description')}${_('Reference')}${_('Due date')}${_('Amount')}${_('Paid')}${_('Total')}
(${company.currency_id.name})
${_('Total')}
(fgn. cur.)
${ formatLang(line.date, date=True) }${ line.name }${ line.ref }${ line.date_maturity and formatLang(line.date_maturity,date=True) or '' }${ formatLang(line.debit) or 0 }${ formatLang(line.credit) or 0 }${ formatLang(line.debit - line.credit, currency_obj = company.currency_id) }${ line.amount_currency and formatLang(line.amount_currency, currency_obj = line.currency_id) or '' }
+ %endif ## if getLines3060(partner) +
+ %if getLines60(partner): +
${_('+60')}
+ + + + + + + + + + + + %for line in getLines60(partner): + + + + + + + + + + + %endfor ## for line in getLines60(partner) +
${_('Date')}${_('Description')}${_('Reference')}${_('Due date')}${_('Amount')}${_('Paid')}${_('Total')}
(${company.currency_id.name})
${_('Total')}
(fgn. cur.)
${ formatLang(line.date, date=True) }${ line.name }${ line.ref }${ line.date_maturity and formatLang(line.date_maturity,date=True) or '' }${ formatLang(line.debit) or 0 }${ formatLang(line.credit) or 0 }${ formatLang(line.debit - line.credit, currency_obj = company.currency_id) }${ line.amount_currency and formatLang(line.amount_currency, currency_obj = line.currency_id) or '' }
+ %endif ## if getLines60(partner) + %endif ## if (partner.credit + partner.debit == 0) + %endfor ## for partner in objects 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 1e234bb8..791286ed 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 @@ -1,6 +1,9 @@ # -*- encoding: utf-8 -*- - -# ############################################################################## +############################################################################### +# +# OpenERP, Open Source Management Solution +# This module copyright (C) 2010 - 2014 Savoir-faire Linux +# (). # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as @@ -17,7 +20,6 @@ # ############################################################################### - import time from datetime import datetime @@ -40,16 +42,80 @@ class PartnerAgedTrialReport(aged_trial_report): self._company = current_user.company_id if self.localcontext.get("active_model", "") == "res.partner": self._partner = self.localcontext["active_id"] + self.localcontext.update({ + 'message': self._message, + 'getLines30': self._lines_get30, + 'getLines3060': self._lines_get_30_60, + 'getLines60': self._lines_get60, + }) + + def _lines_get30(self, obj): + today = datetime.now() + stop = today - relativedelta(days=30) + + moveline_obj = pooler.get_pool(self.cr.dbname)['account.move.line'] + movelines = moveline_obj.search( + self.cr, self.uid, + [('partner_id', '=', obj.id), + ('account_id.type', 'in', ['receivable', 'payable']), + ('state', '<>', 'draft'), ('reconcile_id', '=', False), + '|', + '&', ('date_maturity', '<=', today), ('date_maturity', '>', stop), + '&', ('date_maturity', '=', False), + '&', ('date', '<=', today), ('date', '>', stop)], + context=self.localcontext) + movelines = moveline_obj.browse(self.cr, self.uid, movelines) + return movelines + + def _lines_get_30_60(self, obj): + start = datetime.now() - relativedelta(days=30) + stop = start - relativedelta(days=30) + + moveline_obj = pooler.get_pool(self.cr.dbname)['account.move.line'] + movelines = moveline_obj.search( + self.cr, self.uid, + [('partner_id', '=', obj.id), + ('account_id.type', 'in', ['receivable', 'payable']), + ('state', '<>', 'draft'), ('reconcile_id', '=', False), + '|', + '&', ('date_maturity', '<=', start), ('date_maturity', '>', stop), + '&', ('date_maturity', '=', False), + '&', ('date', '<=', start), ('date', '>', stop)], + context=self.localcontext) + movelines = moveline_obj.browse(self.cr, self.uid, movelines) + return movelines + + def _lines_get60(self, obj): + start = datetime.now() - relativedelta(days=60) + + moveline_obj = pooler.get_pool(self.cr.dbname)['account.move.line'] + movelines = moveline_obj.search( + self.cr, self.uid, + [('partner_id', '=', obj.id), + ('account_id.type', 'in', ['receivable', 'payable']), + ('state', '<>', 'draft'), ('reconcile_id', '=', False), + '|', ('date_maturity', '<=', start), + ('date_maturity', '=', False), ('date', '<=', start)], + context=self.localcontext) + movelines = moveline_obj.browse(self.cr, self.uid, movelines) + return movelines + + def _message(self, obj, company): + company_pool = pooler.get_pool(self.cr.dbname)['res.company'] + message = company_pool.browse( + self.cr, self.uid, company.id, {'lang': obj.lang}).overdue_msg + return message.split('\n') def _get_fiscalyear(self, data): - now = data['form']['date_from'] + now = data['fInvoicesorm']['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) + fiscalyears_obj = pooler.get_pool(self.cr.dbname)['account.fiscalyear'] + fiscalyears = fiscalyears_obj.search( + self.cr, self.uid, domain, limit=1, context=self.localcontext) if fiscalyears: return fiscalyears_obj.browse( self.cr, self.uid, fiscalyears[0], context=self.localcontext @@ -62,12 +128,11 @@ class PartnerAgedTrialReport(aged_trial_report): accounts = account_obj.search( self.cr, self.uid, [('parent_id', '=', False), ('company_id', '=', self._company.id)], - limit=1, - ) + limit=1, context=self.localcontext) if accounts: return account_obj.browse( - self.cr, self.uid, accounts[0], context=self.localcontext - ).name + self.cr, self.uid, accounts[0], + context=self.localcontext).name else: return '' @@ -77,7 +142,10 @@ class PartnerAgedTrialReport(aged_trial_report): 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']),)) + 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 @@ -110,13 +178,18 @@ class PartnerAgedTrialReport(aged_trial_report): 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) + self.query = "{0} AND l.partner_id = {1}".format( + self.query, + self._partner) return res report_sxw.report_sxw( - 'report.account.aged_trial_balance_partner', + 'report.webkit.partner_aged_statement_report', 'res.partner', - 'addons/account/report/account_aged_partner_balance.rml', + ('addons/' + 'account_partner_aged_statement_webkit/' + 'report/' + 'partner_aged_statement.mako'), parser=PartnerAgedTrialReport, - header="internal landscape") +)