我创建了一个自定义模块,用于计算每个客户或供应商付款凭证的总发票。每当我调用报告时,它都会返回错误。
QWebException: unexpected EOF while parsing (, line 1)
模块:module_pdc
模型/优秀_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')
意见/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>