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',
|
'author': 'Agile Business Group',
|
||||||
'website': 'http://www.agilebg.com',
|
'website': 'http://www.agilebg.com',
|
||||||
'license': 'AGPL-3',
|
'license': 'AGPL-3',
|
||||||
"depends" : ['account_accountant', 'analytic'],
|
'depends' : ['account_accountant', 'analytic'],
|
||||||
"init_xml" : [],
|
'data' : [
|
||||||
"update_xml" : [
|
|
||||||
'move_template.xml',
|
'move_template.xml',
|
||||||
'wizard/select_template.xml',
|
'wizard/select_template.xml',
|
||||||
'security/ir.model.access.csv',
|
'security/ir.model.access.csv',
|
||||||
],
|
],
|
||||||
"demo_xml" : [],
|
|
||||||
'test': [
|
'test': [
|
||||||
'test/generate_move.yml',
|
'test/generate_move.yml',
|
||||||
],
|
],
|
||||||
"active": False,
|
'active': False,
|
||||||
"installable": True
|
'installable': True,
|
||||||
}
|
}
|
||||||
|
@ -19,11 +19,11 @@
|
|||||||
#
|
#
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
from openerp.osv import fields, osv
|
from openerp.osv import fields, orm
|
||||||
from openerp.tools.translate import _
|
from openerp.tools.translate import _
|
||||||
import re
|
import re
|
||||||
|
|
||||||
class account_document_template(osv.osv):
|
class account_document_template(orm.Model):
|
||||||
|
|
||||||
_computed_lines = {}
|
_computed_lines = {}
|
||||||
_current_template_id = 0
|
_current_template_id = 0
|
||||||
@ -59,12 +59,12 @@ class account_document_template(osv.osv):
|
|||||||
return self._computed_lines[line_number]
|
return self._computed_lines[line_number]
|
||||||
line = self._get_template_line(self._cr, self._uid, self._current_template_id, 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):
|
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))
|
_('Line %s can\'t refer to itself') % str(line_number))
|
||||||
try:
|
try:
|
||||||
self._computed_lines[line_number] = eval(line.python_code.replace('L', 'self.lines'))
|
self._computed_lines[line_number] = eval(line.python_code.replace('L', 'self.lines'))
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise osv.except_osv(_('Error'),
|
raise orm.except_orm(_('Error'),
|
||||||
_('Code "%s" refers to non existing line') % line.python_code)
|
_('Code "%s" refers to non existing line') % line.python_code)
|
||||||
return self._computed_lines[line_number]
|
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}
|
# returns all the lines (included input lines) in the form {line_number: line_amount}
|
||||||
template = self.browse(cr, uid, template_id)
|
template = self.browse(cr, uid, template_id)
|
||||||
if len(input_lines) != self._input_lines(cr, uid, template):
|
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)
|
_('Inconsistency between input lines and filled lines for template %s') % template.name)
|
||||||
self._current_template_id = template.id
|
self._current_template_id = template.id
|
||||||
self._cr = cr
|
self._cr = cr
|
||||||
@ -92,9 +92,7 @@ class account_document_template(osv.osv):
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
account_document_template()
|
class account_document_template_line(orm.Model):
|
||||||
|
|
||||||
class account_document_template_line(osv.osv):
|
|
||||||
|
|
||||||
_name = 'account.document.template.line'
|
_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),
|
'type': fields.selection([('computed', 'Computed'),('input', 'User input')], 'Type', required=True),
|
||||||
'python_code':fields.text('Python Code'),
|
'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 _
|
from openerp.tools.translate import _
|
||||||
|
|
||||||
class account_move_template(osv.osv):
|
class account_move_template(orm.Model):
|
||||||
|
|
||||||
_inherit = 'account.document.template'
|
_inherit = 'account.document.template'
|
||||||
_name = 'account.move.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 is "cross-journals", the Journals must be different,' \
|
||||||
'if the template does not "cross-journals" the Journals must be the same!',
|
'if the template does not "cross-journals" the Journals must be the same!',
|
||||||
['journal_id'])]
|
['journal_id'])]
|
||||||
|
|
||||||
account_move_template()
|
|
||||||
|
|
||||||
class account_move_template_line(osv.osv):
|
class account_move_template_line(orm.Model):
|
||||||
|
|
||||||
_name = 'account.move.template.line'
|
_name = 'account.move.template.line'
|
||||||
_inherit = 'account.document.template.line'
|
_inherit = 'account.document.template.line'
|
||||||
@ -81,5 +79,3 @@ class account_move_template_line(osv.osv):
|
|||||||
_sql_constraints = [
|
_sql_constraints = [
|
||||||
('sequence_template_uniq', 'unique (template_id,sequence)', 'The sequence of the line must be unique per template !')
|
('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">
|
<record id="view_move_template_line_tree" model="ir.ui.view">
|
||||||
<field name="name">account.move.template.line.tree</field>
|
<field name="name">account.move.template.line.tree</field>
|
||||||
<field name="model">account.move.template.line</field>
|
<field name="model">account.move.template.line</field>
|
||||||
<field name="type">tree</field>
|
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<tree string="Journal Entry Template Line">
|
<tree string="Journal Entry Template Line">
|
||||||
<field name="sequence"/>
|
<field name="sequence"/>
|
||||||
@ -25,7 +24,6 @@
|
|||||||
<record id="view_move_template_line_form" model="ir.ui.view">
|
<record id="view_move_template_line_form" model="ir.ui.view">
|
||||||
<field name="name">account.move.template.line.form</field>
|
<field name="name">account.move.template.line.form</field>
|
||||||
<field name="model">account.move.template.line</field>
|
<field name="model">account.move.template.line</field>
|
||||||
<field name="type">form</field>
|
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<form string="Journal Entry Template Line">
|
<form string="Journal Entry Template Line">
|
||||||
<field colspan="4" name="name" select="1"/>
|
<field colspan="4" name="name" select="1"/>
|
||||||
@ -46,7 +44,6 @@
|
|||||||
<record id="view_move_template_form" model="ir.ui.view">
|
<record id="view_move_template_form" model="ir.ui.view">
|
||||||
<field name="name">account.move.template.form</field>
|
<field name="name">account.move.template.form</field>
|
||||||
<field name="model">account.move.template</field>
|
<field name="model">account.move.template</field>
|
||||||
<field name="type">form</field>
|
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<form string="Journal Entry Template">
|
<form string="Journal Entry Template">
|
||||||
<field name="name"/>
|
<field name="name"/>
|
||||||
@ -61,7 +58,6 @@
|
|||||||
<record id="view_move_template_tree" model="ir.ui.view">
|
<record id="view_move_template_tree" model="ir.ui.view">
|
||||||
<field name="name">account.move.template.tree</field>
|
<field name="name">account.move.template.tree</field>
|
||||||
<field name="model">account.move.template</field>
|
<field name="model">account.move.template</field>
|
||||||
<field name="type">tree</field>
|
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<tree string="Journal Entry Template">
|
<tree string="Journal Entry Template">
|
||||||
<field name="name"/>
|
<field name="name"/>
|
||||||
@ -73,7 +69,6 @@
|
|||||||
<record id="view_move_template_search" model="ir.ui.view">
|
<record id="view_move_template_search" model="ir.ui.view">
|
||||||
<field name="name">account.move.template.search</field>
|
<field name="name">account.move.template.search</field>
|
||||||
<field name="model">account.move.template</field>
|
<field name="model">account.move.template</field>
|
||||||
<field name="type">search</field>
|
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<search string="Journal Entry Template">
|
<search string="Journal Entry Template">
|
||||||
<group>
|
<group>
|
||||||
@ -94,6 +89,6 @@
|
|||||||
</record>
|
</record>
|
||||||
<menuitem
|
<menuitem
|
||||||
action="action_move_template_form" id="menu_action_move_template_form" sequence="5"
|
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>
|
</data>
|
||||||
</openerp>
|
</openerp>
|
||||||
|
@ -19,11 +19,11 @@
|
|||||||
#
|
#
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
from openerp.osv import fields,osv
|
from openerp.osv import fields,orm
|
||||||
import time
|
import time
|
||||||
from openerp.tools.translate import _
|
from openerp.tools.translate import _
|
||||||
|
|
||||||
class wizard_select_template(osv.osv_memory):
|
class wizard_select_template(orm.TransientModel):
|
||||||
|
|
||||||
_name = "wizard.select.move.template"
|
_name = "wizard.select.move.template"
|
||||||
_columns = {
|
_columns = {
|
||||||
@ -55,6 +55,8 @@ class wizard_select_template(osv.osv_memory):
|
|||||||
wizard = self.browse(cr, uid, ids, context=context)[0]
|
wizard = self.browse(cr, uid, ids, context=context)[0]
|
||||||
template_pool = self.pool.get('account.move.template')
|
template_pool = self.pool.get('account.move.template')
|
||||||
wizard_line_pool = self.pool.get('wizard.select.move.template.line')
|
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)
|
template = template_pool.browse(cr, uid, wizard.template_id.id)
|
||||||
for line in template.template_line_ids:
|
for line in template.template_line_ids:
|
||||||
if line.type == 'input':
|
if line.type == 'input':
|
||||||
@ -69,7 +71,20 @@ class wizard_select_template(osv.osv_memory):
|
|||||||
if not wizard.line_ids:
|
if not wizard.line_ids:
|
||||||
return self.load_template(cr, uid, ids)
|
return self.load_template(cr, uid, ids)
|
||||||
wizard.write({'state': 'template_selected'})
|
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):
|
def load_template(self, cr, uid, ids, context=None):
|
||||||
template_obj = self.pool.get('account.move.template')
|
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')
|
mod_obj = self.pool.get('ir.model.data')
|
||||||
wizard = self.browse(cr, uid, ids, context=context)[0]
|
wizard = self.browse(cr, uid, ids, context=context)[0]
|
||||||
if not template_obj.check_zero_lines(cr, uid, wizard):
|
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 = {}
|
input_lines = {}
|
||||||
|
|
||||||
for template_line in wizard.line_ids:
|
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)
|
period_id = account_period_obj.find(cr, uid, context=context)
|
||||||
if not period_id:
|
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]
|
period_id = period_id[0]
|
||||||
|
|
||||||
computed_lines = template_obj.compute_lines(cr, uid, wizard.template_id.id, input_lines)
|
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
|
analytic_account_id = False
|
||||||
if line.analytic_account_id:
|
if line.analytic_account_id:
|
||||||
if not line.journal_id.analytic_journal_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!")
|
_("You have to define an analytic journal on the '%s' journal!")
|
||||||
% (line.journal_id.name,))
|
% (line.journal_id.name,))
|
||||||
analytic_account_id = line.analytic_account_id.id
|
analytic_account_id = line.analytic_account_id.id
|
||||||
@ -161,7 +176,7 @@ class wizard_select_template(osv.osv_memory):
|
|||||||
analytic_account_id = False
|
analytic_account_id = False
|
||||||
if line.analytic_account_id:
|
if line.analytic_account_id:
|
||||||
if not line.journal_id.analytic_journal_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!")
|
_("You have to define an analytic journal on the '%s' journal!")
|
||||||
% (wizard.template_id.journal_id.name,))
|
% (wizard.template_id.journal_id.name,))
|
||||||
analytic_account_id = line.analytic_account_id.id
|
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]
|
val['debit'] = computed_lines[line.sequence]
|
||||||
id_line = account_move_line_obj.create(cr, uid, val)
|
id_line = account_move_line_obj.create(cr, uid, val)
|
||||||
return id_line
|
return id_line
|
||||||
|
|
||||||
wizard_select_template()
|
|
||||||
|
|
||||||
class wizard_select_template_line(osv.osv_memory):
|
class wizard_select_template_line(orm.TransientModel):
|
||||||
_description = 'Template Lines'
|
_description = 'Template Lines'
|
||||||
_name = "wizard.select.move.template.line"
|
_name = "wizard.select.move.template.line"
|
||||||
_columns = {
|
_columns = {
|
||||||
@ -198,5 +211,3 @@ class wizard_select_template_line(osv.osv_memory):
|
|||||||
], 'Move Line Type', required=True,readonly=True),
|
], 'Move Line Type', required=True,readonly=True),
|
||||||
'amount': fields.float('Amount', required=True),
|
'amount': fields.float('Amount', required=True),
|
||||||
}
|
}
|
||||||
|
|
||||||
wizard_select_template_line()
|
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
<record id="wizard_select_template" model="ir.ui.view">
|
<record id="wizard_select_template" model="ir.ui.view">
|
||||||
<field name="name">Select Move Template</field>
|
<field name="name">Select Move Template</field>
|
||||||
<field name="model">wizard.select.move.template</field>
|
<field name="model">wizard.select.move.template</field>
|
||||||
<field name="type">form</field>
|
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<form string="Move Template" >
|
<form string="Move Template" >
|
||||||
<group col="2" width="600" height="500">
|
<group col="2" width="600" height="500">
|
||||||
@ -29,7 +28,6 @@
|
|||||||
<record id="wizard_select_template_line" model="ir.ui.view">
|
<record id="wizard_select_template_line" model="ir.ui.view">
|
||||||
<field name="name">Select Move Template Line</field>
|
<field name="name">Select Move Template Line</field>
|
||||||
<field name="model">wizard.select.move.template.line</field>
|
<field name="model">wizard.select.move.template.line</field>
|
||||||
<field name="type">form</field>
|
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<form string="Move Template Line">
|
<form string="Move Template Line">
|
||||||
<group col="2">
|
<group col="2">
|
||||||
@ -46,7 +44,6 @@
|
|||||||
<record id="wizard_select_template_line_tree" model="ir.ui.view">
|
<record id="wizard_select_template_line_tree" model="ir.ui.view">
|
||||||
<field name="name">Select Move Template Line</field>
|
<field name="name">Select Move Template Line</field>
|
||||||
<field name="model">wizard.select.move.template.line</field>
|
<field name="model">wizard.select.move.template.line</field>
|
||||||
<field name="type">tree</field>
|
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<tree string="Move Template Line" editable="bottom">
|
<tree string="Move Template Line" editable="bottom">
|
||||||
<field name="sequence" invisible="1"/>
|
<field name="sequence" invisible="1"/>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user