Merge lp:~vauxoo/account-management/hbto_acc_mng_v6_fnctl_field into lp:account-management

Proposed by hbto [Vauxoo] http://www.vauxoo.com
Status: Needs review
Proposed branch: lp:~vauxoo/account-management/hbto_acc_mng_v6_fnctl_field
Merge into: lp:account-management
Diff against target: 145 lines (+110/-2)
2 files modified
account_management/model/account_company.py (+83/-0)
account_management/view/account_company.xml (+27/-2)
To merge this branch: bzr merge lp:~vauxoo/account-management/hbto_acc_mng_v6_fnctl_field
Reviewer Review Type Date Requested Status
Gabriela Quilarque Pending
Review via email: mp+87058@code.launchpad.net

Description of the change

Added Functional field to the account.account model
so now it is possible to check which record are related
to a particular account, be it from the account.account
form view or through the panel action, whenever the
foreign key related on that account_id is always being recorded on db,

This change DOES NOT apply to property fields of
account.account due to the innate nature of those fields

To post a comment you must log in.
396. By hbto [Vauxoo] http://www.vauxoo.com

[FIX] Fixing/Modifying use of postgres v 9.x Function CONCAT by
the string operator || so it is compatible with the pg v8.4

Unmerged revisions

396. By hbto [Vauxoo] http://www.vauxoo.com

[FIX] Fixing/Modifying use of postgres v 9.x Function CONCAT by
the string operator || so it is compatible with the pg v8.4

395. By hbto [Vauxoo] http://www.vauxoo.com

[ADD] New View for model account.account.records
[ADD] New way to compute id for sql view.

394. By hbto [Vauxoo] http://www.vauxoo.com

[ADD] Minor Changes to accomplish functional field

393. By hbto [Vauxoo] http://www.vauxoo.com

[ADD] Add new model that holds the record for a given account_id

392. By hbto [Vauxoo] http://www.vauxoo.com

[ADD] Added new functional fields to account.account
so that it can now show which record bear an account_id
related to that record

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'account_management/model/account_company.py'
2--- account_management/model/account_company.py 2011-12-08 21:45:33 +0000
3+++ account_management/model/account_company.py 2012-01-05 16:25:26 +0000
4@@ -24,6 +24,7 @@
5 ##############################################################################
6 from osv import osv
7 from osv import fields
8+import tools
9 from tools.translate import _
10
11 __AYUDA__ = '''
12@@ -156,11 +157,93 @@
13 el codigo contable de la misma.'
14 '''
15
16+def _links_get(self, cr, uid, context=None):
17+ """Gets links value for reference field
18+ @param self: The object pointer
19+ @param cr: the current row, from the database cursor,
20+ @param uid: the current user’s ID for security checks,
21+ @param context: A standard dictionary for contextual values
22+ """
23+ obj = self.pool.get('ir.model.fields')
24+ ids = obj.search(cr,uid,[('ttype','=','many2one'),('relation','=','account.account'),('model','!=','account.account')])
25+ ids = list(set([i['model_id'][0] for i in obj.read(cr,uid,ids,['model_id'])]))
26+ obj = self.pool.get('ir.model')
27+ res = obj.read(cr, uid, ids, ['model', 'name'], context)
28+ return [(r['model'], r['name']) for r in res]
29+
30+class account_account_records(osv.osv):
31+ _name = 'account.account.records'
32+ _auto = False
33+ _description = 'Records by Accounts'
34+ _rec_name = 'record_id'
35+ _columns = {
36+ 'record_id':fields.reference('Record',selection=_links_get,size=128,readonly=True),
37+ 'model_id':fields.many2one('ir.model', 'Model',readonly=True),
38+ 'value_id':fields.integer('Value',readonly=True),
39+ 'field_id':fields.many2one('ir.model.fields', 'Field',readonly=True),
40+ }
41+ def _get_records(self, cr, uid=1, id=None, context=None):
42+ if context is None:
43+ context = {}
44+ res=[]
45+
46+ imf_obj = self.pool.get('ir.model.fields')
47+ #~ imf_ids = imf_obj.search(cr,uid,[('ttype','=','many2one'),('relation','=','account.account'),('model','!=','account.account'),('view_load','=',False)])
48+ imf_ids = imf_obj.search(cr,uid,[('ttype','=','many2one'),('relation','=','account.account'),('model','!=','account.account')])
49+
50+ if imf_ids:
51+ for each in imf_obj.browse(cr, uid, imf_ids, context=context):
52+ if not each.model_id.osv_memory:
53+ cr.execute("""SELECT attname FROM pg_attribute WHERE attrelid = (SELECT oid FROM pg_class WHERE relname = '%s') AND attname = '%s'"""%(each.model.replace('.','_'),each.name))
54+ value = cr.fetchall()
55+ if not value:
56+ continue
57+
58+ res.append("""SELECT COALESCE(%s,NULL) as value_id, CASE WHEN id > 0 THEN (%s || id) END AS record_id, CASE WHEN id > 0 THEN %s END AS field_id, CASE WHEN id > 0 THEN %s END AS model_id, CASE WHEN id > 0 THEN (%s * %s + id) END AS id FROM %s"""%(each.name,"'%s,'"%each.model,each.id,each.model_id.id,each.id,each.model_id.id,each.model.replace('.','_')))
59+ res = ' UNION '.join(res)
60+ return res
61+
62+ def init(self, cr):
63+ tools.drop_view_if_exists(cr, 'account_account_records')
64+ cr.execute("""
65+ CREATE OR REPLACE view account_account_records AS (%s)
66+ """%(self._get_records(cr, 1),))
67+
68+account_account_records()
69+
70+
71 class account_account(osv.osv):
72+ def _get_records(self, cr, uid, ids, fieldname, args, context=None):
73+ if context is None:
74+ context = {}
75+ res={}
76+ for id in ids:
77+ cr.execute('SELECT id FROM account_account_records where value_id = %s'%(id,))
78+ val = cr.fetchall()
79+ if val:
80+ res[id]=[i[0] for i in val]
81+ else:
82+ res[id]=[]
83+ return res
84+
85 _inherit='account.account'
86 _columns={
87 'auto':fields.boolean('AutoCodigo?', help=__auto_help__),
88 'code': fields.char('Code', size=64, required=False),
89+ #~ 'record_ids': fields.many2many('account.account.records',
90+ #~ 'account_account_records',
91+ #~ 'value_id',
92+ #~ 'record_id',
93+ #~ 'Records by account'
94+ #~ ),
95+ 'record_ids': fields.function(
96+ _get_records,
97+ method=True,
98+ relation= 'account.account.records',
99+ type='one2many',
100+ help = 'Show all the record where this account is being used',
101+ string = 'Records by account'
102+ ),
103 }
104
105 def _get_parent(self, cr, uid, code, nivel, patron_nivel, company_id):
106
107=== modified file 'account_management/view/account_company.xml'
108--- account_management/view/account_company.xml 2011-12-08 21:45:33 +0000
109+++ account_management/view/account_company.xml 2012-01-05 16:25:26 +0000
110@@ -49,8 +49,33 @@
111 <field name="parent_id" position="replace">
112 <field name="parent_id" select="1" attrs="{'required':[('auto','=',1)],'readonly':[('auto','=',0)]}"/>
113 </field>
114- </field>
115- </record>
116+ <xpath expr='//page[@string="Notes"]' position='before'>
117+ <page string='Records by account'>
118+ <field name='record_ids' nolabel='1' colspan='4'/>
119+ </page>
120+ </xpath>
121+ </field>
122+ </record>
123+
124+ <record model="ir.ui.view" id="account_account_records_tree">
125+ <field name="name">account.account.records.tree</field>
126+ <field name="model">account.account.records</field>
127+ <field name="type">tree</field>
128+ <field name="arch" type="xml">
129+ <tree string='Records by Account'>
130+ <field name='record_id'/>
131+ <field name='model_id'/>
132+ <field name='field_id'/>
133+ </tree>
134+ </field>
135+ </record>
136+
137+ <act_window
138+ domain="[('value_id', '=', active_id)]"
139+ id="account_accoout_record_action"
140+ name="Records by Account"
141+ res_model="account.account.records"
142+ src_model="account.account"/>
143
144 </data>
145 </openerp>

Subscribers

People subscribed via source and target branches