mirror of
https://github.com/NaN-tic/trytond-patches.git
synced 2023-12-14 06:03:03 +01:00
141 lines
5.5 KiB
Diff
141 lines
5.5 KiB
Diff
Index: account.py
|
|
===================================================================
|
|
|
|
--- ./trytond/trytond/modules/analytic_account/account.py
|
|
+++ ./trytond/trytond/modules/analytic_account/account.py
|
|
@@ -120,17 +120,8 @@
|
|
def get_balance(cls, accounts, name):
|
|
res = {}
|
|
pool = Pool()
|
|
- Line = pool.get('analytic_account.line')
|
|
- MoveLine = pool.get('account.move.line')
|
|
- Account = pool.get('account.account')
|
|
- Company = pool.get('company.company')
|
|
Currency = pool.get('currency.currency')
|
|
cursor = Transaction().cursor
|
|
- table = cls.__table__()
|
|
- line = Line.__table__()
|
|
- move_line = MoveLine.__table__()
|
|
- a_account = Account.__table__()
|
|
- company = Company.__table__()
|
|
|
|
ids = [a.id for a in accounts]
|
|
childs = cls.search([('parent', 'child_of', ids)])
|
|
@@ -141,22 +132,8 @@
|
|
for account in all_accounts:
|
|
id2account[account.id] = account
|
|
|
|
- line_query = Line.query_get(line)
|
|
- cursor.execute(*table.join(line, 'LEFT',
|
|
- condition=table.id == line.account
|
|
- ).join(move_line, 'LEFT',
|
|
- condition=move_line.id == line.move_line
|
|
- ).join(a_account, 'LEFT',
|
|
- condition=a_account.id == move_line.account
|
|
- ).join(company, 'LEFT',
|
|
- condition=company.id == a_account.company
|
|
- ).select(table.id,
|
|
- Sum(Coalesce(line.debit, 0) - Coalesce(line.credit, 0)),
|
|
- company.currency,
|
|
- where=(table.type != 'view')
|
|
- & table.id.in_(all_ids)
|
|
- & table.active & line_query,
|
|
- group_by=(table.id, company.currency)))
|
|
+ query = cls._query_get(all_ids, name)
|
|
+ cursor.execute(*query)
|
|
account_sum = {}
|
|
id2currency = {}
|
|
for account_id, sum, currency_id in cursor.fetchall():
|
|
@@ -194,17 +171,8 @@
|
|
def get_credit_debit(cls, accounts, name):
|
|
res = {}
|
|
pool = Pool()
|
|
- Line = pool.get('analytic_account.line')
|
|
- MoveLine = pool.get('account.move.line')
|
|
- Account = pool.get('account.account')
|
|
- Company = pool.get('company.company')
|
|
Currency = pool.get('currency.currency')
|
|
cursor = Transaction().cursor
|
|
- table = cls.__table__()
|
|
- line = Line.__table__()
|
|
- move_line = MoveLine.__table__()
|
|
- a_account = Account.__table__()
|
|
- company = Company.__table__()
|
|
|
|
if name not in ('credit', 'debit'):
|
|
raise Exception('Bad argument')
|
|
@@ -215,22 +183,8 @@
|
|
res[account.id] = Decimal('0.0')
|
|
id2account[account.id] = account
|
|
|
|
- line_query = Line.query_get(line)
|
|
- cursor.execute(*table.join(line, 'LEFT',
|
|
- condition=table.id == line.account
|
|
- ).join(move_line, 'LEFT',
|
|
- condition=move_line.id == line.move_line
|
|
- ).join(a_account, 'LEFT',
|
|
- condition=a_account.id == move_line.account
|
|
- ).join(company, 'LEFT',
|
|
- condition=company.id == a_account.company
|
|
- ).select(table.id,
|
|
- Sum(Coalesce(Column(line, name), 0)),
|
|
- company.currency,
|
|
- where=(table.type != 'view')
|
|
- & table.id.in_(ids)
|
|
- & table.active & line_query,
|
|
- group_by=(table.id, company.currency)))
|
|
+ query = cls._query_get(ids, name)
|
|
+ cursor.execute(*query)
|
|
|
|
id2currency = {}
|
|
for account_id, sum, currency_id in cursor.fetchall():
|
|
@@ -247,6 +201,48 @@
|
|
res[account_id] += id2account[account_id].currency.round(sum)
|
|
return res
|
|
|
|
+ @classmethod
|
|
+ def _query_get(cls, ids, name):
|
|
+ pool = Pool()
|
|
+ Line = pool.get('analytic_account.line')
|
|
+ MoveLine = pool.get('account.move.line')
|
|
+ Account = pool.get('account.account')
|
|
+ Company = pool.get('company.company')
|
|
+ table = cls.__table__()
|
|
+ line = Line.__table__()
|
|
+ move_line = MoveLine.__table__()
|
|
+ a_account = Account.__table__()
|
|
+ company = Company.__table__()
|
|
+
|
|
+ join = table.join(line, 'LEFT',
|
|
+ condition=table.id == line.account
|
|
+ ).join(move_line, 'LEFT',
|
|
+ condition=move_line.id == line.move_line
|
|
+ ).join(a_account, 'LEFT',
|
|
+ condition=a_account.id == move_line.account
|
|
+ ).join(company, 'LEFT',
|
|
+ condition=company.id == a_account.company
|
|
+ )
|
|
+
|
|
+ line_query = Line.query_get(line)
|
|
+ if name == 'balance':
|
|
+ return join.select(table.id,
|
|
+ Sum(Coalesce(line.debit, 0) - Coalesce(line.credit, 0)),
|
|
+ company.currency,
|
|
+ where=(table.type != 'view')
|
|
+ & table.id.in_(ids)
|
|
+ & table.active & line_query,
|
|
+ group_by=(table.id, company.currency))
|
|
+ elif name in ('credit', 'debit'):
|
|
+ return join.select(table.id,
|
|
+ Sum(Coalesce(Column(line, name), 0)),
|
|
+ company.currency,
|
|
+ where=(table.type != 'view')
|
|
+ & table.id.in_(ids)
|
|
+ & table.active & line_query,
|
|
+ group_by=(table.id, company.currency))
|
|
+ return None
|
|
+
|
|
def get_rec_name(self, name):
|
|
if self.code:
|
|
return self.code + ' - ' + unicode(self.name)
|
|
|