avanzosc team mailing list archive
-
avanzosc team
-
Mailing list archive
-
Message #00445
[Merge] lp:~dani-ds/avanzosc/72horas into lp:~avanzosc-security-team/avanzosc/72horas
Daniel Campos (Avanzosc) has proposed merging lp:~dani-ds/avanzosc/72horas into lp:~avanzosc-security-team/avanzosc/72horas.
Requested reviews:
Avanzosc_security (avanzosc-security-team)
For more details, see:
https://code.launchpad.net/~dani-ds/avanzosc/72horas/+merge/222913
dos_account_fix_compute: Refactorizado para v7/8
--
https://code.launchpad.net/~dani-ds/avanzosc/72horas/+merge/222913
Your team Avanzosc_security is requested to review the proposed merge of lp:~dani-ds/avanzosc/72horas into lp:~avanzosc-security-team/avanzosc/72horas.
=== modified file 'dos_account_fix_compute/__openerp__.py'
--- dos_account_fix_compute/__openerp__.py 2014-06-11 10:23:47 +0000
+++ dos_account_fix_compute/__openerp__.py 2014-06-12 10:20:29 +0000
@@ -21,17 +21,16 @@
{
- "name" : "DOS Account Fix Compute",
- "version" : "1.0",
- "author" : "DOS",
- "category" : "Account",
- "website" : "www.dos-sl.es",
- "description": "This module fix compute calculations of accounts.",
- "depends" : ["account"],
- "init_xml" : [],
- "update_xml" : [],
- "active": False,
- "installable": True
+ 'name' : 'DOS Account Fix Compute',
+ 'version' : '1.0',
+ 'author' : 'DOS',
+ 'category' : 'Account',
+ 'website' : 'www.dos-sl.es',
+ 'description': 'This module fix compute calculations of accounts.',
+ 'depends' : ['account'],
+ 'data': [],
+ 'active': False,
+ 'installable': True
}
=== added directory 'dos_account_fix_compute/models'
=== renamed file 'dos_account_fix_compute/account.py' => 'dos_account_fix_compute/models/account.py'
--- dos_account_fix_compute/account.py 2014-06-11 10:23:47 +0000
+++ dos_account_fix_compute/models/account.py 2014-06-12 10:20:29 +0000
@@ -19,152 +19,156 @@
#
##############################################################################
-import netsvc
-from osv import fields, osv
-import decimal_precision as dp
-from tools.translate import _
-
-class account_account(osv.osv):
-
- _inherit ="account.account"
-
- def __compute(self, cr, uid, ids, field_names, arg=None, context=None,
- query='', query_params=()):
- """ compute the balance, debit and/or credit for the provided
- account ids
- Arguments:
- `ids`: account ids
- `field_names`: the fields to compute (a list of any of
- 'balance', 'debit' and 'credit')
- `arg`: unused fields.function stuff
- `query`: additional query filter (as a string)
- `query_params`: parameters for the provided query string
- (__compute will handle their escaping) as a
- tuple
- """
-
- mapping = {
- 'balance': "COALESCE(SUM(balance),0) as balance",
- 'debit': "COALESCE(SUM(debit), 0) as debit",
- 'credit': "COALESCE(SUM(credit), 0) as credit"
- }
- #get all the necessary accounts
- children_and_consolidated = ids
-
- #compute for each account the balance/debit/credit from the move lines
- accounts = {}
- if children_and_consolidated:
- aml_query = self.pool.get('account.move.line')._query_get(cr, uid, context=context)
-
- wheres = [""]
- if query.strip():
- wheres.append(query.strip())
- if aml_query.strip():
- wheres.append(aml_query.strip())
- filters = " AND ".join(wheres)
-
- self.logger.notifyChannel('addons.'+self._name, netsvc.LOG_DEBUG,
- 'Filters: %s'%filters)
-
- # Compute credit, debit, balane
-
-
- request = ("SELECT id, " \
- " MIN(code) As code, " \
- +\
- ', '.join(map(mapping.__getitem__, field_names)) +
- " FROM " \
- " ( " \
- " SELECT aa_tree_1.id As id, " \
- " aa_tree_1.code AS code, " \
- " aa_tree_1.currency_id AS to_currency, " \
- " c.rate AS to_rate, " \
- " aa_tree_2.code AS code2, " \
- " aa_tree_2.currency_id AS from_currency, " \
- " c2.rate AS from_rate, " \
- " l.period_id, " \
- " l.date As date, " \
- " ROUND(l.debit * (COALESCE(c.rate,1) / COALESCE(c2.rate,1)), 2) AS debit, " \
- " ROUND(l.credit * (COALESCE(c.rate,1) / COALESCE(c2.rate,1)), 2) AS credit, " \
- " ROUND((l.debit * (COALESCE(c.rate,1) / COALESCE(c2.rate,1))) - (l.credit * (COALESCE(c.rate,1) / COALESCE(c2.rate,1))), 2) AS balance " \
- " FROM account_account aa_tree_1 " \
- " INNER JOIN account_account aa_tree_2 " \
- " ON aa_tree_2.parent_left " \
- " BETWEEN aa_tree_1.parent_left AND aa_tree_1.parent_right " \
- " AND aa_tree_1.company_id=aa_tree_2.company_id " \
- " LEFT JOIN ( " \
- " SELECT c.id, r.rate " \
- " FROM res_currency c " \
- " INNER JOIN res_currency_rate r ON c.id=r.currency_id " \
- " GROUP BY c.id, r.name, r.rate " \
- " HAVING r.name = MAX(r.name) " \
- " LIMIT 1 " \
- " ) c ON c.id = aa_tree_1.currency_id " \
- " LEFT JOIN ( " \
- " SELECT c.id, r.rate " \
- " FROM res_currency c " \
- " INNER JOIN res_currency_rate r ON c.id=r.currency_id " \
- " GROUP BY c.id, r.name, r.rate " \
- " HAVING r.name = MAX(r.name) " \
- " LIMIT 1 " \
- " ) c2 ON c2.id = aa_tree_2.currency_id " \
- " INNER JOIN account_move_line l" \
- " ON l.account_id = aa_tree_2.id " \
- " WHERE aa_tree_1.id IN %s " \
- + filters +
- " ) a " \
- " GROUP BY a.id")
-
- """
- request = ("SELECT aa_tree_1.id, " \
- "MIN(aa_tree_1.code) AS code, " \
- +\
- ', '.join(map(mapping.__getitem__, field_names)) +
- " FROM account_account aa_tree_1" \
- " INNER JOIN account_account aa_tree_2" \
- " ON aa_tree_2.parent_left" \
- " BETWEEN aa_tree_1.parent_left AND aa_tree_1.parent_right" \
- " AND aa_tree_1.company_id=aa_tree_2.company_id" \
- " INNER JOIN account_move_line l" \
- " ON l.account_id = aa_tree_2.id" \
- " WHERE aa_tree_1.id IN %s " \
- + filters +
- " GROUP BY aa_tree_1.id")
- """
-
- params = (tuple(children_and_consolidated),) + query_params
- cr.execute(request, params)
-
- self.logger.notifyChannel('addons.'+self._name, netsvc.LOG_DEBUG,
- 'Status: %s'%cr.statusmessage)
-
- for res in cr.dictfetchall():
- accounts[res['id']] = res
-
- # consolidate accounts with direct children
- children_and_consolidated.reverse()
- brs = list(self.browse(cr, uid, children_and_consolidated, context=context))
- sums = {}
-
- while brs:
- current = brs[0]
-
- brs.pop(0)
- for fn in field_names:
- sums.setdefault(current.id, {})[fn] = accounts.get(current.id, {}).get(fn, 0.0)
-
- res = {}
- null_result = dict((fn, 0.0) for fn in field_names)
- for acc_id in ids:
- res[acc_id] = sums.get(acc_id, null_result)
-
- return res
-
-
- _columns = {
- 'balance': fields.function(__compute, digits_compute=dp.get_precision('Account'), method=True, string='Balance', multi='balance'),
- 'credit': fields.function(__compute, digits_compute=dp.get_precision('Account'), method=True, string='Credit', multi='balance'),
- 'debit': fields.function(__compute, digits_compute=dp.get_precision('Account'), method=True, string='Debit', multi='balance'),
- }
-
-account_account()
+from openerp import netsvc
+from openerp.osv import fields
+from openerp.osv import osv
+import openerp.addons.decimal_precision as dp
+from openerp.tools.translate import _
+
+
+class AccountAccount(osv.osv):
+
+ _inherit = "AccountAccount"
+
+ def __compute(self, cr, uid, ids, field_names, arg=None, context=None,
+ query='', query_params=()):
+
+ """ compute the balance, debit and/or credit
+ for the provided account ids
+ Arguments:
+ `ids`: account ids
+ `field_names`: the fields to compute (a list of any of
+ 'balance', 'debit' and 'credit')
+ `arg`: unused fields.function stuff
+ `query`: additional query filter (as a string)
+ `query_params`: parameters for the provided query string
+ (__compute will handle their escaping) as a tuple
+ """
+
+ mapping = {'balance': "COALESCE(SUM(balance),0) as balance",
+ 'debit': "COALESCE(SUM(debit), 0) as debit",
+ 'credit': "COALESCE(SUM(credit), 0) as credit"}
+ # get all the necessary accounts
+ children_and_consolidated = ids
+ accounts = {}
+ # compute for each account the balance/debit/credit from the move lines
+ if children_and_consolidated:
+ acc_mline_obj = self.pool['account.move.line']
+ aml_query = acc_mline_obj ._query_get(cr, uid, context=context)
+
+ wheres = [""]
+ if query.strip():
+ wheres.append(query.strip())
+ if aml_query.strip():
+ wheres.append(aml_query.strip())
+ filters = " AND ".join(wheres)
+
+ self.logger.notifyChannel('addons.'+self._name, netsvc.LOG_DEBUG,
+ 'Filters: %s' % filters)
+
+ # Compute credit, debit, balane
+
+ request = ("SELECT id, "
+ " MIN(code) As code, " +
+ ', '.join(map(mapping.__getitem__, field_names)) +
+ " FROM "
+ " ( "
+ " SELECT aa_tree_1.id As id, "
+ " aa_tree_1.code AS code, "
+ " aa_tree_1.currency_id AS to_currency, "
+ " c.rate AS to_rate, "
+ " aa_tree_2.code AS code2, "
+ " aa_tree_2.currency_id AS from_currency, "
+ " c2.rate AS from_rate, "
+ " l.period_id, "
+ " l.date As date, "
+ " ROUND(l.debit * (COALESCE(c.rate,1) / "
+ "COALESCE(c2.rate,1)), 2) AS debit, "
+ " ROUND(l.credit * (COALESCE(c.rate,1) / "
+ "COALESCE(c2.rate,1)), 2) AS credit, "
+ " ROUND((l.debit * (COALESCE(c.rate,1) / "
+ "COALESCE(c2.rate,1))) - (l.credit * "
+ "(COALESCE(c.rate,1) / "
+ "COALESCE(c2.rate,1))), 2) AS balance "
+ " FROM account_account aa_tree_1 "
+ " INNER JOIN account_account aa_tree_2 "
+ " ON aa_tree_2.parent_left "
+ " BETWEEN aa_tree_1.parent_left AND"
+ " aa_tree_1.parent_right "
+ " AND aa_tree_1.company_id = aa_tree_2.company_id"
+ " LEFT JOIN ( "
+ " SELECT c.id, r.rate "
+ " FROM res_currency c "
+ " INNER JOIN res_currency_rate r "
+ " ON c.id=r.currency_id "
+ " GROUP BY c.id, r.name, r.rate "
+ " HAVING r.name = MAX(r.name) "
+ " LIMIT 1 "
+ " ) c ON c.id = aa_tree_1.currency_id "
+ " LEFT JOIN ( "
+ " SELECT c.id, r.rate "
+ " FROM res_currency c "
+ " INNER JOIN res_currency_rate r ON"
+ " c.id=r.currency_id "
+ " GROUP BY c.id, r.name, r.rate "
+ " HAVING r.name = MAX(r.name) "
+ " LIMIT 1 "
+ " ) c2 ON c2.id = aa_tree_2.currency_id "
+ " INNER JOIN account_move_line l"
+ " ON l.account_id = aa_tree_2.id "
+ " WHERE aa_tree_1.id IN %s "
+ + filters +
+ " ) a "
+ " GROUP BY a.id")
+ """
+ request = ("SELECT aa_tree_1.id, " \
+ "MIN(aa_tree_1.code) AS code, " \
+ +\
+ ', '.join(map(mapping.__getitem__, field_names)) +
+ " FROM account_account aa_tree_1" \
+ " INNER JOIN account_account aa_tree_2" \
+ " ON aa_tree_2.parent_left" \
+ " BETWEEN aa_tree_1.parent_left AND "
+ " aa_tree_1.parent_right" \
+ " AND aa_tree_1.company_id=aa_tree_2.company_id" \
+ " INNER JOIN account_move_line l" \
+ " ON l.account_id = aa_tree_2.id" \
+ " WHERE aa_tree_1.id IN %s " \
+ + filters +
+ " GROUP BY aa_tree_1.id")
+ """
+ params = (tuple(children_and_consolidated),) + query_params
+ cr.execute(request, params)
+ self.logger.notifyChannel('addons.'+self._name, netsvc.LOG_DEBUG,
+ 'Status: %s' % cr.statusmessage)
+
+ for res in cr.dictfetchall():
+ accounts[res['id']] = res
+
+ # consolidate accounts with direct children
+ children_and_consolidated.reverse()
+ brs = list(self.browse(cr, uid, children_and_consolidated,
+ context=context))
+ sums = {}
+ while brs:
+ current = brs[0]
+ brs.pop(0)
+ for fn in field_names:
+ result_1 = accounts.get(current.id, {}).get(fn, 0.0)
+ sums.setdefault(current.id, {})[fn] = result_1
+ res = {}
+ null_result = dict((fn, 0.0) for fn in field_names)
+ for acc_id in ids:
+ res[acc_id] = sums.get(acc_id, null_result)
+ return res
+
+ _columns = {'balance': fields.function(__compute, method=True,
+ digits_compute=dp.get_precision('Account'),
+ string='Balance', multi='balance'),
+ 'credit': fields.function(__compute, method=True,
+ digits_compute=dp.get_precision('Account'),
+ string='Credit', multi='balance'),
+ 'debit': fields.function(__compute, method=True,
+ digits_compute=dp.get_precision('Account'),
+ string='Debit', multi='balance'),
+ }
Follow ups