[FIX] report: set a default paperformat for companies, based on rml paperformat

bzr revid: chs@openerp.com-20140423132100-t6lmyd8qymoo4wqq
This commit is contained in:
Christophe Simonis 2014-04-23 15:21:00 +02:00
parent 1b594f5cce
commit 9ed196bc81
2 changed files with 22 additions and 5 deletions

View File

@ -32,9 +32,5 @@
<field name="header_spacing">35</field>
<field name="dpi">90</field>
</record>
<record id="base.main_company" model="res.company">
<field name="paperformat_id" ref="paperformat_euro"></field>
</record>
</data>
</openerp>
</openerp>

View File

@ -19,6 +19,9 @@
#
##############################################################################
from functools import partial
from openerp import SUPERUSER_ID
from openerp.osv import osv, fields
@ -114,6 +117,24 @@ class res_company(osv.Model):
_columns = {'paperformat_id': fields.many2one('report.paperformat', 'Paper format')}
def init(self, cr):
# set a default paperformat based on rml one.
ref = partial(self.pool['ir.model.data'].xmlid_to_res_id, cr, SUPERUSER_ID)
ids = self.search(cr, SUPERUSER_ID, [('paperformat_id', '=', False)])
for company in self.browse(cr, SUPERUSER_ID, ids):
paperformat_id = {
'a4': ref('report.paperformat_euro'),
'us_letter': ref('report.paperformat_us'),
}.get(company.rml_paper_format) or ref('report.paperformat_euro')
if paperformat_id:
company.write({'paperformat_id': paperformat_id})
sup = super(res_company, self)
if hasattr(sup, 'init'):
sup.init(cr)
class ir_actions_report(osv.Model):
_inherit = 'ir.actions.report.xml'