seguimiento_pago.py 4.5 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. class seguir_pago(osv.osv):
  24. """
  25. Quants are the smallest unit of stock physical instances
  26. """
  27. _name = "seguir.pago"
  28. _description = "Seguirpago"
  29. _auto = False
  30. _columns = {
  31. 'partner_id':fields.many2one('res.partner', 'Cliente', readonly=True),
  32. 'ref': fields.char('Referencia', readonly=True),
  33. 'date': fields.date('Fecha Factura', readonly=True),
  34. 'debit': fields.float('Total', readonly=True),
  35. 'debit_pyg': fields.float('Total', readonly=True),
  36. 'date_maturity': fields.date('Vence', readonly=True),
  37. 'currency_id':fields.many2one('res.currency', 'Moneda', readonly=True),
  38. 'company_id':fields.many2one('res.company', 'Company', readonly=True),
  39. 'rate': fields.float('Total', readonly=True),
  40. 'pagado_usd': fields.float('pagado_usd', readonly=True, default=0),
  41. 'saldo_usd': fields.float('saldo_usd', readonly=True, default=0),
  42. 'pagado_pyg': fields.float('pagado_pyg', readonly=True, default=0),
  43. 'saldo_pyg': fields.float('saldo_pyg', readonly=True, default=0),
  44. }
  45. _order = 'partner_id desc'
  46. def init(self, cr):
  47. tools.sql.drop_view_if_exists(cr, 'seguir_pago')
  48. cr.execute("""
  49. CREATE OR REPLACE VIEW seguir_pago as (
  50. SELECT s.id as id,
  51. s.partner_id as partner_id,
  52. s.ref as ref,
  53. s.date as date,
  54. s.debit as debit,
  55. (CASE WHEN rrc.amount_tot is null THEN 0 ELSE rrc.amount_tot END) as pagado_usd,
  56. (s.debit - CASE WHEN rrc.amount_tot is null THEN 0 ELSE rrc.amount_tot END ) as saldo_usd,
  57. x.rate as rate,
  58. (s.debit * x.rate) debit_pyg,
  59. (CASE WHEN rrc.amount_tot is null THEN 0 ELSE rrc.amount_tot END * x.rate) as pagado_pyg,
  60. ((s.debit * x.rate) - (CASE WHEN rrc.amount_tot is null THEN 0 ELSE rrc.amount_tot END * x.rate)) as saldo_pyg,
  61. s.date_maturity as date_maturity,
  62. t.currency_id as currency_id,
  63. p.id as company_id
  64. FROM account_move_line s
  65. left join account_invoice t on (t.move_id=s.move_id)
  66. left join res_currency d on (d.id=s.currency_id)
  67. left join res_partner r on (r.id=s.partner_id)
  68. left join res_company p on (p.id=s.company_id)
  69. left join res_currency_rate x on (x.id =(select max(id) from res_currency_rate where currency_id =d.id and currency_id=166))
  70. left join (
  71. Select sum(avl.amount / rc.rate) as amount_tot, move_line_id
  72. from account_voucher_line avl
  73. left join res_currency_rate rc on (rc.id = (SELECT max(rcr.id) FROM res_currency_rate rcr, account_voucher av ,account_journal aj
  74. where av.id = avl.voucher_id AND rcr.currency_id = CASE WHEN aj.currency is null THEN 3 ELSE aj.currency END AND av.journal_id = aj.id ))
  75. Group by move_line_id) as rrc on s.id = rrc.move_line_id
  76. where t.type='out_invoice' and t.state<>'paid' and s.date_maturity IS NOT NULL AND s.reconcile_id is null
  77. GROUP BY s.id,s.partner_id,s.ref,s.date,s.date_maturity,p.id,t.currency_id,s.debit,x.rate, rrc.amount_tot)
  78. """)
  79. # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: