account_move_template migration to openerp 7
This commit is contained in:
parent
2bd2e91783
commit
d6939fa448
@ -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,
|
||||
}
|
||||
|
@ -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()
|
||||
|
@ -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'
|
||||
@ -59,9 +59,7 @@ class account_move_template(osv.osv):
|
||||
'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()
|
||||
|
@ -5,7 +5,6 @@
|
||||
<record id="view_move_template_line_tree" model="ir.ui.view">
|
||||
<field name="name">account.move.template.line.tree</field>
|
||||
<field name="model">account.move.template.line</field>
|
||||
<field name="type">tree</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="Journal Entry Template Line">
|
||||
<field name="sequence"/>
|
||||
@ -25,7 +24,6 @@
|
||||
<record id="view_move_template_line_form" model="ir.ui.view">
|
||||
<field name="name">account.move.template.line.form</field>
|
||||
<field name="model">account.move.template.line</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Journal Entry Template Line">
|
||||
<field colspan="4" name="name" select="1"/>
|
||||
@ -46,7 +44,6 @@
|
||||
<record id="view_move_template_form" model="ir.ui.view">
|
||||
<field name="name">account.move.template.form</field>
|
||||
<field name="model">account.move.template</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Journal Entry Template">
|
||||
<field name="name"/>
|
||||
@ -61,7 +58,6 @@
|
||||
<record id="view_move_template_tree" model="ir.ui.view">
|
||||
<field name="name">account.move.template.tree</field>
|
||||
<field name="model">account.move.template</field>
|
||||
<field name="type">tree</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="Journal Entry Template">
|
||||
<field name="name"/>
|
||||
@ -73,7 +69,6 @@
|
||||
<record id="view_move_template_search" model="ir.ui.view">
|
||||
<field name="name">account.move.template.search</field>
|
||||
<field name="model">account.move.template</field>
|
||||
<field name="type">search</field>
|
||||
<field name="arch" type="xml">
|
||||
<search string="Journal Entry Template">
|
||||
<group>
|
||||
@ -94,6 +89,6 @@
|
||||
</record>
|
||||
<menuitem
|
||||
action="action_move_template_form" id="menu_action_move_template_form" sequence="5"
|
||||
parent="account.menu_configuration_misc" groups="base.group_extended"/>
|
||||
parent="account.menu_configuration_misc" groups="account.group_account_manager"/>
|
||||
</data>
|
||||
</openerp>
|
||||
|
@ -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
|
||||
@ -182,9 +197,7 @@ class wizard_select_template(osv.osv_memory):
|
||||
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()
|
||||
|
@ -5,7 +5,6 @@
|
||||
<record id="wizard_select_template" model="ir.ui.view">
|
||||
<field name="name">Select Move Template</field>
|
||||
<field name="model">wizard.select.move.template</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Move Template" >
|
||||
<group col="2" width="600" height="500">
|
||||
@ -29,7 +28,6 @@
|
||||
<record id="wizard_select_template_line" model="ir.ui.view">
|
||||
<field name="name">Select Move Template Line</field>
|
||||
<field name="model">wizard.select.move.template.line</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Move Template Line">
|
||||
<group col="2">
|
||||
@ -46,7 +44,6 @@
|
||||
<record id="wizard_select_template_line_tree" model="ir.ui.view">
|
||||
<field name="name">Select Move Template Line</field>
|
||||
<field name="model">wizard.select.move.template.line</field>
|
||||
<field name="type">tree</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="Move Template Line" editable="bottom">
|
||||
<field name="sequence" invisible="1"/>
|
||||
|
Loading…
x
Reference in New Issue
Block a user