report_stockgral.py 4.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 report_stockgral1(osv.osv):
  24. """
  25. Quants are the smallest unit of stock physical instances
  26. """
  27. _name = "report.stockgral1"
  28. _description = "Stockgral"
  29. _auto = False
  30. _columns = {
  31. 'product_id': fields.many2one('product.product', 'Product', required=True, select=True, readonly=True),
  32. 'unit_price': fields.float('Precio Venta', readonly=True),
  33. 'quantity': fields.float('Cantidad', readonly=True),
  34. 'subtotal_venta': fields.float('Subtotal', readonly=True),
  35. 'location_id': fields.many2one('stock.location', 'Ubicacion', readonly=True),
  36. 'categ_id': fields.many2one('product.category', 'Categoria', readonly=True),
  37. 'brand_id': fields.many2one('product.brand', 'Marca', readonly=True),
  38. 'factory_reference': fields.char('Referencia', readonly=True),
  39. 'genre_id': fields.many2one('product.genre', 'Genero', readonly=True),
  40. 'parent_id': fields.many2one('product.category', 'Categoria Padre', readonly=True),
  41. 'id_parent' : fields.many2one('product.category', 'Categoria Padre', readonly=True),
  42. }
  43. _order = 'product_id desc'
  44. def init(self, cr):
  45. tools.sql.drop_view_if_exists(cr, 'report_stockgral1')
  46. cr.execute("""
  47. CREATE OR REPLACE VIEW report_stockgral1 as (
  48. SELECT s.id as id,
  49. s.product_id as product_id,
  50. pt.list_price as unit_price,
  51. SUM(s.qty) as quantity,
  52. SUM(s.qty) * SUM(pt.list_price) as subtotal_venta,
  53. pt.product_brand_id as brand_id,
  54. pt.product_genre_id as genre_id,
  55. pt.categ_id as categ_id,
  56. pt.factory_reference as factory_reference,
  57. r.id as location_id,
  58. g.parent_id as parent_id,
  59. pcc.id_parent as id_parent
  60. FROM stock_quant s
  61. left join stock_location r on (r.id=s.location_id)
  62. left join product_product p on (p.id=s.product_id)
  63. left join product_template pt on (pt.id=p.product_tmpl_id)
  64. left join product_brand z on (pt.product_brand_id=z.id)
  65. left join product_genre t on (pt.product_genre_id=t.id)
  66. left join product_category g on (g.id=pt.categ_id)
  67. left join product_uom u on (u.id=pt.uom_id)
  68. left join (SELECT pp.id, pp.parent_id,
  69. case when (select ppp.parent_id from product_category ppp where ppp.id= pp.parent_id and ppp.parent_id !=1) is NULL
  70. then pp.parent_id ELSE
  71. (select ppp.parent_id from product_category ppp where ppp.id= pp.parent_id and ppp.parent_id !=1) END as id_parent
  72. from product_category pp) as pcc on pcc.id = pt.categ_id
  73. WHERE r.usage='internal' and s.qty>0 and pt.active=True
  74. GROUP BY s.id,s.product_id,r.id,pt.product_brand_id,pt.factory_reference,pt.categ_id,pt.product_genre_id,pt.list_price, g.parent_id,pcc.id_parent)
  75. """)
  76. # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: