Replace the webkit report by a qweb one

This commit is contained in:
Guewen Baconnier
2014-10-29 14:52:33 +01:00
parent 0dfd7068af
commit c89896146c
13 changed files with 135 additions and 351 deletions

View File

@@ -26,5 +26,4 @@ from . import partner
from . import policy
from . import company
from . import wizard
from . import report
from . import invoice

View File

@@ -27,9 +27,10 @@
'depends': ['base',
'account',
'email_template',
'report_webkit'],
],
'website': 'http://www.camptocamp.com',
'data': ["report/report.xml",
"report/report_credit_control_summary.xml",
"data.xml",
"line_view.xml",
"account_view.xml",

View File

@@ -9,9 +9,9 @@
<field name="model_id" ref="model_credit_control_communication"/>
<field name="auto_delete" eval="True"/>
<field name="lang">${object.get_contact_address().lang or 'en_US'}</field>
<field name="report_template" ref="report_webkit_html"/>
<field name="report_template" ref="credit_control_summary"/>
<field name="body_html"><![CDATA[
Dear ${object.get_contact_address().name or ''}
Dear ${object.contact_address.name or ''}
<br/>
<br/>
${object.current_policy_level.custom_mail_text}

View File

@@ -181,7 +181,7 @@ class CreditControlPolicy(models.Model):
different_lines = move_line_obj.browse()
if not lines:
return different_lines
cr = self._cr
cr = self.env.cr
cr.execute("SELECT move_line_id FROM credit_control_line"
" WHERE policy_id != %s and move_line_id in %s"
" AND manually_overridden IS false",
@@ -322,7 +322,7 @@ class CreditControlPolicyLevel(models.Model):
move_line_obj = self.env['account.move.line']
if not lines:
return move_line_obj.browse()
cr = self._cr
cr = self.env.cr
sql = ("SELECT DISTINCT mv_line.id\n"
" FROM account_move_line mv_line\n"
" WHERE mv_line.id in %(line_ids)s\n"
@@ -356,7 +356,7 @@ class CreditControlPolicyLevel(models.Model):
move_line_obj = self.env['account.move.line']
if not lines:
return move_line_obj.browse()
cr = self._cr
cr = self.env.cr
sql = ("SELECT mv_line.id\n"
" FROM account_move_line mv_line\n"
" JOIN credit_control_line cr_line\n"

View File

@@ -1 +0,0 @@
from . import credit_control_summary

View File

@@ -1,244 +0,0 @@
## -*- coding: utf-8 -*-
<html>
<head>
<style type="text/css">
${css}
body {
font-family: helvetica;
font-size: 12px;
}
.custom_text {
font-family: helvetica;
font-size: 12px;
}
table {
font-family: helvetica;
font-size: 12px;
}
.header {
margin-left: 0px;
text-align: left;
width: 300px;
font-size: 12px;
}
.title {
font-size: 16px;
font-weight: bold;
}
.basic_table{
text-align: center;
border: 1px solid lightGrey;
border-collapse: collapse;
font-family: helvetica;
font-size: 12px;
}
.basic_table th {
border: 1px solid lightGrey;
font-size: 11px;
font-weight: bold;
}
.basic_table td {
border: 1px solid lightGrey;
font-size: 12px;
}
.list_table {
border-color: black;
text-align: center;
border-collapse: collapse;
}
.list_table td {
border-color: gray;
border-top: 1px solid gray;
text-align: left;
font-size: 12px;
padding-right: 3px;
padding-left: 3px;
padding-top: 3px;
padding-bottom:3px;
}
.list_table th {
border-bottom: 2px solid black;
text-align: left;
font-size: 11px;
font-weight: bold;
padding-right: 3px
padding-left: 3px
}
.list_table thead {
display: table-header-group;
}
.address table {
font-size: 11px;
border-collapse: collapse;
margin: 0px;
padding: 0px;
}
.address .shipping {
}
.address .invoice {
margin-top: 10px;
}
.address .recipient {
font-size: 13px;
margin-right: 120px;
margin-left: 350px;
float: right;
}
table .address_title {
font-weight: bold;
}
.address td.name {
font-weight: bold;
}
td.amount, th.amount {
text-align: right;
padding-right:2px;
}
h1 {
font-size: 16px;
font-weight: bold;
}
tr.line .note {
border-style: none;
font-size: 9px;
padding-left: 10px;
}
tr.line {
margin-bottom: 10px;
}
</style>
</head>
<body>
%for comm in objects :
<% setLang(comm.get_contact_address().lang) %>
<div class="address">
<table class="recipient">
<%
add = comm.get_contact_address()
%>
%if comm.partner_id.id == add.id:
<tr><td class="name">${comm.partner_id.title and comm.partner_id.title.name or ''} ${comm.partner_id.name }</td></tr>
<% address_lines = comm.partner_id.contact_address.split("\n") %>
%else:
<tr><td class="name">${comm.partner_id.name or ''}</td></tr>
<tr><td>${add.title and add.title.name or ''} ${add.name}</td></tr>
<% address_lines = add.contact_address.split("\n")[1:] %>
%endif
%for part in address_lines:
%if part:
<tr><td>${part}</td></tr>
%endif
%endfor
</table>
<br/>
<br/>
<br/>
<br/>
</div>
<br/>
<br/>
<br/>
<div>
<h3 style="clear: both; padding-top: 20px;">
${_('Reminder')}: ${comm.current_policy_level.name or '' }
</h3>
<p>${_('Dear')},</p>
<p class="custom_text" width="95%">${comm.current_policy_level.custom_text.replace('\n', '<br />')}</p>
<br/>
<br/>
<p><b>${_('Summary')}<br/></b></p>
<table class="basic_table" style="width: 100%;">
<tr>
<th width="200">${_('Invoice number')}</th>
<th>${_('Invoice date')}</th>
<th>${_('Date due')}</th>
<th>${_('Invoiced amount')}</th>
<th>${_('Open amount')}</th>
<th>${_('Currency')}</th>
</tr>
%for line in comm.credit_control_line_ids:
<tr>
%if line.invoice_id:
<td width="200">${line.invoice_id.number}
%if line.invoice_id.name:
<br/>
${line.invoice_id.name}
%endif
</td>
%else:
<td width="200">${line.move_line_id.name}</td>
%endif
<td class="date">${line.date_entry}</td>
<td class="date">${line.date_due}</td>
<td class="amount">${line.amount_due}</td>
<td class="amount">${line.balance_due}</td>
<td class="amount">${line.currency_id.name or comm.company_id.currency_id.name}</td>
</tr>
%endfor
</table>
<br/>
<br/>
<%doc>
<!-- uncomment to have info after summary -->
<p>${_('If you have any question, do not hesitate to contact us.')}</p>
<p>${comm.user_id.name} ${comm.user_id.email and '<%s>'%(comm.user_id.email) or ''}<br/>
${comm.company_id.name}<br/>
% if comm.company_id.street:
${comm.company_id.street or ''}<br/>
% endif
% if comm.company_id.street2:
${comm.company_id.street2}<br/>
% endif
% if comm.company_id.city or comm.company_id.zip:
${comm.company_id.zip or ''} ${comm.company_id.city or ''}<br/>
% endif
% if comm.company_id.country_id:
${comm.company_id.state_id and ('%s, ' % comm.company_id.state_id.name) or ''} ${comm.company_id.country_id.name or ''}<br/>
% endif
% if comm.company_id.phone:
Phone: ${comm.company_id.phone}<br/>
% endif
% if comm.company_id.website:
${comm.company_id.website or ''}<br/>
% endif
</%doc>
<p style="page-break-after:always"></p>
%endfor
</body>
</html>

View File

@@ -1,41 +0,0 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Author: Nicolas Bessi, Guewen Baconnier
# Copyright 2012 Camptocamp SA
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import time
from openerp.report import report_sxw
class CreditSummaryReport(report_sxw.rml_parse):
def __init__(self, cr, uid, name, context):
super(CreditSummaryReport, self).__init__(cr, uid, name,
context=context)
self.localcontext.update({
'time': time,
'cr': cr,
'uid': uid,
})
report_sxw.report_sxw(
'report.credit_control_summary',
'credit.control.communication',
'addons/account_credit_control/report/credit_control_summary.html.mako',
parser=CreditSummaryReport
)

View File

@@ -1,16 +1,15 @@
<openerp>
<data>
<report auto="False"
id="report_webkit_html"
model="credit.control.communication"
name="credit_control_summary"
file="account_credit_control/report/credit_control_summary.html.mako"
string="Credit Summary"
report_type="webkit"
webkit_header="report_webkit.ir_header_webkit_basesample0"/>
<record model="ir.actions.report.xml" id="report_webkit_html">
<field name="precise_mode" eval="True"/>
</record>
<report
id="credit_control_summary"
model="credit.control.communication"
string="Credit Control Summary"
report_type="qweb-pdf"
name="account_credit_control.report_credit_control_summary"
file="account_credit_control.report_credit_control_summary"
auto="False"
/>
</data>
</openerp>

View File

@@ -0,0 +1,78 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<template id="report_credit_control_summary_document">
<t t-call="report.external_layout">
<div class="page">
<div class="row" id="address">
<div class="col-xs-5 col-xs-offset-7">
<address t-field="o.contact_address"
t-field-options='{"widget": "contact",
"fields": ["address", "name"],
"no_marker": true}' />
</div>
</div>
<h2 id="policy_level">
<span>Reminder</span> <span t-field="o.current_policy_level.name"/>
</h2>
<p>Dear,</p>
<p t-field="o.current_policy_level.custom_text"/>
<h3>Summary</h3>
<table class="table table-condensed" id="summary_table">
<thead>
<tr>
<th>Invoice number</th>
<th>Invoice date</th>
<th>Date due</th>
<th class="text-right">Invoiced amount</th>
<th class="text-right">Open amount</th>
</tr>
</thead>
<tbody>
<tr t-foreach="o.credit_control_line_ids" t-as="l">
<t t-if="l.invoice_id">
<td><span t-field="l.invoice_id.number"/>
<t t-if="l.invoice_id.name">
<span t-field="l.invoice_id.name"/>
</t>
</td>
</t>
<t t-if="not l.invoice_id">
<td><span t-field="l.move_line_id.name"/></td>
</t>
<td>
<span t-field="l.date_entry"/>
</td>
<td>
<span t-field="l.date_due"/>
</td>
<td class="text-right">
<span t-field="l.amount_due"/>
</td>
<td class="text-right">
<span t-field="l.balance_due"
t-field-options='{"widget": "monetary",
"display_currency": "l.currency_id or l.company_id.currency_id"}'/>
</td>
</tr>
</tbody>
</table>
</div>
</t>
</template>
<template id="report_credit_control_summary">
<t t-call="report.html_container">
<t t-foreach="doc_ids" t-as="doc_id">
<t t-raw="translate_doc(doc_id, doc_model, 'partner_id.lang', 'account_credit_control.report_credit_control_summary_document')"/>
</t>
</t>
</template>
</data>
</openerp>

View File

@@ -144,8 +144,8 @@ class CreditControlRun(models.Model):
calls of this method.
"""
try:
self._cr.execute('SELECT id FROM credit_control_run'
' LIMIT 1 FOR UPDATE NOWAIT')
self.env.cr.execute('SELECT id FROM credit_control_run'
' LIMIT 1 FOR UPDATE NOWAIT')
except Exception:
# In case of exception openerp will do a rollback
# for us and free the lock

View File

@@ -20,7 +20,6 @@
##############################################################################
import logging
from openerp import models, fields, api
from openerp import netsvc
logger = logging.getLogger('credit.control.line.mailing')
@@ -40,10 +39,15 @@ class CreditCommunication(models.TransientModel):
current_policy_level = fields.Many2one('credit.control.policy.level',
'Level',
required=True)
credit_control_line_ids = fields.Many2many('credit.control.line',
rel='comm_credit_rel',
string='Credit Lines')
contact_address = fields.Many2one('res.partner',
string='Contact Address',
readonly=True)
@api.model
def _get_company(self):
company_obj = self.env['res.company']
@@ -57,21 +61,37 @@ class CreditCommunication(models.TransientModel):
default=lambda self: self.env.user,
string='User')
@api.model
@api.returns('self', lambda value: value.id)
def create(self, vals):
if vals.get('partner_id'):
# the computed field does not work in TransientModel,
# just set a value on creation
partner_id = vals['partner_id']
vals['contact_address'] = self._get_contact_address(partner_id).id
return super(CreditCommunication, self).create(vals)
@api.multi
def get_email(self):
""" Return a valid email for customer """
self.ensure_one()
contact = self.get_contact_address()
contact = self.contact_address
return contact.email
@api.multi
@api.returns('res.partner')
def get_contact_address(self):
""" Compatibility method, please use the contact_address field """
self.ensure_one()
return self.contact_address
@api.model
@api.returns('res.partner')
def _get_contact_address(self, partner_id):
partner_obj = self.env['res.partner']
partner = self.partner_id
partner = partner_obj.browse(partner_id)
add_ids = partner.address_get(adr_pref=['invoice']) or {}
add_id = add_ids.get('invoice', add_ids.get('default', False))
add_id = add_ids['invoice']
return partner_obj.browse(add_id)
@api.model
@@ -89,9 +109,9 @@ class CreditCommunication(models.TransientModel):
""" Aggregate credit control line by partner, level, and currency
It also generate a communication object per aggregation.
"""
if not lines:
return []
comms = self.browse()
if not lines:
return comms
sql = (
"SELECT distinct partner_id, policy_level_id, "
" credit_control_line.currency_id, "
@@ -103,7 +123,7 @@ class CreditCommunication(models.TransientModel):
" ORDER by credit_control_policy_level.level, "
" credit_control_line.currency_id"
)
cr = self._cr
cr = self.env.cr
cr.execute(sql, (tuple(lines.ids), ))
res = cr.dictfetchall()
for level_assoc in res:
@@ -139,7 +159,6 @@ class CreditCommunication(models.TransientModel):
template.id,
comm.id,
context=context)
email_values['body_html'] = email_values['body']
email_values['type'] = 'email'
email = email_message_obj.create(email_values)
@@ -179,13 +198,8 @@ class CreditCommunication(models.TransientModel):
of related policy template
"""
return ''
service = netsvc.LocalService('report.credit_control_summary')
cr, uid = self.env.cr, self.env.uid
result, format = service.create(cr, uid, self.ids, {}, {})
return result
# TODO
# return self.env['report'].get_pdf(self, 'credit_control_summary')
report_name = 'account_credit_control.report_credit_control_summary'
return self.env['report'].get_pdf(self, report_name)
@api.multi
@api.returns('credit.control.line')

View File

@@ -18,7 +18,6 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import base64
from openerp import models, fields, api, _
@@ -40,9 +39,6 @@ class CreditControlPrinter(models.TransientModel):
mark_as_sent = fields.Boolean(string='Mark letter lines as sent',
default=True,
help="Only letter lines will be marked.")
report_file = fields.Binary(string='Generated Report', readonly=True)
report_name = fields.Char(string='Report name')
state = fields.Char(string='state')
line_ids = fields.Many2many('credit.control.line',
string='Credit Control Lines',
default=_get_line_ids)
@@ -67,15 +63,9 @@ class CreditControlPrinter(models.TransientModel):
comms = comm_obj._generate_comm_from_credit_lines(lines)
report_content = comms._generate_report()
self.write({'report_file': base64.b64encode(report_content),
'report_name': ('credit_control_esr_bvr_%s.pdf' %
fields.datetime.now()),
'state': 'done'})
if self.mark_as_sent:
comms._mark_credit_line_as_sent()
action = self.get_formview_action()[0]
action['target'] = 'new'
return action
report_name = 'account_credit_control.report_credit_control_summary'
report_obj = self.env['report'].with_context(active_ids=comms.ids)
return report_obj.get_action(comms, report_name)

View File

@@ -11,28 +11,17 @@
<newline/>
<group>
<field name="mark_as_sent"
colspan="4"
attrs="{'invisible': [('state', '=', 'done')]}"/>
colspan="4"/>
</group>
<newline/>
<notebook>
<page string="Lines" attrs="{'invisible': [('state', '=', 'done')]}">
<field name="line_ids" colspan="4" nolabel="1"
attrs="{'invisible': [('state', '=', 'done')]}" />
<page string="Lines">
<field name="line_ids" colspan="4" nolabel="1"/>
</page>
</notebook>
<field name="report_name"
invisible="1"/>
<field name="report_file"
colspan="4"
filename="report_name"
attrs="{'invisible': [('state', '!=', 'done')]}"/>
<field name="state" invisible="1" />
<newline/>
<footer>
<button class="oe_highlight" name="print_lines" string="Print" type="object" attrs="{'invisible': [('state', '=', 'done')]}"/>
<button special="cancel" string="Cancel" icon='gtk-cancel' attrs="{'invisible': [('state', '=', 'done')]}"/>
<button special="cancel" string="Close" icon='gtk-close' attrs="{'invisible': [('state', '!=', 'done')]}"/>
<button class="oe_highlight" name="print_lines" string="Print" type="object"/>
<button special="cancel" string="Cancel" icon='gtk-cancel'/>
</footer>
</form>
</field>