Browse Source

Add invoice refunds

pull/9/head
dufresnedavid 9 years ago
committed by Maxime Chambreuil
parent
commit
c1f9c351e2
  1. 20
      account_partner_aged_statement_webkit/i18n/account_partner_aged_statement_webkit.pot
  2. 20
      account_partner_aged_statement_webkit/i18n/fr.po
  3. 38
      account_partner_aged_statement_webkit/report/partner_aged_statement.mako
  4. 58
      account_partner_aged_statement_webkit/report/partner_aged_statement_report.py
  5. 3
      account_partner_aged_statement_webkit/report/supplier_aged_statement_report.py
  6. 37
      account_partner_aged_statement_webkit/tests/test_aged_statement.py

20
account_partner_aged_statement_webkit/i18n/account_partner_aged_statement_webkit.pot

@ -245,3 +245,23 @@ msgstr ""
#: report:addons/account_partner_aged_statement_webkit/report/partner_aged_statement.mako:0
msgid "List of overdue invoices"
msgstr ""
#. module: account_partner_aged_statement_webkit
#: report:addons/account_partner_aged_statement_webkit/report/partner_aged_statement.mako:0
msgid "Sum of Customer Refunds"
msgstr ""
#. module: account_partner_aged_statement_webkit
#: report:addons/account_partner_aged_statement_webkit/report/partner_aged_statement.mako:0
msgid "List of Customer Refunds"
msgstr ""
#. module: account_partner_aged_statement_webkit
#: report:addons/account_partner_aged_statement_webkit/report/partner_aged_statement.mako:0
msgid "Sum of Supplier Refunds"
msgstr ""
#. module: account_partner_aged_statement_webkit
#: report:addons/account_partner_aged_statement_webkit/report/partner_aged_statement.mako:0
msgid "List of Supplier Refunds"
msgstr ""

20
account_partner_aged_statement_webkit/i18n/fr.po

@ -297,3 +297,23 @@ msgstr "Courriel:"
#: model:ir.actions.report.xml,name:account_partner_aged_statement_webkit.supplier_aged_statement_report
msgid "Supplier Aged Statement"
msgstr "Relevé de balance âgée FRS"
#. module: account_partner_aged_statement_webkit
#: report:addons/account_partner_aged_statement_webkit/report/partner_aged_statement.mako:0
msgid "Sum of Customer Refunds"
msgstr "Somme des notes de crédit"
#. module: account_partner_aged_statement_webkit
#: report:addons/account_partner_aged_statement_webkit/report/partner_aged_statement.mako:0
msgid "List of Customer Refunds"
msgstr "Liste des notes de crédit"
#. module: account_partner_aged_statement_webkit
#: report:addons/account_partner_aged_statement_webkit/report/partner_aged_statement.mako:0
msgid "Sum of Supplier Refunds"
msgstr "Somme des notes de crédit"
#. module: account_partner_aged_statement_webkit
#: report:addons/account_partner_aged_statement_webkit/report/partner_aged_statement.mako:0
msgid "List of Supplier Refunds"
msgstr "Liste des notes de crédit"

38
account_partner_aged_statement_webkit/report/partner_aged_statement.mako

@ -82,6 +82,12 @@
<br/>
<br/>
%if get_refunds_total(partner, company):
<div>${_('Sum of Customer Refunds') if ttype == 'receipt' else _('Sum of Supplier Refunds')} : ${ get_refunds_total(partner, company) }</div>
<br/>
<br/>
%endif
%if getLinesCurrent(partner, company):
<div class="title">${_('List of current invoices')}</div>
<br/>
@ -170,6 +176,38 @@
%endfor ## for line in getLines60(partner, company)
</table>
%endif ## if getLines60(partner)
%if getLinesRefunds(partner, company):
<br/>
<br/>
<div class="title">${_('List of Customer Refunds') if ttype == 'receipt' else _('List of Supplier Refunds')}</div>
<br/>
<table class="basic_table" style="width: 100%;">
<tr>
<th>${_('Date')}</th>
<th>${_('Description')}</th>
<th>${_('Reference')}</th>
<th>${_('Due date')}</th>
<th>${_('Amount')}</th>
<th>${_('Paid')}</th>
<th>${_('Total')}</th>
<th>${_('Currency')}</th>
</tr>
%for line in getLinesRefunds(partner, company):
<tr>
<td>${ formatLang(line['date_original'], date=True) }</td>
<td>${ line['name'] }</td>
<td>${ line['ref'] }</td>
<td>${ line['date_due'] and formatLang(line['date_due'], date=True) or '' }</td>
<td style="text-align: right;">${ formatLang(line['amount_original']) }</td>
<td style="text-align: right;">${ formatLang(line['amount_original'] - line['amount_unreconciled']) }</td>
<td style="text-align: right;">${ formatLang(line['amount_unreconciled']) }</td>
<td>${ line['currency_name'] }</td>
</tr>
%endfor ## for line in getLinesCurrent(partner, company)
</table>
%endif ## if getLinesRefunds(partner, company)
%endif ## if (partner.credit + partner.debit == 0
%endfor ## for partner in objects
</body>

58
account_partner_aged_statement_webkit/report/partner_aged_statement_report.py

@ -44,18 +44,21 @@ class PartnerAgedTrialReport(aged_trial_report):
current_user = self.localcontext["user"]
self._company = current_user.company_id
if self.localcontext.get("active_model", "") == "res.partner":
self._partners = self.localcontext["active_ids"]
self._partner = self.localcontext["active_id"]
self.ttype = 'receipt'
self.localcontext.update({
'message': self._message,
'getLinesCurrent': self._lines_get_current,
'getLines3060': self._lines_get_30_60,
'getLines60': self._lines_get_60,
'getLinesRefunds': self._lines_get_refunds,
'show_message': True,
'get_current_invoice_lines': self._get_current_invoice_lines,
'get_balance': self._get_balance,
'get_refunds_total': self._refunds_total,
'ttype': self.ttype,
})
self.partner_invoices_dict = {}
self.ttype = 'receipt'
tz = self.localcontext.get('tz', False)
tz = tz and pytz.timezone(tz) or pytz.utc
self.today = datetime.now(tz)
@ -76,7 +79,11 @@ class PartnerAgedTrialReport(aged_trial_report):
date_90 = date_90.strftime(DEFAULT_SERVER_DATE_FORMAT)
date_120 = date_120.strftime(DEFAULT_SERVER_DATE_FORMAT)
movelines = self._get_current_invoice_lines(partner, company, today)
movelines = [
line for line in
self._get_current_invoice_lines(partner, company, today)
if line['type'] in ['in_invoice', 'out_invoice']
]
movelines = sorted(movelines, key=lambda x: x['currency_name'])
grouped_movelines = [
@ -147,12 +154,15 @@ class PartnerAgedTrialReport(aged_trial_report):
inv_obj = pool['account.invoice']
invoice_types = (
['out_invoice', 'out_refund'] if self.ttype == 'receipt'
else ['in_invoice', 'in_refund'])
invoice_ids = inv_obj.search(cr, uid, [
('state', '=', 'open'),
('company_id', '=', company.id),
('partner_id', '=', partner.id),
('type', '=', 'out_invoice'
if self.ttype == 'receipt' else 'in_invoice'),
('type', 'in', invoice_types),
], context=context)
invoices = inv_obj.browse(cr, uid, invoice_ids, context=context)
@ -168,6 +178,7 @@ class PartnerAgedTrialReport(aged_trial_report):
'name': inv.number,
'ref': inv.reference or '',
'id': inv.id,
'type': inv.type,
} for inv in invoices
], key=lambda inv: inv['date_original'])
@ -183,9 +194,13 @@ class PartnerAgedTrialReport(aged_trial_report):
movelines = self._get_current_invoice_lines(partner, company, today)
movelines = [
line for line in movelines
if not line['date_original'] or
line['date_original'] >= stop
if ((
not line['date_original'] or
line['date_original'] >= stop
) and line['type'] in ['in_invoice', 'out_invoice'])
]
print movelines
return movelines
def _lines_get_30_60(self, partner, company):
@ -200,8 +215,10 @@ class PartnerAgedTrialReport(aged_trial_report):
movelines = self._get_current_invoice_lines(partner, company, today)
movelines = [
line for line in movelines
if line['date_original'] and
stop < line['date_original'] <= start
if ((
line['date_original'] and
stop < line['date_original'] <= start
) and line['type'] in ['in_invoice', 'out_invoice'])
]
return movelines
@ -215,8 +232,27 @@ class PartnerAgedTrialReport(aged_trial_report):
movelines = self._get_current_invoice_lines(partner, company, today)
movelines = [
line for line in movelines
if line['date_original'] and
line['date_original'] <= start
if ((
line['date_original'] and
line['date_original'] <= start
) and line['type'] in ['in_invoice', 'out_invoice'])
]
return movelines
def _refunds_total(self, partner, company):
today = self.today
movelines = self._get_current_invoice_lines(partner, company, today)
return sum(
line['amount_unreconciled'] for line in movelines
if line['type'] in ['in_refund', 'out_refund']
)
def _lines_get_refunds(self, partner, company):
today = self.today
movelines = self._get_current_invoice_lines(partner, company, today)
movelines = [
line for line in movelines
if line['type'] in ['in_refund', 'out_refund']
]
return movelines

3
account_partner_aged_statement_webkit/report/supplier_aged_statement_report.py

@ -31,10 +31,11 @@ class SupplierAgedTrialReport(PartnerAgedTrialReport):
"""
def __init__(self, cr, uid, name, context):
super(SupplierAgedTrialReport, self).__init__(cr, uid, name, context)
self.ttype = 'payment'
self.localcontext.update({
'show_message': False,
'ttype': self.ttype,
})
self.ttype = 'payment'
WebKitParser(

37
account_partner_aged_statement_webkit/tests/test_aged_statement.py

@ -103,14 +103,17 @@ class test_aged_statement(common.TransactionCase):
'price_unit': invoice[1],
'quantity': 1,
})],
'type': invoice[2],
}, context=context)
for invoice in [
(self.today, 300),
(self.date1, 100),
(self.date2, 150),
(self.date3, 200),
(self.date4, 250),
(self.date5, 500),
(self.today, 300, 'out_invoice'),
(self.date1, 100, 'out_invoice'),
(self.date2, 150, 'out_invoice'),
(self.date3, 200, 'out_invoice'),
(self.date4, 250, 'out_invoice'),
(self.date5, 500, 'out_invoice'),
(self.date2, 600, 'out_refund'),
(self.date4, 700, 'out_refund'),
]
]
@ -193,3 +196,25 @@ class test_aged_statement(common.TransactionCase):
'amount_original': 200,
'amount_unreconciled': 200,
})
def test_line_get_refunds(self):
lines = sorted(
self.report._lines_get_refunds(self.partner, self.company),
key=lambda l: l['date_original'])
self.compare_vals(lines[0], {
'date_original': self.date4,
'amount_original': 700,
'amount_unreconciled': 700,
})
self.compare_vals(lines[1], {
'date_original': self.date2,
'amount_original': 600,
'amount_unreconciled': 600,
})
def test_refunds_total(self):
res = self.report._refunds_total(self.partner, self.company)
self.assertEqual(res, 1300)
Loading…
Cancel
Save