report_productlist.py 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 report_productlist(osv.osv):
  25. _name = "report.productlist"
  26. _description = "Lista de Precios"
  27. _auto = False
  28. _rec_name = 'product_id'
  29. _columns = {
  30. 'product_id': fields.many2one('product.product', 'Producto', readonly=True),
  31. 'name_template': fields.char('Descripción', readonly=True),
  32. 'list_price': fields.char('Lista de Precio', readonly=True),
  33. 'price_surcharge': fields.float('Precio', readonly=True),
  34. 'company_id': fields.many2one('res.company', 'Compañia', readonly=True),
  35. }
  36. _order = 'id desc'
  37. def init(self, cr):
  38. tools.drop_view_if_exists(cr, 'report_productlist')
  39. cr.execute("""
  40. create or replace view report_productlist as (
  41. SELECT row_number() over (ORDER BY pl.id) as id,
  42. po.id AS product_id,
  43. po.name_template AS name_template,
  44. pv.name as list_price,
  45. pl.price_surcharge as price_surcharge,
  46. pt.company_id
  47. from product_pricelist_item pl
  48. LEFT JOIN product_product po ON po.id = pl.product_tmpl_id
  49. LEFT JOIN product_template pt ON pt.id = po.product_tmpl_id
  50. LEFT JOIN product_pricelist_version pv ON pv.id = pl.price_version_id
  51. where pv.price_grid = True and pl.price_surcharge>0 and po.name_template <> ''
  52. GROUP BY pl.id,
  53. po.id,
  54. po.name_template,
  55. pv.name,
  56. pl.price_surcharge,
  57. pt.company_id)
  58. """)
  59. # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: