report_invoicegral.py 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # OpenERP, Open Source Management Solution
  5. # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU Affero General Public License as
  9. # published by the Free Software Foundation, either version 3 of the
  10. # License, or (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU Affero General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Affero General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. #
  20. ##############################################################################
  21. from openerp import tools
  22. from openerp.osv import fields, osv
  23. from datetime import datetime
  24. class invoice_reportgral(osv.osv):
  25. _name = "invoice.reportgral"
  26. _description = "Facturas - Analisis"
  27. _auto = False
  28. _rec_name = 'date'
  29. _columns = {
  30. 'date': fields.date('Fecha', readonly=True),
  31. 'partner_id':fields.many2one('res.partner', 'Proveedor', readonly=True),
  32. 'supplier_invoice_number':fields.char('N° Factura', readonly=True),
  33. 'product_id':fields.many2one('product.product', 'Product', readonly=True),
  34. 'name': fields.char('Descripcion', readonly=True),
  35. 'product_qty':fields.integer('Product Quantity', readonly=True),
  36. 'journal_id': fields.many2one('account.journal', 'Journal', readonly=True),
  37. 'company_id': fields.many2one('res.company', 'Company', readonly=True),
  38. 'user_id':fields.many2one('res.users', 'Salesperson', readonly=True),
  39. 'price_total': fields.float('Total Without Tax', readonly=True),
  40. 'currency_id': fields.many2one('res.currency', 'Moneda',readonly=True),
  41. 'state': fields.selection([
  42. ('draft','Draft'),
  43. ('proforma','Pro-forma'),
  44. ('proforma2','Pro-forma'),
  45. ('open','Open'),
  46. ('paid','Done'),
  47. ('cancel','Cancelled')
  48. ], 'Invoice Status', readonly=True),
  49. 'account_id': fields.many2one('account.account', 'Account',readonly=True),
  50. 'account_line_id': fields.many2one('account.account', 'Account Line',readonly=True),
  51. }
  52. _order = 'date desc'
  53. def init(self, cr):
  54. tools.drop_view_if_exists(cr, 'invoice_reportgral')
  55. cr.execute("""
  56. create or replace view invoice_reportgral as (
  57. select
  58. min(ail.id) AS id,
  59. ai.date_invoice AS date,
  60. ai.partner_id AS partner_id,
  61. ai.supplier_invoice_number AS supplier_invoice_number,
  62. ail.product_id AS product_id,
  63. ail.name AS name,
  64. sum(ail.quantity) as product_qty,
  65. ai.journal_id,
  66. ai.company_id,
  67. ai.user_id,
  68. ai.state,
  69. ai.currency_id,
  70. ai.account_id,
  71. ail.account_id AS account_line_id,
  72. sum(ail.quantity * ail.price_unit) as price_total
  73. from account_invoice_line ail
  74. JOIN account_invoice ai ON ai.id = ail.invoice_id
  75. JOIN res_partner partner ON ai.commercial_partner_id = partner.id
  76. LEFT JOIN product_product pr ON pr.id = ail.product_id
  77. left JOIN product_template pt ON pt.id = pr.product_tmpl_id
  78. LEFT JOIN product_uom u ON u.id = ail.uos_id
  79. where ai.type = 'in_invoice'
  80. GROUP BY ail.product_id, ai.date_invoice,
  81. ai.partner_id,ail.name,ai.currency_id,ai.supplier_invoice_number, ai.journal_id,
  82. ai.user_id, ai.company_id, ai.state, pt.categ_id,
  83. ai.account_id, ail.account_id)
  84. """)
  85. # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: