report_facturagolden.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 facturagolden_report(osv.osv):
  25. _name = "facturagolden.report"
  26. _description = "Factura de Ventas - Informe"
  27. _auto = False
  28. _rec_name = 'date'
  29. _columns = {
  30. 'date': fields.date('Fecha', readonly=True),
  31. 'partner_id':fields.many2one('res.partner', 'Cliente', readonly=True),
  32. 'invoice_id' : fields.many2one('account.invoice','N° Factura', readonly=True),
  33. 'product_id':fields.many2one('product.product', 'Producto', readonly=True),
  34. 'name': fields.char('Descripcion', readonly=True),
  35. 'origin': fields.char('Referencia', readonly=True),
  36. 'product_qty':fields.integer('Cantidad', readonly=True),
  37. 'journal_id': fields.many2one('account.journal', 'Diario', readonly=True),
  38. 'currency_id':fields.many2one('res.currency', 'Moneda', readonly=True),
  39. 'company_id': fields.many2one('res.company', 'Compañia', readonly=True),
  40. 'user_id':fields.many2one('res.users', 'Vendedor', readonly=True),
  41. 'price_total': fields.float('Total s/ Impuesto', readonly=True),
  42. 'state': fields.selection([
  43. ('draft','Borrador'),
  44. ('proforma','Pro-forma'),
  45. ('proforma2','Pro-forma'),
  46. ('open','Abierto'),
  47. ('paid','Pagado'),
  48. ('cancel','Cancelado')
  49. ], 'Estado de Factura', readonly=True),
  50. 'account_id': fields.many2one('account.account', 'Account',readonly=True),
  51. 'account_line_id': fields.many2one('account.account', 'Account Line',readonly=True),
  52. }
  53. _order = 'date desc'
  54. def init(self, cr):
  55. tools.drop_view_if_exists(cr, 'facturagolden_report')
  56. cr.execute("""
  57. create or replace view facturagolden_report as (
  58. select
  59. min(ail.id) AS id,
  60. ai.date_invoice AS date,
  61. ai.partner_id AS partner_id,
  62. ai.id AS invoice_id,
  63. ail.product_id AS product_id,
  64. ai.origin AS origin,
  65. ail.name AS name,
  66. sum(ail.quantity) as product_qty,
  67. ai.journal_id,
  68. ai.company_id,
  69. ai.user_id,
  70. ai.state,
  71. ai.account_id,
  72. ai.currency_id,
  73. ail.account_id AS account_line_id,
  74. sum(ail.quantity * ail.price_unit) as price_total
  75. from account_invoice_line ail
  76. JOIN account_invoice ai ON ai.id = ail.invoice_id
  77. LEFT JOIN res_currency t ON t.id = ai.currency_id
  78. JOIN res_partner partner ON ai.commercial_partner_id = partner.id
  79. LEFT JOIN product_product pr ON pr.id = ail.product_id
  80. left JOIN product_template pt ON pt.id = pr.product_tmpl_id
  81. LEFT JOIN product_uom u ON u.id = ail.uos_id
  82. where ai.type = 'out_invoice' and ai.state <> 'cancel' and ai.state <> 'draft'
  83. GROUP BY ail.product_id,ai.origin, ai.date_invoice,
  84. ai.partner_id,ail.name,ai.id, ai.journal_id,ai.currency_id,
  85. ai.user_id, ai.company_id, ai.state, pt.categ_id,
  86. ai.account_id, ail.account_id)
  87. """)
  88. # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: