# -*- 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 . # 'price_costo': fields.float('Price Costo', readonly=True), ############################################################################## from openerp import tools from openerp.osv import fields, osv class compraventa_analisis(osv.osv): _name = "compraventa.analisis" _description = "Analisis de Compra y Venta sobre Productos" _auto = False _columns = { 'id': fields.many2one('product.product', 'Id', readonly=True), 'name_template': fields.char('Descripcion', readonly=True), 'price_cost': fields.float('Precio compra', readonly=True), 'product_qty': fields.float('Qty compra', readonly=True), 'tpc': fields.float('Subtotal compra', readonly=True), 'price_unit': fields.float('Precio venta', readonly=True), 'product_uom_qty': fields.float('Qty venta', readonly=True), 'tpv': fields.float('Subtotal venta', readonly=True), 'tgan': fields.float('Ganancia/Perdida', readonly=True), } _order = 'id desc' def init(self, cr): tools.sql.drop_view_if_exists(cr, 'compraventa_analisis') cr.execute(""" CREATE OR REPLACE VIEW compraventa_analisis AS ( SELECT p.id as id, p.name_template as name_template, c.price_cost as price_cost, c.compras as product_qty, c.tpc as tpc, v.price_unit as price_unit,v.ventas as product_uom_qty, v.tpv as tpv, (v.tpv-c.tpc) as tgan FROM product_product p LEFT JOIN ( SELECT MIN(r.product_id) AS id, SUM(r.price_unit/r.product_qty) as price_cost, SUM(r.product_qty) compras, (SUM(r.price_unit/r.product_qty)*SUM(r.product_qty)) tpc FROM purchase_order_line r left join purchase_order f on (f.id=r.order_id) where f.state='done' GROUP BY r.product_id) c ON c.id=p.id LEFT JOIN ( SELECT MIN(l.product_id) AS id, SUM(l.price_unit/l.product_uom_qty) as price_unit, SUM(l.product_uom_qty) ventas, (SUM(l.price_unit/l.product_uom_qty)*SUM(l.product_uom_qty)) tpv FROM sale_order_line l left join sale_order s on (s.id=l.order_id) where l.state='done' GROUP BY l.product_id, l.price_unit) v ON v.id=p.id ) """) compraventa_analisis()