Reimplement analytic account query_get() classmethod to use internal_currency instead of account.move's currency field

This commit is contained in:
Guillem Barba 2015-02-10 10:54:29 +01:00
parent 3c79b7f2cf
commit 1a2adc2c0e

View file

@ -87,34 +87,29 @@ class AnalyticAccount:
return map(int, pending_accounts)
@classmethod
def _query_get(cls, ids, name):
def query_get(cls, ids, names):
pool = Pool()
Line = pool.get('analytic_account.line')
table = cls.__table__()
line = Line.__table__()
join = table.join(line, 'LEFT',
condition=table.id == line.account
)
line_query = Line.query_get(line)
if name == 'balance':
return join.select(table.id,
Sum(Coalesce(line.debit, 0) - Coalesce(line.credit, 0)),
line.internal_currency,
where=(table.type != 'view')
& table.id.in_(ids)
& table.active & line_query,
group_by=(table.id, line.internal_currency))
elif name in ('credit', 'debit'):
return join.select(table.id,
Sum(Coalesce(Column(line, name), 0)),
line.internal_currency,
where=(table.type != 'view')
& table.id.in_(ids)
& table.active & line_query,
group_by=(table.id, line.internal_currency))
return None
columns = [table.id, line.internal_currency]
for name in names:
if name == 'balance':
columns.append(
Sum(Coalesce(line.debit, 0) - Coalesce(line.credit, 0)))
else:
columns.append(Sum(Coalesce(Column(line, name), 0)))
query = table.join(line, 'LEFT',
condition=table.id == line.account
).select(*columns,
where=(table.type != 'view')
& table.id.in_(ids)
& table.active & line_query,
group_by=(table.id, line.internal_currency))
return query
@classmethod
def validate(cls, accounts):