From 39c490a8424c03c4a91d232cae22e1f81bc816eb Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Thu, 6 Oct 2011 15:20:09 +0200 Subject: [PATCH] [IMP] lxml-ify fields_view_get override in account.move.line bzr revid: xmo@openerp.com-20111006132009-ci16jjrylmb23nnn --- addons/account/account_move_line.py | 55 ++++++++++++++++------------- 1 file changed, 31 insertions(+), 24 deletions(-) diff --git a/addons/account/account_move_line.py b/addons/account/account_move_line.py index ce349fc4f4e..acee05a5a00 100644 --- a/addons/account/account_move_line.py +++ b/addons/account/account_move_line.py @@ -23,6 +23,8 @@ import time from datetime import datetime from operator import itemgetter +from lxml import etree + import netsvc from osv import fields, osv from tools.translate import _ @@ -970,7 +972,6 @@ class account_move_line(osv.osv): fields = {} flds = [] title = _("Accounting Entries") #self.view_header_get(cr, uid, view_id, view_type, context) - xml = '''\n\n\t''' % (title) ids = journal_pool.search(cr, uid, []) journals = journal_pool.browse(cr, uid, ids, context=context) @@ -1001,61 +1002,67 @@ class account_move_line(osv.osv): 'tax_code_id': 50, 'move_id': 40, } + + document = etree.Element('tree', string=title, editable="top", + refresh="5", on_write="on_create_write", + colors="red:state=='draft';black:state=='valid'") for field_it in fld: field = field_it[0] if common_fields.get(field) == total: fields.get(field).append(None) -# if field=='state': -# state = 'colors="red:state==\'draft\'"' - attrs = [] + # if field=='state': + # state = 'colors="red:state==\'draft\'"' + f = etree.SubElement(document, 'field', name=field) + if field == 'debit': - attrs.append('sum = "%s"' % _("Total debit")) + f.set('sum', _("Total debit")) elif field == 'credit': - attrs.append('sum = "%s"' % _("Total credit")) + f.set('sum', _("Total credit")) elif field == 'move_id': - attrs.append('required = "False"') + f.set('required', 'False') elif field == 'account_tax_id': - attrs.append('domain="[(\'parent_id\', \'=\' ,False)]"') - attrs.append("context=\"{'journal_id': journal_id}\"") + f.set('domain', "[('parent_id', '=' ,False)]") + f.set('context', "{'journal_id': journal_id}") elif field == 'account_id' and journal.id: - attrs.append('domain="[(\'journal_id\', \'=\', journal_id),(\'type\',\'<>\',\'view\'), (\'type\',\'<>\',\'closed\')]" on_change="onchange_account_id(account_id, partner_id)"') + f.set('domain', "[('journal_id', '=', journal_id),('type','!=','view'), ('type','!=','closed')]") + f.set('on_change', 'onchange_account_id(account_id, partner_id)') elif field == 'partner_id': - attrs.append('on_change="onchange_partner_id(move_id, partner_id, account_id, debit, credit, date, journal_id)"') + f.set('on_change', 'onchange_partner_id(move_id, partner_id, account_id, debit, credit, date, journal_id)') elif field == 'journal_id': - attrs.append("context=\"{'journal_id': journal_id}\"") + f.set('context', "{'journal_id': journal_id}") elif field == 'statement_id': - attrs.append("domain=\"[('state', '!=', 'confirm'),('journal_id.type', '=', 'bank')]\"") + f.set('domain', "[('state', '!=', 'confirm'),('journal_id.type', '=', 'bank')]") elif field == 'date': - attrs.append('on_change="onchange_date(date)"') + f.set('on_change', 'onchange_date(date)') elif field == 'analytic_account_id': - attrs.append('''groups="analytic.group_analytic_accounting"''') # Currently it is not working due to framework problem may be .. + # Currently it is not working due to being executed by superclass's fields_view_get + # f.set('groups', 'analytic.group_analytic_accounting') + pass if field in ('amount_currency', 'currency_id'): - attrs.append('on_change="onchange_currency(account_id, amount_currency, currency_id, date, journal_id)"') - attrs.append('''attrs="{'readonly': [('state', '=', 'valid')]}"''') + f.set('on_change', 'onchange_currency(account_id, amount_currency, currency_id, date, journal_id)') + f.set('attrs', "{'readonly': [('state', '=', 'valid')]}") if field in widths: - attrs.append('width="'+str(widths[field])+'"') + f.set('width', str(widths[field])) if field in ('journal_id',): - attrs.append("invisible=\"context.get('journal_id', False)\"") + f.set("invisible", "context.get('journal_id', False)") elif field in ('period_id',): - attrs.append("invisible=\"context.get('period_id', False)\"") + f.set("invisible", "context.get('period_id', False)") else: - attrs.append("invisible=\"context.get('visible_id') not in %s\"" % (fields.get(field))) - xml += '''\n''' % (field,' '.join(attrs)) + f.set('invisible', "context.get('visible_id') not in %s" % (fields.get(field))) - xml += '''''' - result['arch'] = xml + result['arch'] = etree.tostring(document, pretty_print=True) result['fields'] = self.fields_get(cr, uid, flds, context) return result