report_posvariantgral.py 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 posgralvariant_report(osv.osv):
  24. _name = "posgralvariant.report"
  25. _description = "Listado General de Punto 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. 'att_id': fields.many2one('product.attribute.value', 'Atributo', readonly=True),
  34. 'fname': fields.char('nombre', readonly=True),
  35. 'product_brand_id': fields.many2one('product.brand', 'Marca', readonly=True),
  36. 'product_genre_id': fields.many2one('product.genre', 'Genero', readonly=True),
  37. 'product_categ_id': fields.many2one('product.category', 'Categoria', readonly=True),
  38. }
  39. _order = 'date desc'
  40. def init(self, cr):
  41. tools.drop_view_if_exists(cr, 'posgralvariant_report')
  42. cr.execute("""
  43. create or replace view posgralvariant_report as (
  44. SELECT row_number() over (ORDER BY p.id) as id,
  45. s.date_order as date,
  46. s.partner_id as partner_id,
  47. l.product_id as product_id,
  48. sum(l.qty) as product_qty,
  49. f.name as fname,
  50. zr.att_id as att_id,
  51. pt.product_brand_id as product_brand_id,
  52. pt.product_genre_id as product_genre_id,
  53. pt.categ_id as product_categ_id
  54. from pos_order_line l
  55. left join product_product p on (p.id=l.product_id)
  56. left join product_template pt on (pt.id=p.product_tmpl_id)
  57. left join product_brand r on (r.id=pt.product_brand_id)
  58. left join product_genre z on (z.id=pt.product_genre_id)
  59. left join pos_order s on (s.id=l.order_id)
  60. left join product_attribute_value_product_product_rel zr on (p.id=zr.prod_id)
  61. left join product_attribute_value f on (f.id=zr.att_id)
  62. where s.state= 'done'
  63. group by
  64. p.id,f.name,f.id,zr.att_id,s.partner_id,l.product_id,s.date_order,pt.product_brand_id,pt.categ_id,pt.product_genre_id)""")
  65. # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: