I created a custom module that computes total invoice from each customer or supplier payment voucher. It returns an error whenever I call the report.
QWebException: unexpected EOF while parsing (, line 1)
module: module_pdc
models/outstanding_pdc.py
from openerp import fields, api, models, exceptions
from datetime import datetime
from openerp.tools.translate import _
import openerp.addons.decimal_precision as dp
class AccountOutstandingPostDatedCheck(models.Model):
_name = 'account.post.dated.check.outstanding'
_description = 'Outstanding Receivable'
name = fields.Char(string='Reference No.')
is_customer = fields.Boolean('Customers')
is_supplier = fields.Boolean('Suppliers')
outstanding_pdc_line_ids = fields.One2many('account.post.dated.check.outstanding.line', 'outstanding_line_id', 'Outstanding Receivable Line')
@api.model
def create(self, values):
sequence_obj = self.env['ir.sequence']
values.update({'name' : sequence_obj.next_by_code('pdc.outstanding.ref')})
return super(AccountOutstandingPostDatedCheck,self).create(values)
@api.multi
def check_outstanding_pdc(self):
customer = self.is_customer
supplier = self.is_supplier
# Create object classes to access records.
account_voucher = self.env['account.voucher']
outstanding_pdc_line_ids = self.env['account.post.dated.check.outstanding.line']
# Clear the list before execution of the main process:
if self.outstanding_pdc_line_ids.ids != []:
self.outstanding_pdc_line_ids.unlink()
#Search the voucher within the selected period
date_today = datetime.now().date()
date_today = date_today.strftime("%Y-%m-%d")
pdc_vouchers = []
if customer and supplier:
raise exceptions.ValidationError(_('Select only one partner.'))
if not customer and not supplier:
raise exceptions.ValidationError(_('Select one partner.'))
elif customer:
pdc_vouchers = account_voucher.search([('post_dated', '=', True), ('state','=','posted'), ('partner_id.customer', '=', True), ('payment_details.type', '=', 'check'), ('payment_details.date_due', '>', date_today)])
elif supplier:
pdc_vouchers = account_voucher.search([('post_dated', '=', True), ('state','=','posted'), ('partner_id.supplier', '=', True), ('payment_details.type', '=', 'check'), ('payment_details.date_due', '>', date_today)])
# Loop through each Voucher and collect its Partner Ids.
partners = []
for voucher in pdc_vouchers:
if voucher.partner_id not in partners: partners.append(voucher.partner_id)
receivable = 0.00
envelope = 0.00
pdc = 0.00
for partner in partners:
for pdc_voucher in pdc_vouchers:
if pdc_voucher.partner_id == partner:
for voucher_line in pdc_voucher.line_ids:
receivable += voucher_line.amount_original
if not voucher_line.move_line_id.invoice.reconciled:
envelope += voucher_line.move_line_id.invoice.residual
pdc = receivable - envelope
vals = {
'outstanding_line_id' : self.ids[0],
'partner_id': partner.id,
'receivable': receivable,
'pdc': pdc,
'envelope': envelope
}
receivable = 0.00
envelope = 0.00
pdc = 0.00
outstanding_pdc_line_ids.create(vals)
class AccountPostDatedCheckOutstandingLine(models.Model):
_name = "account.post.dated.check.outstanding.line"
_description = "Outstanding Receivable Line"
outstanding_line_id = fields.Many2one('account.post.dated.check.outstanding', 'Outstanding Receivable Line')
partner_id = fields.Many2one('res.partner', 'Partner')
receivable = fields.Float('Receivable')
pdc= fields.Float('PDC')
envelope = fields.Float('Envelope')
views/report_outstanding_pdc_layout.xml
<?xml version="1.0" encoding="UTF-8" ?>
<openerp>
<data>
<template id="outstanding_pdc_header">
<div class="header">
<div class="row" style="text-align:center;">
<div class="col-xs-12">
<br/>
<h2>Outstanding Receivable</h2>
<t t-if="o.outstanding_pdc_line_ids.partner_id.customer">
<th>(Customers)</th>
</t>
<t t-if="o.outstanding_pdc_line_ids.partner_id.supplier">
<th>(Suppliers)</th>
</t>
</div>
</div>
</div>
</template>
<template id="outstanding_pdc_footer">
<div class="footer">
<div class="row">
<div class="col-xs-5">
<span t-esc="time.strftime('%A, %B %d, %Y')"/>
</div>
<div class="col-xs-3" style="text-right">
<![CDATA[ ]]>
</div>
<div class="col-xs-1">
<![CDATA[ ]]>
</div>
<div class="col-xs-3" style="text-right">
Page: <span class="page"/> of <span class="topage"/>
</div>
</div> `
</div>
</template>
<template id="outstanding_pdc_layout">
<t t-call="module_pdc.outstanding_pdc_header"/>
<t t-raw="0"/>
<t t-call="module_pdc.outstanding_pdc_footer"/>
</template>
</data>
</openerp>
views/report_outstanding_pdc.xml
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<template id="report_outstanding_pdc_document">
<t t-call="report.html_container">
<t t-foreach="docs" t-as="o">
<t t-call="module_pdc.outstanding_pdc_layout">
<div class="page">
<table class="table table-condensed">
<thead>
<tr>
<th class="col-xs-3">Name</th>
<th class="col-xs-3">Receivable</th>
<th class="col-xs-3">PDC</th>
<th class="col-xs-3">Envelope</th>
</tr>
</thead>
<tr t-foreach="o.outstanding_pdc_line_ids" t-as="or">
<td class="col-xs-3">
<span t-field="or.partner_id"/>
</td>
<td class="col-xs-3">
<span t-field="or.receivable"/>
</td>
<td class="col-xs-3">
<span t-field="or.pdc"/>
</td>
<td class="col-xs-3">
<span t-field="or.envelope"/>
</td>
</tr>
<t t-set="rec" t-value="0.00"/>
<t t-foreach="o.outstanding_pdc_line_ids" t-as="r">
<t t-set="rec" t-value="rec+r.receivable"/>
</t>
<t t-set="pd" t-value="0.00"/>
<t t-foreach="o.outstanding_pdc_line_ids" t-as="p">
<t t-set="pd" t-value="pd+p.pdc"/>
</t>
<t t-set="env" t-value="0.00"/>
<t t-foreach="o.outstanding_pdc_line_ids" t-as="e">
<t t-set="env" t-value="env+e.envelope"/>
</t>
<tr>
<th class="col-xs-3"><strong>Total:</strong></th>
<th class="col-xs-3" t-esc="rec"/>
<th class="col-xs-3" t-esc="pd"/>
<th class="col-xs-3" t-esc="env"/>
</tr>
</table>
</div>
</t>
</t>
</t>
</template>
</data>
</openerp>