[FIX] Small changes in barcode controller and set default values when creating paper format

bzr revid: sle@openerp.com-20140221101520-tg522m1w38jdp55p
This commit is contained in:
Simon Lejeune 2014-02-21 11:15:20 +01:00
parent 35b64811e9
commit 0304f71112
3 changed files with 21 additions and 9 deletions

View File

@ -53,7 +53,6 @@ class tax_report(http.Controller, common_report_header):
}
return request.registry['report'].render(self.cr, self.uid, [], 'account.report_vat', docargs)
def _get_basedon(self, form):
return form['form']['based_on']

View File

@ -360,7 +360,6 @@ class Report(http.Controller):
def _build_wkhtmltopdf_args(self, paperformat, specific_paperformat_args=None):
"""Build arguments understandable by wkhtmltopdf from an ir.actions.report.paperformat
record.
Sample: <img t-att-src="'/report/getbarcode/QR/%s/200/200' % o.name"/>
:paperformat: ir.actions.report.paperformat record associated to a document
:specific_paperformat_args: a dict containing prioritized wkhtmltopdf arguments
@ -456,12 +455,10 @@ class Report(http.Controller):
response.headers.add('Content-Disposition', 'attachment; filename=report.pdf;')
return response
@http.route([
'/report/getbarcode/<type>/<value>',
'/report/getbarcode/<type>/<value>/<int:width>/<int:height>',
], type='http', auth="user")
@http.route(['/report/barcode', '/report/barcode/<type>/<value>'], type='http', auth="user")
def barcode(self, type, value, width=300, height=50):
"""Contoller able to render barcode images thanks to reportlab.
Sample: <img t-att-src="'/report/barcode/QR/%s' % o.name"/>
:param type: Accepted types: 'Codabar', 'Code11', 'Code128', 'EAN13', 'EAN8', 'Extended39',
'Extended93', 'FIM', 'I2of5', 'MSI', 'POSTNET', 'QR', 'Standard39', 'Standard93',
@ -469,9 +466,11 @@ class Report(http.Controller):
"""
try:
barcode = createBarcodeImageInMemory(
type, value=value, format='jpg', width=width, height=height
type, value=value, format='png', width=width, height=height
)
except (ValueError, AttributeError):
raise exceptions.HTTPException(description='Cannot convert into barcode.')
except AssertionError:
raise exceptions.HTTPException(description='Please upgrade reportlab to at least 3.0.')
return request.make_response(barcode, headers=[('Content-Type', 'image/jpg')])
return request.make_response(barcode, headers=[('Content-Type', 'image/png')])

View File

@ -76,7 +76,7 @@ class report_paperformat(osv.Model):
'Orientation'),
'header_line': fields.boolean('Display a header line'),
'header_spacing': fields.integer('Header spacing'),
'dpi': fields.integer('Output DPI'),
'dpi': fields.integer('Output DPI', required=True),
'report_ids': fields.one2many('ir.actions.report.xml',
'paperformat_id',
'Associated reports',
@ -94,6 +94,20 @@ class report_paperformat(osv.Model):
'page width/height.', ['format']),
]
_defaults = {
'format': 'A4',
'margin_top': 40,
'margin_bottom': 20,
'margin_left': 7,
'margin_right': 7,
'page_height': False,
'page_width': False,
'orientation': 'Landscape',
'header_line': False,
'header_spacing': 35,
'dpi': 90,
}
class res_company(osv.Model):
_inherit = 'res.company'