analisis_accountvoucher.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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/>. if(l.type='receipt','l.amount','0') AS amount_entrada,
  19. # r.employee_id as 'amount_salida': fields.float('Total Salida', readonly=True),
  20. # GROUP BY p.id ,l.partner_id,l.journal_id,l.create_date,l.amount_total,s.total
  21. ##############################################################################
  22. from openerp import tools
  23. from openerp.osv import fields, osv
  24. from openerp.tools.translate import _
  25. from openerp.tools import DEFAULT_SERVER_DATE_FORMAT, DEFAULT_SERVER_DATETIME_FORMAT
  26. class diarioacc_voucher(osv.osv):
  27. _name = "diarioacc.voucher"
  28. _description = "Analisis de Entrada y Salida sobre Diario de Cuentas"
  29. _auto = False
  30. _columns = {
  31. 'invoice_id': fields.char('N°Ref Cobro', readonly=True),
  32. 'partner_id': fields.many2one('res.partner', 'Partner', readonly=True),
  33. 'reference': fields.char('Ref #', readonly=True),
  34. 'type': fields.char('Tipo', readonly=True),
  35. 'currency_id': fields.many2one('res.currency', 'Moneda', required=True,readonly=True),
  36. 'amount_entrada': fields.float('Total Entrada', readonly=True),
  37. 'amount_salida': fields.float('Total Salida', readonly=True),
  38. 'saldo': fields.float('Saldo', readonly=True),
  39. 'date_x': fields.date('Date Order', readonly=True),
  40. }
  41. _order = 'date_x desc'
  42. def init(self, cr):
  43. tools.sql.drop_view_if_exists(cr,'diarioacc_voucher')
  44. cr.execute("""
  45. CREATE OR REPLACE VIEW diarioacc_voucher AS (
  46. SELECT row_number() over (ORDER BY l.id) as id,
  47. r.name as invoice_id,
  48. l.partner_id as partner_id,
  49. l.reference as reference,
  50. l.type as type,
  51. l.payment_rate_currency_id as currency_id,
  52. (case when l.type = 'receipt' and l.amount>0 then l.amount else 0 end) as amount_entrada,
  53. (case when l.type = 'payment' then l.amount else 0 end) as amount_salida,
  54. ((case when l.type = 'payment' then l.amount else 0 end)-(case when l.type = 'receipt' and l.amount>0 then l.amount else 0 end)) as saldo,
  55. l.date as date_x
  56. FROM account_move r
  57. left join account_voucher l on (r.id=l.move_id)
  58. left join account_voucher_line p on (p.voucher_id=l.id)
  59. WHERE l.state='posted'
  60. GROUP BY l.id,r.name,l.partner_id,l.reference,l.type,l.payment_rate_currency_id ,l.date
  61. )
  62. """)
  63. diarioacc_voucher()