# -*- coding: utf-8 -*- ############################################################################## # # OpenERP, Open Source Management Solution # Copyright (C) 2004-2010 Tiny SPRL (). # # 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 . # ############################################################################## from openerp import tools from openerp.osv import fields, osv from datetime import datetime class cabventa_report(osv.osv): _name = "cabventa.report" _description = "Ventas - Informe" _auto = False _rec_name = 'date' _columns = { 'sale_id': fields.many2one('sale.order', 'N° Venta', readonly=True), 'date': fields.datetime('Fecha', readonly=True), 'origin': fields.char('Referencia', readonly=True), 'partner_id': fields.many2one('res.partner', 'Cliente', readonly=True), 'amount_total': fields.float('Total Gs.', readonly=True), 'amount_totald': fields.float('Total $.', readonly=True), 'company_id': fields.many2one('res.company', 'Compañia', readonly=True), 'currency_id': fields.many2one('res.currency', 'Moneda',readonly=True), 'user_id': fields.many2one('res.users', 'Vendedor', readonly=True), 'state': fields.selection([ ('cancel', 'Cancelado'), ('draft', 'Borrador'), ('confirmed', 'Confirmado'), ('exception', 'Excepcion'), ('done', 'Realizado')], 'Estado', readonly=True), 'warehouse_id': fields.many2one('stock.warehouse', 'Sucursal'), 'section_id': fields.many2one('crm.case.section', 'Sales Team'), } _order = 'date desc' def init(self, cr): tools.drop_view_if_exists(cr, 'cabventa_report') cr.execute(""" create or replace view cabventa_report as ( SELECT row_number() over (ORDER BY so.id) as id, so.id as sale_id, so.date_order AS date, so.partner_id AS partner_id, so.origin AS origin, rc.id as currency_id, so.company_id, so.user_id, so.state, (case when so.amount_total>0 and rc.id=166 then so.amount_total else 0 end) as amount_total, (case when so.amount_total>0 and rc.id=3 then so.amount_total else 0 end) as amount_totald, so.warehouse_id as warehouse_id, so.section_id as section_id from sale_order so JOIN res_partner rp ON so.partner_id = rp.id LEFT JOIN product_pricelist pl ON pl.id = so.pricelist_id LEFT JOIN res_currency rc ON rc.id = pl.currency_id GROUP BY so.date_order ,so.id, so.origin, so.partner_id, so.warehouse_id,so.amount_total, so.user_id, so.company_id, so.state, rc.id, so.amount_total, so.section_id) """) # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: