report_cabventa.py 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 cabventa_report(osv.osv):
  25. _name = "cabventa.report"
  26. _description = "Ventas - Informe"
  27. _auto = False
  28. _rec_name = 'date'
  29. _columns = {
  30. 'sale_id': fields.many2one('sale.order', 'N° Venta', readonly=True),
  31. 'date': fields.datetime('Fecha', readonly=True),
  32. 'origin': fields.char('Referencia', readonly=True),
  33. 'partner_id': fields.many2one('res.partner', 'Cliente', readonly=True),
  34. 'amount_total': fields.float('Total Gs.', readonly=True),
  35. 'amount_totald': fields.float('Total $.', readonly=True),
  36. 'company_id': fields.many2one('res.company', 'Compañia', readonly=True),
  37. 'currency_id': fields.many2one('res.currency', 'Moneda',readonly=True),
  38. 'user_id': fields.many2one('res.users', 'Vendedor', readonly=True),
  39. 'state': fields.selection([
  40. ('cancel', 'Cancelado'),
  41. ('draft', 'Borrador'),
  42. ('confirmed', 'Confirmado'),
  43. ('exception', 'Excepcion'),
  44. ('done', 'Realizado')], 'Estado', readonly=True),
  45. 'warehouse_id': fields.many2one('stock.warehouse', 'Sucursal'),
  46. 'section_id': fields.many2one('crm.case.section', 'Sales Team'),
  47. }
  48. _order = 'date desc'
  49. def init(self, cr):
  50. tools.drop_view_if_exists(cr, 'cabventa_report')
  51. cr.execute("""
  52. create or replace view cabventa_report as (
  53. SELECT row_number() over (ORDER BY so.id) as id,
  54. so.id as sale_id,
  55. so.date_order AS date,
  56. so.partner_id AS partner_id,
  57. so.origin AS origin,
  58. rc.id as currency_id,
  59. so.company_id,
  60. so.user_id,
  61. so.state,
  62. (case when so.amount_total>0 and rc.id=166 then so.amount_total else 0 end) as amount_total,
  63. (case when so.amount_total>0 and rc.id=3 then so.amount_total else 0 end) as amount_totald,
  64. so.warehouse_id as warehouse_id,
  65. so.section_id as section_id
  66. from sale_order so
  67. JOIN res_partner rp ON so.partner_id = rp.id
  68. LEFT JOIN product_pricelist pl ON pl.id = so.pricelist_id
  69. LEFT JOIN res_currency rc ON rc.id = pl.currency_id
  70. GROUP BY so.date_order ,so.id, so.origin,
  71. so.partner_id, so.warehouse_id,so.amount_total,
  72. so.user_id, so.company_id, so.state, rc.id,
  73. so.amount_total, so.section_id)
  74. """)
  75. # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: