123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- # -*- coding: utf-8 -*-
- from openerp.http import request as r
- def get_account_invoice_purchase():
- company_currency_rate = r.env.user.company_id.currency_id.rate
- origin = '%PO%'
- query = '''
- SELECT
- invoice.id,
- rate.currency_id,
- invoice.date_invoice,
- invoice.type,
- invoice.origin,
- invoice.partner_id,
- invoice.user_id,
- invoice.amount_total * (%s / (array_agg(rate.rate ORDER BY rate.id DESC))[1]),
- invoice.number,
- partner.name,
- customer.name,
- invoice.amount_tax * (%s / (array_agg(rate.rate ORDER BY rate.id DESC))[1]),
- invoice.state,
- journal.store_id,
- invoice.journal_id,
- invoice.state,
- invoice.company_id
- FROM account_invoice AS invoice
- LEFT JOIN res_store_journal_rel AS journal
- ON journal.journal_id = invoice.journal_id
- LEFT JOIN res_currency_rate AS rate
- ON rate.currency_id = invoice.currency_id
- LEFT JOIN res_company AS company
- ON company.id = invoice.company_id
- LEFT JOIN res_users AS users
- ON users.id = invoice.user_id
- LEFT JOIN res_partner AS partner
- ON partner.id = users.partner_id
- LEFT JOIN res_partner AS customer
- ON customer.id = invoice.partner_id
- WHERE invoice.state NOT IN ('draft', 'cancel')
- AND invoice.type IN ('in_invoice')
- AND invoice.origin LIKE %s
- GROUP BY
- invoice.id,
- rate.currency_id,
- invoice.date_invoice,
- invoice.type,
- invoice.origin,
- invoice.amount_total,
- invoice.partner_id,
- invoice.user_id,
- invoice.amount_total,
- partner.name,
- customer.name,
- invoice.amount_tax,
- invoice.state,
- journal.store_id,
- invoice.journal_id,
- invoice.state,
- invoice.company_id
- '''
- r.cr.execute(query,(tuple([company_currency_rate,company_currency_rate,origin])))
- return [
- {
- 'invoice_id': j[0],
- 'currency_id': j[1],
- 'date': j[2],
- 'type': j[3],
- 'origin': j[4],
- 'customer_id':j[5],
- 'user_id':j[6],
- 'amount':j[7],
- 'number':j[8],
- 'user_name':j[9],
- 'customer_name':j[10],
- 'amount_tax':j[11],
- 'state':j[12],
- 'store_id':j[13],
- 'journal_id':j[14],
- 'state':j[15],
- 'company_id':j[16]
- } for j in r.cr.fetchall()
- ]
|