123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516 |
- # -*- coding: utf-8 -*-
- from openerp.http import request as r
- def get_account_invoice_all_type():
- company_currency_rate = r.env.user.company_id.currency_id.rate
- 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]) as invoice_rate,
- invoice.number,
- partner.name,
- customer.name,
- invoice.amount_tax,
- invoice.state,
- journal.store_id,
- invoice.journal_id,
- invoice.state,
- customer.ruc,
- invoice.supplier_invoice_number
- 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')
- 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,
- customer.ruc,
- invoice.supplier_invoice_number
- '''
- r.cr.execute(query,(tuple([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],
- 'customer_ruc':j[16],
- 'supplier_invoice_number':j[17],
- } for j in r.cr.fetchall()
- ]
- def get_account_invoice_sale_type(): #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
- 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
- '''
- 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
- 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
- '''
- 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],
- } 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],
- } for j in r.cr.fetchall()]
- def get_account_invoice_sale_and_refund_type():
- company_currency_rate = r.env.user.company_id.currency_id.rate
- 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]) as invoice_rate,
- invoice.number,
- partner.name,
- customer.name,
- invoice.amount_tax,
- 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 ('out_invoice','out_refund')
- 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])))
- 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()
- ]
- def get_account_invoice_expense_type():
- 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]) as invoice_rate,
- invoice.number,
- partner.name,
- customer.ruc,
- customer.name,
- invoice.amount_tax,
- invoice.state,
- journal.store_id,
- invoice.journal_id,
- invoice.state,
- invoice.company_id,
- invoice.supplier_invoice_number
- 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 NOT LIKE %s OR invoice.origin IS NULL)
- 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.ruc,
- customer.name,
- invoice.amount_tax,
- invoice.state,
- journal.store_id,
- invoice.journal_id,
- invoice.state,
- invoice.company_id,
- invoice.supplier_invoice_number
- '''
- r.cr.execute(query,([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],
- 'supplier_ruc':j[10],
- 'supplier_name':j[11],
- 'amount_tax':j[12],
- 'state':j[13],
- 'store_id':j[14],
- 'journal_id':j[15],
- 'state':j[16],
- 'company_id':j[17],
- 'supplier_invoice_number':j[18],
- } for j in r.cr.fetchall()
- ]
- def get_account_invoice_purchase_type():
- 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]) as invoice_rate,
- invoice.number,
- partner.name,
- customer.ruc,
- customer.name,
- invoice.amount_tax,
- invoice.state,
- journal.store_id,
- invoice.journal_id,
- invoice.state,
- invoice.company_id,
- invoice.supplier_invoice_number
- 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 OR invoice.origin <> NULL)
- 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.ruc,
- customer.name,
- invoice.amount_tax,
- invoice.state,
- journal.store_id,
- invoice.journal_id,
- invoice.state,
- invoice.company_id,
- invoice.supplier_invoice_number
- '''
- r.cr.execute(query,([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],
- 'supplier_ruc':j[10],
- 'supplier_name':j[11],
- 'amount_tax':j[12],
- 'state':j[13],
- 'store_id':j[14],
- 'journal_id':j[15],
- 'state':j[16],
- 'company_id':j[17],
- 'supplier_invoice_number':j[18],
- } for j in r.cr.fetchall()
- ]
|