123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- # -*- coding: utf-8 -*-
- ##############################################################################
- #
- # OpenERP, Open Source Management Solution
- # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
- #
- # This program is free software: you can redistribute it and/or modify
- # it under the terms of the GNU Affero General Public License as
- # published by the Free Software Foundation, either version 3 of the
- # License, or (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU Affero General Public License for more details.
- #
- # You should have received a copy of the GNU Affero General Public License
- # along with this program. If not, see <http://www.gnu.org/licenses/>. if(l.type='receipt','l.amount','0') AS amount_entrada,
- # r.employee_id as 'amount_salida': fields.float('Total Salida', readonly=True),
- # GROUP BY p.id ,l.partner_id,l.journal_id,l.create_date,l.amount_total,s.total
- ##############################################################################
- from openerp import tools
- from openerp.osv import fields, osv
- from openerp.tools.translate import _
- from openerp.tools import DEFAULT_SERVER_DATE_FORMAT, DEFAULT_SERVER_DATETIME_FORMAT
- class diarioacc_voucher(osv.osv):
- _name = "diarioacc.voucher"
- _description = "Analisis de Entrada y Salida sobre Diario de Cuentas"
- _auto = False
- _columns = {
- 'partner_id': fields.many2one('res.partner', 'Cliente / Proveedor', readonly=True),
- 'invoice_id': fields.many2one('account.invoice', 'N° Factura', readonly=True),
- 'reference': fields.char('Ref.', readonly=True),
- 'type': fields.char('Tipo', readonly=True),
- 'currency_id': fields.many2one('res.currency', 'Moneda', required=True,readonly=True),
- 'amount_entrada': fields.float('Total Entrada', readonly=True),
- 'amount_salida': fields.float('Total Salida', readonly=True),
- 'saldo': fields.float('Saldo', readonly=True),
- 'date_x': fields.date('Date Order', readonly=True),
- 'company_id': fields.many2one('res.company', 'Company', invisible=True, readonly=True)
- }
- _order = 'date_x desc'
- def init(self, cr):
- tools.sql.drop_view_if_exists(cr,'diarioacc_voucher')
- cr.execute("""
- CREATE OR REPLACE VIEW diarioacc_voucher AS (
- SELECT row_number() over (ORDER BY t.id)as id,
- t.id as invoice_id,
- r.name as xname,
- l.partner_id as partner_id,
- l.company_id as company_id,
- l.reference as reference,
- l.type as type,
- l.payment_rate_currency_id as currency_id,
- (case when l.type = 'receipt' and l.amount>0 then l.amount else 0 end) as amount_entrada,
- (case when l.type = 'payment' then l.amount else 0 end) as amount_salida,
- ((case when l.type = 'receipt' and l.amount>0 then l.amount else 0 end)-(case when l.type = 'payment' then l.amount else 0 end)) as saldo,
- l.date as date_x
- FROM account_move r
- left join account_invoice t on (r.ref=t.number)
- left join account_voucher l on (r.id=l.move_id)
- WHERE l.state='posted'
- GROUP BY r.name,t.id,l.partner_id,l.reference,l.type,l.amount,l.payment_rate_currency_id ,l.date, l.company_id
- )
- """)
- diarioacc_voucher()
|