123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- # -*- 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/>.
- #
- ##############################################################################
- from openerp import tools
- from openerp.osv import fields, osv
- from datetime import datetime
- class facturaventa_report(osv.osv):
- _name = "facturaventa.report"
- _description = "Factura de Ventas - Informe"
- _auto = False
- _rec_name = 'date'
- _columns = {
- 'date': fields.date('Fecha', readonly=True),
- 'partner_id':fields.many2one('res.partner', 'Cliente', readonly=True),
- 'invoice_id' : fields.many2one('account.invoice','N° Factura', readonly=True),
- 'product_id':fields.many2one('product.product', 'Producto', readonly=True),
- 'name': fields.char('Descripcion', readonly=True),
- 'origin': fields.char('Referencia', readonly=True),
- 'product_qty':fields.integer('Cantidad', readonly=True),
- 'journal_id': fields.many2one('account.journal', 'Diario', readonly=True),
- 'currency_id':fields.many2one('res.currency', 'Moneda', readonly=True),
- 'company_id': fields.many2one('res.company', 'Compañia', readonly=True),
- 'user_id':fields.many2one('res.users', 'Vendedor', readonly=True),
- 'price_total': fields.float('Total s/ Impuesto', readonly=True),
- 'state': fields.selection([
- ('draft','Borrador'),
- ('proforma','Pro-forma'),
- ('proforma2','Pro-forma'),
- ('open','Abierto'),
- ('paid','Pagado'),
- ('cancel','Cancelado')
- ], 'Estado de Factura', readonly=True),
- 'account_id': fields.many2one('account.account', 'Account',readonly=True),
- 'account_line_id': fields.many2one('account.account', 'Account Line',readonly=True),
- }
- _order = 'date desc'
- def init(self, cr):
- tools.drop_view_if_exists(cr, 'facturaventa_report')
- cr.execute("""
- create or replace view facturaventa_report as (
- select
- min(ail.id) AS id,
- ai.date_invoice AS date,
- ai.partner_id AS partner_id,
- ai.id AS invoice_id,
- ail.product_id AS product_id,
- ai.origin AS origin,
- ail.name AS name,
- sum(ail.quantity) as product_qty,
- ai.journal_id,
- ai.company_id,
- ai.user_id,
- ai.state,
- ai.account_id,
- ai.currency_id,
- ail.account_id AS account_line_id,
- sum(ail.quantity * ail.price_unit) as price_total
- from account_invoice_line ail
- JOIN account_invoice ai ON ai.id = ail.invoice_id
- LEFT JOIN res_currency t ON t.id = ai.currency_id
- JOIN res_partner partner ON ai.commercial_partner_id = partner.id
- LEFT JOIN product_product pr ON pr.id = ail.product_id
- left JOIN product_template pt ON pt.id = pr.product_tmpl_id
- LEFT JOIN product_uom u ON u.id = ail.uos_id
- where ai.type = 'out_invoice'
- GROUP BY ail.product_id,ai.origin, ai.date_invoice,
- ai.partner_id,ail.name,ai.id, ai.journal_id,ai.currency_id,
- ai.user_id, ai.company_id, ai.state, pt.categ_id,
- ai.account_id, ail.account_id)
- """)
- # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|