Browse Source

Modulo analisis_compraventa

sebas 8 years ago
commit
3ce97776aa

+ 29 - 0
__init__.py

@@ -0,0 +1,29 @@
+# -*- encoding: utf-8 -*-
+#################################################################################
+#                                                                               #
+#    product_brand for OpenERP                                                  #
+#    Copyright (C) 2009 NetAndCo (<http://www.netandco.net>).                   #
+#    Authors, Mathieu Lemercier, mathieu@netandco.net,                          #
+#             Franck Bret, franck@netandco.net                                  #
+#    Copyright (C) 2011 Akretion Benoît Guillot <benoit.guillot@akretion.com>   #
+#                                                                               #
+#    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/>.      #
+#                                                                               #
+#################################################################################
+###################################################################################
+# Product Brand is an Openobject module wich enable Brand management for products #
+###################################################################################
+from . import analisis_compraventa
+from . import report_compraventa
+import math

BIN
__init__.pyc


+ 49 - 0
__openerp__.py

@@ -0,0 +1,49 @@
+# -*- encoding: utf-8 -*-
+#################################################################################
+#                                                                               #
+#    product_features for OpenERP                                                  #
+#    Copyright (C) 2009 NetAndCo (<http://www.netandco.net>).                   #
+#    Authors, Mathieu Lemercier, mathieu@netandco.net,                          #
+#             Franck Bret, franck@netandco.net                                  #
+#    Copyright (C) 2011 Akretion Benoît Guillot <benoit.guillot@akretion.com>   #
+#                                                                               #
+#    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/>.      #
+#                                                                               #
+#################################################################################
+###################################################################################
+# Product features is an Openobject module wich enable features management for products #
+###################################################################################
+{
+    'name': 'Analisis de compra y venta sobre Productos',
+    'version': '0.1',
+    'category': 'Product',
+    'description': """
+Analisis de compra y venta sobre Productos
+========================================
+
+Genera varios Analisis de compra y venta sobre Productos
+- Cuenta con varios filtros y muestra los siguientes datos: fecha venta/compra,  descripcion, cantidad comprado, cantidad vendido
+
+
+    """,
+    'author': 'Eiru/Sebastian Penayo',
+    'website': '',
+	'depends': ['sale','purchase','sales_team', 'report'],
+    'data': [
+		'informe_analisiscompraventa_view.xml',
+        'informe_analisiscompraventa_fecha.xml',
+        'analisiscompraventa_filter_view.xml',
+    ],
+    'installable': True,
+}

+ 59 - 0
analisis_compraventa.py

@@ -0,0 +1,59 @@
+# -*- 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/>.
+#          '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()

BIN
analisis_compraventa.pyc


+ 79 - 0
analisiscompraventa_filter_view.xml

@@ -0,0 +1,79 @@
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+<data>
+
+
+
+    <!-- Custom reports (aka filters) -->
+
+  <!--   <record id="filter_analisis_productos_salespersons1" model="ir.filters">
+        <field name="name">Por Vendedores</field>
+        <field name="model_id">product.analisis</field>
+        <field name="user_id" eval="False"/>
+        <field name="context">{'group_by': ['date:month', 'user_id']}</field>
+    </record> -->
+    <!--<record id="filter_sale_report_salesteam1" model="ir.filters">
+        <field name="name">Por equipo de ventas</field>
+        <field name="model_id">sale.reportgral</field>
+        <field name="user_id" eval="False"/>
+        <field name="context">{'group_by': ['date:month', 'section_id']}</field>
+    </record> -->
+  <!--  <record id="filter_analisis_productos_product1" model="ir.filters">
+        <field name="name">Por Mes Producto</field>
+        <field name="model_id">product.analisis</field>
+        <field name="user_id" eval="False"/>
+        <field name="context">{'group_by': ['date:month', 'product_id']}</field>
+    </record>
+
+    <record id="filter_analisis_productos_mescategmarca" model="ir.filters">
+          <field name="name">Por Mes/Categoria/Marca</field>
+          <field name="model_id">product.analisis</field>
+          <field name="user_id" eval="False"/>
+          <field name="context">{'group_by': ['date:month','product_categ_id','product_brand_id']}</field>
+    </record>
+
+    <record id="filter_analisis_productos_salesteam1" model="ir.filters">
+        <field name="name">Por Categoria</field>
+        <field name="model_id">product.analisis</field>
+        <field name="user_id" eval="False"/>
+        <field name="context">{'group_by': ['product_categ_id']}</field>
+    </record>
+	<record id="filter_analisis_productos_brand1" model="ir.filters">
+        <field name="name">Por Marca</field>
+        <field name="model_id">product.analisis</field>
+        <field name="user_id" eval="False"/>
+        <field name="context">{'group_by': ['product_brand_id']}</field>
+    </record>
+	<record id="filter_analisis_productos_brand2" model="ir.filters">
+        <field name="name">Por Mes/Marca</field>
+        <field name="model_id">product.analisis</field>
+        <field name="user_id" eval="False"/>
+        <field name="context">{'group_by': ['date:month','product_brand_id']}</field>
+    </record>
+
+    <record id="filter_analisis_productos_mescategcli" model="ir.filters">
+          <field name="name">Por Mes/Categoria/Cliente</field>
+          <field name="model_id">product.analisis</field>
+          <field name="user_id" eval="False"/>
+          <field name="context">{'group_by': ['date:month','product_categ_id']}</field>
+    </record>
+
+	<record id="filter_analisis_compra_venta" model="ir.filters">
+        <field name="name">Por Producto</field>
+        <field name="model_id">compraventa.analisis</field>
+        <field name="user_id" eval="False"/>
+        <field name="context">{'group_by': ['id']}</field>
+    </record> -->
+
+    <!-- <record id="view_order_compra_venta" model="ir.ui.view">
+        <field name="name">compra.venta.search</field>
+        <field name="model">compraventa.analisis</field>
+        <field name="arch" type="xml">
+            <search string="Analisis de Compra/Ventas ">
+                <field name="Producto" domain="[('Descripcion','=',self)]"/>
+            </search>
+        </field>
+    </record> -->
+
+</data>
+</openerp>

+ 93 - 0
informe_analisiscompraventa_fecha.xml

@@ -0,0 +1,93 @@
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+	<data>
+		<report id="report_diariocta3"
+            model="compraventa.analisis"
+            string="Listado de utilidad s/ compra/venta por producto"
+            report_type="qweb-pdf"
+            name="analisis_compraventa.informe_compraventaanalisis_fecha"
+            file="analisis_compraventa.informe_compraventaanalisis_fecha"
+    />
+
+	  <template id="informe_compraventaanalisis_fecha">
+		<t t-call="report.html_container">
+			<t t-call="report.internal_layout">
+				<div class="page">
+					<h2 class="text-center text-info">Listado de utilidad s/ compra/venta por producto</h2>
+					<br/>
+					<div class="row">
+						<div class="col-xs-12 col-sm-7 col-md-7">
+							<div class="panel panel-success">
+								<table class="table table-condensed">
+									<thead>
+										<th class="text-left">Producto</th>
+										<th class="text-right">P.Costo</th>
+										<th class="text-right">Cant.</th>
+										<th class="text-right">T.Costo</th>
+										<th class="text-right">P.Venta</th>
+										<th class="text-right">Cant.</th>
+										<th class="text-right">T.Venta</th>
+										<th class="text-right">Gan/Per</th>
+									</thead>
+									<tbody>
+										<t t-foreach="docs" t-as="o">
+												     <tr>
+													      <td class="text-left"><span t-esc="o.name_template"/></td>
+													      <td class="text-right"><span t-esc="'{0:,.0f}'.format(round(float(o.price_cost), 0))"/></td>
+													      <td class="text-right"><span t-esc="'{0:,.0f}'.format(round(float(o.product_qty), 0))"/></td>
+													      <td class="text-right"><span t-esc="'{0:,.0f}'.format(round(float(o.tpc), 0))"/></td>
+																<td class="text-right"><span t-esc="'{0:,.0f}'.format(round(float(o.price_unit), 0))"/></td>
+													      <td class="text-right"><span t-esc="'{0:,.0f}'.format(round(float(o.product_uom_qty), 0))"/></td>
+													      <td class="text-right"><span t-esc="'{0:,.0f}'.format(round(float(o.tpv), 0))"/></td>
+																<td class="text-right"><span t-esc="'{0:,.0f}'.format(round(float(o.tgan), 0))"/></td>
+												      </tr>
+										 </t>
+									 </tbody>
+
+									 <td class="panel-footer">
+										 <strong>Totales:</strong>
+									</td>
+									<td class="panel-footer">
+										 <strong><t t-set="tqty" t-value="sum([x.product_qty for x in docs])"/>
+										 <td class="text-right"><span t-esc="'{0:,.0f}'.format(round(float(tqty), 0))"/></td>
+										 </strong>
+									 </td>
+										 <strong><t t-set="tsaldo1" t-value="sum([x.tpc for x in docs])"/>
+										 <td class="text-right"><span t-esc="'{0:,.0f}'.format(round(float(tsaldo1), 0))"/></td>
+										 </strong>
+									 <td class="panel-footer">
+										 <strong><t t-set="tqty1" t-value="sum([x.product_uom_qty for x in docs])"/>
+										 <td class="text-right"><span t-esc="'{0:,.0f}'.format(round(float(tqty1), 0))"/></td>
+										 </strong>
+									 </td>
+									 <td class="panel-footer text-right">
+										 <strong><t t-set="tsaldo2" t-value="sum([x.tpv for x in docs])"/>
+										 <span t-esc="'{0:,.0f}'.format(round(float(tsaldo2), 0))"/>
+										 </strong>
+									 </td>
+									 <td class="panel-footer text-right">
+										 <strong><t t-set="tgan" t-value="sum([x.tgan for x in docs])"/>
+										 <span t-esc="'{0:,.0f}'.format(round(float(tgan), 0))"/>
+										 </strong>
+									 </td>
+
+
+								 </table>
+
+							 </div>
+						  </div>
+
+
+
+
+
+
+
+					</div>
+
+				</div>
+			</t>
+		</t>
+	  </template>
+ </data>
+</openerp>

+ 35 - 0
informe_analisiscompraventa_view.xml

@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+    <data>
+        <record id="compraventa_analisis_tree_view" model="ir.ui.view">
+            <field name="name">compraventa.analisis.tree.view</field>
+            <field name="model">compraventa.analisis</field>
+            <field name="priority" eval="20"/>
+            <field name="arch" type="xml">
+            <tree string="Analisis de Compras y Ventas" create="false">
+               <field name="name_template"/>
+               <field name="price_cost" string="Precio Costo"/>
+               <field name="product_qty" sum="Qty compra" string="Cant. Compra"/>
+               <field name="tpc" sum="Total Compra" string="T. Compra"/>
+               <field name="price_unit"  string="Precio Venta"/>
+               <field name="product_uom_qty" sum="Qty venta" string="Cant. Venta"/>
+               <field name="tpv" sum="Total Venta" string="T. Venta"/>
+               <field name="tgan" sum="Ganancia/Perdida" string="Ganancia/Perdida"/>
+				    </tree>
+            </field>
+        </record>
+
+		<record id="action_compraventa_analisis_tree_view" model="ir.actions.act_window">
+            <field name="name">Analisis de Compras y Ventas</field>
+            <field name="res_model">compraventa.analisis</field>
+            <field name="view_type">form</field>
+            <field name="view_mode">tree</field>
+        </record>
+
+
+
+		<menuitem name="Analisis de Compras y Ventas" sequence="47" id="menu_analisiscompraventa_gral" parent="base.menu_reporting"/>
+		<menuitem id="compraventa_analisis_menu" name="Analisis de Compras y Ventas" parent="menu_analisiscompraventa_gral" action="action_compraventa_analisis_tree_view"/>
+
+	</data>
+</openerp>

+ 55 - 0
report_compraventa.py

@@ -0,0 +1,55 @@
+#    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 datetime import datetime, timedelta
+import time
+from openerp.osv import fields, osv
+from openerp.tools.translate import _
+from openerp.tools import DEFAULT_SERVER_DATE_FORMAT, DEFAULT_SERVER_DATETIME_FORMAT
+import openerp.addons.decimal_precision as dp
+from openerp import workflow
+
+# class product_product(osv.Model):
+    # _inherit = 'product.product'
+
+    # def _sales_count(self, cr, uid, ids, field_name, arg, context=None):
+        # SaleOrderLine = self.pool['sale.order.line']
+        # return {
+            # product_id: SaleOrderLine.search_count(cr,uid, [('product_id', '=', product_id)], context=context)
+            # for product_id in ids
+        # }
+
+    # _columns = {
+        # 'sales_count': fields.function(_sales_count, string='# Sales', type='integer'),
+
+    # }
+
+# class product_template(osv.Model):
+    # _inherit = 'product.template'
+
+    # def _sales_count(self, cr, uid, ids, field_name, arg, context=None):
+        # res = dict.fromkeys(ids, 0)
+        # for template in self.browse(cr, uid, ids, context=context):
+            # res[template.id] = sum([p.sales_count for p in template.product_variant_ids])
+        # return res
+    
+    # def action_view_sales(self, cr, uid, ids, context=None):
+        # act_obj = self.pool.get('ir.actions.act_window')
+        # mod_obj = self.pool.get('ir.model.data')
+        # product_ids = []
+        # for template in self.browse(cr, uid, ids, context=context):
+            # product_ids += [x.id for x in template.product_variant_ids]
+        # result = mod_obj.xmlid_to_res_id(cr, uid, 'sale.action_order_line_product_tree',raise_if_not_found=True)
+        # result = act_obj.read(cr, uid, [result], context=context)[0]
+        # result['domain'] = "[('product_id','in',[" + ','.join(map(str, product_ids)) + "])]"
+        # return result
+    
+    
+    # _columns = {
+        # 'sales_count': fields.function(_sales_count, string='# Sales', type='integer'),
+
+    # }
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

BIN
report_compraventa.pyc


BIN
static/description/icon.png