report_salesinvariantgral.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. class salegralsinvariant_report(osv.osv):
  24. _name = "salegralsinvariant.report"
  25. _description = "Listado General de Ventas por variantes"
  26. _auto = False
  27. _rec_name = 'date'
  28. _columns = {
  29. 'date': fields.datetime('Date Order', readonly=True),
  30. 'partner_id':fields.many2one('res.partner', 'Cliente', readonly=True),
  31. 'product_id':fields.many2one('product.product', 'Producto', readonly=True),
  32. 'product_qty':fields.integer('Product Quantity', readonly=True),
  33. 'product_categ_id': fields.many2one('product.category', 'Categoria', readonly=True),
  34. }
  35. _order = 'date desc'
  36. def init(self, cr):
  37. tools.drop_view_if_exists(cr, 'salegralsinvariant_report')
  38. cr.execute("""
  39. create or replace view salegralsinvariant_report as (
  40. SELECT
  41. min(p.id) as id,
  42. s.date_order as date,
  43. s.partner_id as partner_id,
  44. l.product_id as product_id,
  45. sum(l.product_uom_qty) as product_qty,
  46. pt.categ_id as product_categ_id
  47. from sale_order_line l
  48. left join product_product p on (p.id=l.product_id)
  49. left join product_template pt on (pt.id=p.product_tmpl_id)
  50. left join sale_order s on (s.id=l.order_id)
  51. where s.state='done'
  52. group by
  53. s.partner_id,l.product_id,s.date_order,pt.categ_id)""")
  54. # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: