123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212 |
- # -*- coding: utf-8 -*-
- from openerp.http import request as r
- def get_account_invoice_sale_type_baco(): #historico de venta
- company_currency_rate = r.env.user.company_id.currency_id.rate
- validate_columns = '''
- SELECT EXISTS (SELECT 1 FROM information_schema.columns
- WHERE table_name='account_invoice' AND column_name in ('contado','credito'))'''
- query1 = '''
- 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,
- customer.ruc,
- invoice.supplier_invoice_number,
- customer.phone,
- customer.mobile,
- customer.email,
- invoice.is_delivery,
- invoice.delivery_type,
- customer.city
- 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 ('out_invoice')
- 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,
- customer.ruc,
- invoice.supplier_invoice_number,
- customer.phone,
- customer.mobile,
- customer.email,
- customer.city
- '''
- query2 = '''
- 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,
- customer.ruc,
- invoice.supplier_invoice_number,
- invoice.contado,
- invoice.credito,
- customer.phone,
- customer.mobile,
- customer.email,
- invoice.is_delivery,
- invoice.delivery_type,
- customer.city
- 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 ('out_invoice')
- 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,
- customer.ruc,
- invoice.supplier_invoice_number,
- customer.phone,
- customer.mobile,
- customer.email,
- customer.city
- '''
- r.cr.execute(validate_columns)
- for j in r.cr.fetchall():
- column = j[0]
- if column == True:
- r.cr.execute(query2,(tuple([company_currency_rate,company_currency_rate])))
- 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],
- 'customer_ruc':j[17],
- 'supplier_invoice_number':j[18],
- 'contado':j[19],
- 'credito':j[20],
- 'phone':j[21],
- 'mobile':j[22],
- 'email':j[23],
- 'is_delivery':j[24],
- 'delivery_type':j[25],
- 'city':j[26]
- } for j in r.cr.fetchall()]
- else:
- r.cr.execute(query1,(tuple([company_currency_rate,company_currency_rate])))
- 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],
- 'customer_ruc':j[17],
- 'supplier_invoice_number':j[18],
- 'phone':j[19],
- 'mobile':j[20],
- 'email':j[21],
- 'is_delivery':j[22],
- 'delivery_type':j[23],
- 'city':j[24]
- } for j in r.cr.fetchall()]
|