From d6939fa44879dfbc1daa9be2e8dabd28f52d9505 Mon Sep 17 00:00:00 2001 From: Bruno Bottacini Date: Mon, 17 Jun 2013 12:25:27 +0200 Subject: [PATCH] account_move_template migration to openerp 7 --- account_move_template/__openerp__.py | 10 +++--- .../account_document_template.py | 16 ++++----- .../account_move_template.py | 10 ++---- account_move_template/move_template.xml | 7 +--- .../wizard/select_template.py | 35 ++++++++++++------- .../wizard/select_template.xml | 3 -- 6 files changed, 37 insertions(+), 44 deletions(-) diff --git a/account_move_template/__openerp__.py b/account_move_template/__openerp__.py index 08d1a6ad..12f0613b 100644 --- a/account_move_template/__openerp__.py +++ b/account_move_template/__openerp__.py @@ -32,17 +32,15 @@ The journal entry form allows lo load, through a wizard, the template to use and 'author': 'Agile Business Group', 'website': 'http://www.agilebg.com', 'license': 'AGPL-3', - "depends" : ['account_accountant', 'analytic'], - "init_xml" : [], - "update_xml" : [ + 'depends' : ['account_accountant', 'analytic'], + 'data' : [ 'move_template.xml', 'wizard/select_template.xml', 'security/ir.model.access.csv', ], - "demo_xml" : [], 'test': [ 'test/generate_move.yml', ], - "active": False, - "installable": True + 'active': False, + 'installable': True, } diff --git a/account_move_template/account_document_template.py b/account_move_template/account_document_template.py index 1946f7ce..d520cf36 100644 --- a/account_move_template/account_document_template.py +++ b/account_move_template/account_document_template.py @@ -19,11 +19,11 @@ # ############################################################################## -from openerp.osv import fields, osv +from openerp.osv import fields, orm from openerp.tools.translate import _ import re -class account_document_template(osv.osv): +class account_document_template(orm.Model): _computed_lines = {} _current_template_id = 0 @@ -59,12 +59,12 @@ class account_document_template(osv.osv): return self._computed_lines[line_number] line = self._get_template_line(self._cr, self._uid, self._current_template_id, line_number) if re.match('L\( *'+str(line_number)+' *\)',line.python_code): - raise osv.except_osv(_('Error'), + raise orm.except_orm(_('Error'), _('Line %s can\'t refer to itself') % str(line_number)) try: self._computed_lines[line_number] = eval(line.python_code.replace('L', 'self.lines')) except KeyError: - raise osv.except_osv(_('Error'), + raise orm.except_orm(_('Error'), _('Code "%s" refers to non existing line') % line.python_code) return self._computed_lines[line_number] @@ -73,7 +73,7 @@ class account_document_template(osv.osv): # returns all the lines (included input lines) in the form {line_number: line_amount} template = self.browse(cr, uid, template_id) if len(input_lines) != self._input_lines(cr, uid, template): - raise osv.except_osv(_('Error'), + raise orm.except_orm(_('Error'), _('Inconsistency between input lines and filled lines for template %s') % template.name) self._current_template_id = template.id self._cr = cr @@ -92,9 +92,7 @@ class account_document_template(osv.osv): return True return False -account_document_template() - -class account_document_template_line(osv.osv): +class account_document_template_line(orm.Model): _name = 'account.document.template.line' @@ -104,5 +102,3 @@ class account_document_template_line(osv.osv): 'type': fields.selection([('computed', 'Computed'),('input', 'User input')], 'Type', required=True), 'python_code':fields.text('Python Code'), } - -account_document_template_line() diff --git a/account_move_template/account_move_template.py b/account_move_template/account_move_template.py index 012afaf0..f515e790 100644 --- a/account_move_template/account_move_template.py +++ b/account_move_template/account_move_template.py @@ -19,10 +19,10 @@ # ############################################################################## -from openerp.osv import fields, osv +from openerp.osv import fields, orm from openerp.tools.translate import _ -class account_move_template(osv.osv): +class account_move_template(orm.Model): _inherit = 'account.document.template' _name = 'account.move.template' @@ -58,10 +58,8 @@ class account_move_template(osv.osv): 'If the template is "cross-journals", the Journals must be different,' \ 'if the template does not "cross-journals" the Journals must be the same!', ['journal_id'])] - -account_move_template() -class account_move_template_line(osv.osv): +class account_move_template_line(orm.Model): _name = 'account.move.template.line' _inherit = 'account.document.template.line' @@ -81,5 +79,3 @@ class account_move_template_line(osv.osv): _sql_constraints = [ ('sequence_template_uniq', 'unique (template_id,sequence)', 'The sequence of the line must be unique per template !') ] - -account_move_template_line() diff --git a/account_move_template/move_template.xml b/account_move_template/move_template.xml index 23705a2a..860c81b3 100644 --- a/account_move_template/move_template.xml +++ b/account_move_template/move_template.xml @@ -5,7 +5,6 @@ account.move.template.line.tree account.move.template.line - tree @@ -25,7 +24,6 @@ account.move.template.line.form account.move.template.line - form
@@ -46,7 +44,6 @@ account.move.template.form account.move.template - form @@ -61,7 +58,6 @@ account.move.template.tree account.move.template - tree @@ -73,7 +69,6 @@ account.move.template.search account.move.template - search @@ -94,6 +89,6 @@ + parent="account.menu_configuration_misc" groups="account.group_account_manager"/> diff --git a/account_move_template/wizard/select_template.py b/account_move_template/wizard/select_template.py index 9ad22040..52b4fe55 100644 --- a/account_move_template/wizard/select_template.py +++ b/account_move_template/wizard/select_template.py @@ -19,11 +19,11 @@ # ############################################################################## -from openerp.osv import fields,osv +from openerp.osv import fields,orm import time from openerp.tools.translate import _ -class wizard_select_template(osv.osv_memory): +class wizard_select_template(orm.TransientModel): _name = "wizard.select.move.template" _columns = { @@ -55,6 +55,8 @@ class wizard_select_template(osv.osv_memory): wizard = self.browse(cr, uid, ids, context=context)[0] template_pool = self.pool.get('account.move.template') wizard_line_pool = self.pool.get('wizard.select.move.template.line') + model_data_obj = self.pool.get('ir.model.data') + template = template_pool.browse(cr, uid, wizard.template_id.id) for line in template.template_line_ids: if line.type == 'input': @@ -69,7 +71,20 @@ class wizard_select_template(osv.osv_memory): if not wizard.line_ids: return self.load_template(cr, uid, ids) wizard.write({'state': 'template_selected'}) - return True + + view_rec = model_data_obj.get_object_reference(cr, uid, 'account_move_template', 'wizard_select_template') + view_id = view_rec and view_rec[1] or False + + return { + 'view_type': 'form', + 'view_id' : [view_id], + 'view_mode': 'form', + 'res_model': 'wizard.select.move.template', + 'res_id': wizard.id, + 'type': 'ir.actions.act_window', + 'target': 'new', + 'context': context, + } def load_template(self, cr, uid, ids, context=None): template_obj = self.pool.get('account.move.template') @@ -80,7 +95,7 @@ class wizard_select_template(osv.osv_memory): mod_obj = self.pool.get('ir.model.data') wizard = self.browse(cr, uid, ids, context=context)[0] if not template_obj.check_zero_lines(cr, uid, wizard): - raise osv.except_osv(_('Error !'), _('At least one amount has to be non-zero!')) + raise orm.except_orm(_('Error !'), _('At least one amount has to be non-zero!')) input_lines = {} for template_line in wizard.line_ids: @@ -88,7 +103,7 @@ class wizard_select_template(osv.osv_memory): period_id = account_period_obj.find(cr, uid, context=context) if not period_id: - raise osv.except_osv(_('No period found !'), _('Unable to find a valid period !')) + raise orm.except_orm(_('No period found !'), _('Unable to find a valid period !')) period_id = period_id[0] computed_lines = template_obj.compute_lines(cr, uid, wizard.template_id.id, input_lines) @@ -131,7 +146,7 @@ class wizard_select_template(osv.osv_memory): analytic_account_id = False if line.analytic_account_id: if not line.journal_id.analytic_journal_id: - raise osv.except_osv(_('No Analytic Journal !'), + raise orm.except_orm(_('No Analytic Journal !'), _("You have to define an analytic journal on the '%s' journal!") % (line.journal_id.name,)) analytic_account_id = line.analytic_account_id.id @@ -161,7 +176,7 @@ class wizard_select_template(osv.osv_memory): analytic_account_id = False if line.analytic_account_id: if not line.journal_id.analytic_journal_id: - raise osv.except_osv(_('No Analytic Journal !'), + raise orm.except_orm(_('No Analytic Journal !'), _("You have to define an analytic journal on the '%s' journal!") % (wizard.template_id.journal_id.name,)) analytic_account_id = line.analytic_account_id.id @@ -181,10 +196,8 @@ class wizard_select_template(osv.osv_memory): val['debit'] = computed_lines[line.sequence] id_line = account_move_line_obj.create(cr, uid, val) return id_line - -wizard_select_template() -class wizard_select_template_line(osv.osv_memory): +class wizard_select_template_line(orm.TransientModel): _description = 'Template Lines' _name = "wizard.select.move.template.line" _columns = { @@ -198,5 +211,3 @@ class wizard_select_template_line(osv.osv_memory): ], 'Move Line Type', required=True,readonly=True), 'amount': fields.float('Amount', required=True), } - -wizard_select_template_line() diff --git a/account_move_template/wizard/select_template.xml b/account_move_template/wizard/select_template.xml index 51bcdfa7..e6ce4636 100644 --- a/account_move_template/wizard/select_template.xml +++ b/account_move_template/wizard/select_template.xml @@ -5,7 +5,6 @@ Select Move Template wizard.select.move.template - form @@ -29,7 +28,6 @@ Select Move Template Line wizard.select.move.template.line - form @@ -46,7 +44,6 @@ Select Move Template Line wizard.select.move.template.line - tree