From 57d0ebb5e6dfcb7b9bb141c74621dc470d2bee5b Mon Sep 17 00:00:00 2001
From: jvo <>
Date: Tue, 15 Jul 2008 15:34:58 +0530
Subject: [PATCH] -Added Use model wizard. -Added 'legend' field on
account.model -Added 'description' field and name_get method on
account.tax."
bzr revid: jvo-20080715100458-0io7neh1n1grgrt3
---
addons/account/account.py | 17 ++++
addons/account/account_view.xml | 6 +-
addons/account/account_wizard.xml | 48 +++++-----
addons/account/wizard/__init__.py | 1 +
addons/account/wizard/wizard_use_model.py | 108 ++++++++++++++++++++++
5 files changed, 155 insertions(+), 25 deletions(-)
create mode 100644 addons/account/wizard/wizard_use_model.py
diff --git a/addons/account/account.py b/addons/account/account.py
index 6eade89acfa..86ee89bca7a 100644
--- a/addons/account/account.py
+++ b/addons/account/account.py
@@ -1086,8 +1086,19 @@ class account_tax(osv.osv):
'ref_tax_sign': fields.float('Tax Code Sign', help="Usualy 1 or -1."),
'include_base_amount': fields.boolean('Include in base amount', help="Indicate if the amount of tax must be included in the base amount for the computation of the next taxes"),
'company_id': fields.many2one('res.company', 'Company', required=True),
+ 'description': fields.char('Description', size=128, required=True),
}
+ def name_get(self, cr, uid, ids, context={}):
+ if not len(ids):
+ return []
+ reads = self.read(cr, uid, ids, ['description'], context)
+ res = []
+ for record in reads:
+ name = record['description']
+ res.append((record['id'],name ))
+ return res
+
def _default_company(self, cr, uid, context={}):
user = self.pool.get('res.users').browse(cr, uid, uid, context=context)
if user.company_id:
@@ -1367,7 +1378,13 @@ class account_model(osv.osv):
'ref': fields.char('Ref', size=64),
'journal_id': fields.many2one('account.journal', 'Journal', required=True),
'lines_id': fields.one2many('account.model.line', 'model_id', 'Model Entries'),
+ 'legend' :fields.text('Legend',readonly=True,size=100),
}
+
+ _defaults = {
+ 'legend':lambda *a:'''You can specify year,month and date in the name of the model using the following labels:\n\n%(year)s : To Specify Year \n%(month)s : To Specify Month \n%(date) : Current Date\n\ne.g. My model on %(date)s''',
+ }
+
def generate(self, cr, uid, ids, datas={}, context={}):
move_ids = []
for model in self.browse(cr, uid, ids, context):
diff --git a/addons/account/account_view.xml b/addons/account/account_view.xml
index 59ec5f8133c..dc7b567795c 100644
--- a/addons/account/account_view.xml
+++ b/addons/account/account_view.xml
@@ -559,7 +559,8 @@
child_ids
-
+
+
@@ -573,6 +574,7 @@
+
@@ -1125,6 +1127,8 @@
+
+
diff --git a/addons/account/account_wizard.xml b/addons/account/account_wizard.xml
index a34130995fe..6c18f8f9b61 100644
--- a/addons/account/account_wizard.xml
+++ b/addons/account/account_wizard.xml
@@ -9,71 +9,71 @@
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
-
+
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
-
+
+
-
+
-
+
-
-
+
+
diff --git a/addons/account/wizard/__init__.py b/addons/account/wizard/__init__.py
index 966fdd56db7..193598b3cbd 100644
--- a/addons/account/wizard/__init__.py
+++ b/addons/account/wizard/__init__.py
@@ -60,3 +60,4 @@ import wizard_account_chart
import wizard_move_line_select
import wizard_validate_account_move
+import wizard_use_model
\ No newline at end of file
diff --git a/addons/account/wizard/wizard_use_model.py b/addons/account/wizard/wizard_use_model.py
new file mode 100644
index 00000000000..c0d0b94e59f
--- /dev/null
+++ b/addons/account/wizard/wizard_use_model.py
@@ -0,0 +1,108 @@
+import wizard
+import time
+import datetime
+import pooler
+
+model_form = """
+"""
+
+model_fields = {
+ 'model': {'string': 'Account Model', 'type': 'many2many', 'relation': 'account.model', 'required': True},
+ }
+
+form = """
+
+"""
+fields = {
+ }
+def _create_entries(self, cr, uid, data, context):
+ pool_obj = pooler.get_pool(cr.dbname)
+ model_ids = data['form']['model'][0][2]
+ data_model = pool_obj.get('account.model').browse(cr,uid,model_ids)
+ move_ids = []
+ for model in data_model:
+
+ period_id = pool_obj.get('account.period').find(cr,uid, context=context)
+ if not period_id:
+ raise wizard.except_wizard('No period found !', 'Unable to find a valid period !')
+ period_id = period_id[0]
+ name = model.name
+ if model.journal_id.sequence_id:
+ name_seq = pool_obj.get('ir.sequence').get_id(cr, uid, model.journal_id.sequence_id.id)
+
+ if name.find("%(year)s") != -1:
+ name=name.decode('utf-8').replace("%(year)s",str(time.strftime("%Y")))
+
+ if name.find("%(month)s") != -1:
+ name=name.decode('utf-8').replace("%(month)s",str(time.strftime("%B")))
+
+ if name.find("%(date)s") != -1:
+ name=name.decode('utf-8').replace("%(date)s",str(time.strftime("%Y-%m-%d")))
+
+ move_id = pool_obj.get('account.move').create(cr, uid, {
+ 'name': str(name_seq) + " : " +name,
+ 'ref': model.ref,
+ 'period_id': period_id,
+ 'journal_id': model.journal_id.id,
+ })
+ move_ids.append(move_id)
+ for line in model.lines_id:
+ val = {
+ 'move_id': move_id,
+ 'journal_id': model.journal_id.id,
+ 'period_id': period_id
+ }
+ val.update({
+ 'name': line.name,
+ 'quantity': line.quantity,
+ 'debit': line.debit,
+ 'credit': line.credit,
+ 'account_id': line.account_id.id,
+ 'move_id': move_id,
+ 'ref': line.ref,
+ 'partner_id': line.partner_id.id,
+ 'date': time.strftime('%Y-%m-%d'),
+ 'date_maturity': time.strftime('%Y-%m-%d')
+ })
+ c = context.copy()
+ c.update({'journal_id': model.journal_id.id,'period_id': period_id})
+ id_line = pool_obj.get('account.move.line').create(cr, uid, val, context=c)
+ data['form']['move_ids']=move_ids
+ return data['form']
+
+class use_model(wizard.interface):
+
+ def _open_moves(self, cr, uid, data, context):
+ pool_obj = pooler.get_pool(cr.dbname)
+ model_data_ids = pool_obj.get('ir.model.data').search(cr,uid,[('model','=','ir.ui.view'),('name','=','view_move_form')])
+ resource_id = pool_obj.get('ir.model.data').read(cr,uid,model_data_ids,fields=['res_id'])[0]['res_id']
+ return {
+ 'domain': "[('id','in', ["+','.join(map(str,data['form']['move_ids']))+"])]",
+ 'name': 'Entries',
+ 'view_type': 'form',
+ 'view_mode': 'tree,form',
+ 'res_model': 'account.move',
+ 'views': [(False,'tree'),(resource_id,'form')],
+ 'type': 'ir.actions.act_window'
+ }
+
+ states = {
+ 'init': {
+ 'actions': [],
+ 'result': {'type':'form', 'arch':model_form, 'fields':model_fields, 'state':[('end','Cancel'),('create','Create Entries')]},
+ },
+ 'create': {
+ 'actions': [_create_entries],
+ 'result': {'type': 'form','arch':form, 'fields':fields, 'state':[('end','Ok'),('open_move','Open')]},
+ },
+ 'open_move': {
+ 'actions': [],
+ 'result': {'type':'action', 'action':_open_moves, 'state':'end'}
+ }
+ }
+
+use_model("account_use_models")
\ No newline at end of file