12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- # -*- coding: utf-8 -*-
- from openerp.http import request as r
- def get_account_voucher_widget():
- user_store = r.env.user.store_id.id
- company_currency_rate = r.env.user.company_id.currency_id.rate
- query = '''
- SELECT voucher.id,
- voucher.number,
- voucher.type,
- voucher.date,
- journal.currency,
- voucher.amount,
- CASE
- WHEN journal.currency IS NULL
- THEN voucher.amount
- ELSE voucher.amount * (%s / (array_agg(rate.rate ORDER BY rate.name DESC))[1])
- END AS amount_currency,
- voucher.journal_id,
- voucher.reference
- FROM account_voucher AS voucher
- LEFT JOIN res_store_journal_rel AS journal_rel
- ON voucher.journal_id = journal_rel.journal_id
- LEFT JOIN account_journal AS journal
- ON journal.id = voucher.journal_id
- LEFT JOIN res_currency_rate AS rate
- ON rate.currency_id = journal.currency
- WHERE voucher.state = 'posted'
- AND TO_CHAR(voucher.date,'YYYY-MM') = TO_CHAR(current_date,'YYYY-MM')
- AND journal_rel.store_id = ''' + str(user_store) + '''
- GROUP BY
- voucher.id,
- voucher.number,
- voucher.type,
- voucher.date,
- voucher.amount,
- journal.name,
- journal.currency
- '''
- r.cr.execute(query,(tuple([company_currency_rate])))
- return [
- {
- 'id': j[0],
- 'number': j[1],
- 'type': j[2],
- 'date': j[3],
- 'currency_id': j[4],
- 'amount': j[5],
- 'amount_currency': j[6],
- 'journal_id': j[7],
- 'reference': j[8],
- } for j in r.cr.fetchall()
- ]
|