Sfoglia il codice sorgente

Ranking de productos de ventas

sebas 3 anni fa
commit
d8f4afaeea

+ 24 - 0
__init__.py

@@ -0,0 +1,24 @@
+# -*- coding: utf-8 -*-
+#################################################################################
+#
+#    Odoo, Open Source Management Solution
+#    Copyright (C) 2018-Today Ascetic Business Solution <www.asceticbs.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/>.
+#
+#################################################################################
+
+
+from . import report
+import product_detail

BIN
__init__.pyc


+ 38 - 0
__openerp__.py

@@ -0,0 +1,38 @@
+# -*- coding: utf-8 -*-
+#################################################################################
+#
+#    Odoo, Open Source Management Solution
+#    Copyright (C) 2018-Today Ascetic Business Solution <www.asceticbs.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/>.
+#
+#################################################################################
+
+{
+    'name': 'Top Sold Products',
+    'author': 'Ascetic Business Solution',
+    'category': 'sale',
+    'summary': """Reports of Top Sold Products""",
+    'license': 'AGPL-3',
+    'website': 'http://www.asceticbs.com',
+    'description': """
+""",
+    'version': '1.0',
+    'depends': ['base','product','sale'],
+    'data': ['top_sales_view.xml','views/top_sold_view.xml','report/selected_product_report.xml','report/selected_product_template.xml','report/selected_product_amount_report.xml','report/selected_product_amount_template.xml'],
+    'images': ['static/description/banner.png'],
+    'installable': True,
+    'application': True,
+    'auto_install': False,
+}

+ 48 - 0
product_detail.py

@@ -0,0 +1,48 @@
+# -*- coding: utf-8 -*-
+#################################################################################
+#
+#    Odoo, Open Source Management Solution
+#    Copyright (C) 2018-Today Ascetic Business Solution <www.asceticbs.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/>.
+#
+#################################################################################
+
+from openerp import api, fields, models, _
+
+class ProductDetail(models.TransientModel):
+    _name = "product.detail"
+
+
+    start_date = fields.Date(string="Desde la fecha", required='1')
+    end_date = fields.Date(string="Hasta la fecha", required='1')
+    top_products = fields.Selection([
+        ('by_units', 'Units'),
+        ('by_amounts', 'Sales')
+    ], string='Segun', default = 'by_units')
+    no_of_products = fields.Integer(string='Numero de productos a mostrar', default = '20')
+
+    @api.multi
+    def check_report(self):
+        data = {}
+        data['form'] = self.read(['start_date', 'end_date', 'top_products', 'no_of_products'])[0]
+        return self._print_report(data)
+
+
+    def _print_report(self, data):
+        data['form'].update(self.read(['start_date', 'end_date', 'top_products', 'no_of_products'])[0])
+        if data['form']['top_products'] == 'by_units':
+            return self.env['report'].get_action(self, 'abs_top_sold_products.report_products', data=data)
+        else:
+            return self.env['report'].get_action(self, 'abs_top_sold_products.report_products_amount', data=data)

BIN
product_detail.pyc


+ 23 - 0
report/__init__.py

@@ -0,0 +1,23 @@
+# -*- coding: utf-8 -*-
+#################################################################################
+#
+#    Odoo, Open Source Management Solution
+#    Copyright (C) 2018-Today Ascetic Business Solution <www.asceticbs.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/>.
+#
+#################################################################################
+
+import report_product
+import report_product_amount

BIN
report/__init__.pyc


+ 57 - 0
report/report_product.py

@@ -0,0 +1,57 @@
+# -*- coding: utf-8 -*-
+#################################################################################
+#
+#    Odoo, Open Source Management Solution
+#    Copyright (C) 2018-Today Ascetic Business Solution <www.asceticbs.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/>.
+#
+#################################################################################
+
+import time
+from openerp import api, models
+from dateutil.parser import parse
+# from openerp.exceptions import UserError
+
+
+
+class ReportProducts(models.AbstractModel):
+    _name = 'report.abs_top_sold_products.report_products'
+
+    @api.model
+    def render_html(self, docids, data=None):
+        self.model = self.env.context.get('active_model')
+        docs = self.env[self.model].browse(self.env.context.get('active_id'))
+        product_records = {}
+        sorted_product_records = []
+        sales = self.env['sale.order'].search([('state','in',('sale','done')),('date_order','>=',docs.start_date),('date_order','<=',docs.end_date)])
+        for s in sales:
+            orders = self.env['sale.order.line'].search([('order_id','=',s.id)])
+            for order in orders:
+                if order.product_id:
+                    if order.product_id not in product_records:
+                        product_records.update({order.product_id:0})
+                    product_records[order.product_id] += order.product_uom_qty
+
+        for product_id, product_uom_qty in sorted(product_records.iteritems(), key=lambda (k,v): (v,k), reverse=True)[:docs.no_of_products]:
+            sorted_product_records.append({'name':product_id.name, 'qty': int(product_uom_qty)})
+
+        docargs = {
+            'doc_ids': self.ids,
+            'doc_model': self.model,
+            'docs': docs,
+            'time': time,
+            'products': sorted_product_records
+        }
+        return self.env['report'].render('abs_top_sold_products.report_products', docargs)

BIN
report/report_product.pyc


+ 57 - 0
report/report_product_amount.py

@@ -0,0 +1,57 @@
+# -*- coding: utf-8 -*-
+#################################################################################
+#
+#    Odoo, Open Source Management Solution
+#    Copyright (C) 2018-Today Ascetic Business Solution <www.asceticbs.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/>.
+#
+#################################################################################
+
+import time
+from openerp import api, models
+from dateutil.parser import parse
+# from  openerp.exceptions import UserError
+
+
+
+class ReportProductsAmount(models.AbstractModel):
+    _name = 'report.abs_top_sold_products.report_products_amount'
+
+    @api.model
+    def render_html(self, docids, data=None):
+        self.model = self.env.context.get('active_model')
+        docs = self.env[self.model].browse(self.env.context.get('active_id'))
+        product_records = {}
+        sorted_product_records = []
+        sales = self.env['sale.order'].search([('state','in',('sale','done')),('date_order','>=',docs.start_date),('date_order','<=',docs.end_date)])
+        for s in sales:
+            orders = self.env['sale.order.line'].search([('order_id','=',s.id)])
+            for order in orders:
+                if order.product_id:
+                    if order.product_id not in product_records:
+                        product_records.update({order.product_id:0})
+                    product_records[order.product_id] += order.price_subtotal
+
+        for product_id, price_subtotal in sorted(product_records.iteritems(), key=lambda (k,v): (v,k), reverse=True)[:docs.no_of_products]:
+            sorted_product_records.append({'name':product_id.name, 'amount': int(price_subtotal), 'pricelist_id' : product_id.company_id.currency_id })
+
+        docargs = {
+            'doc_ids': self.ids,
+            'doc_model': self.model,
+            'docs': docs,
+            'time': time,
+            'products': sorted_product_records
+        }
+        return self.env['report'].render('abs_top_sold_products.report_products_amount', docargs)

BIN
report/report_product_amount.pyc


+ 15 - 0
report/selected_product_amount_report.xml

@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+    <data>
+
+        <report
+            id="action_report_products_amount"
+            string="Top de Productos Vendidos PDF "
+            model="report.abs_top_sold_products.report_products_amount"
+            report_type="qweb-pdf"
+            file="abs_top_sold_products.report_products_amount"
+            name="abs_top_sold_products.report_products_amount"
+        />
+
+    </data>
+</openerp>

+ 47 - 0
report/selected_product_amount_template.xml

@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+<data>
+<template id="report_products_amount">
+    <t t-call="report.html_container">
+        <t t-foreach="docs" t-as="o">
+            <t t-call="report.internal_layout">
+                <div class="page">
+                    <div style="text-align: center;">
+                    	<span style="font-size: 25px;">Productos más vendidos según el importe de las ventas</span>
+                    </div>
+
+                    <div class="row mt32 mb32">
+                        <div class="col-xs-4">
+                            <p>
+                                <t t-if="docs.start_date"><strong>Desde la fecha :</strong> <span t-esc="docs.start_date"/><br/></t>
+                                <t t-if="docs.end_date"><strong>Hasta la fecha :</strong> <span t-esc="docs.end_date"/></t>
+                            </p>
+                        </div>
+                    </div>
+
+                    <table class="table table-condensed">
+                        <thead>
+                            <tr>
+                                <th>Productos</th>
+                                <th class="text-right">Ventas totales</th>
+                            </tr>
+                        </thead>
+                        <tbody>
+                            <tr t-foreach="products" t-as="a">
+                                <td>
+                                    <span t-esc="a['name']" />
+                                </td>
+                                <td class="text-right" style="white-space: text-nowrap;">
+                                    <span t-esc="a['amount']" t-options="{'widget': 'monetary', 'display_currency': a['pricelist_id']}"/>
+                                </td>
+
+                            </tr>
+                        </tbody>
+                    </table>
+                </div>
+            </t>
+        </t>
+    </t>
+</template>
+  </data>
+</openerp>

+ 15 - 0
report/selected_product_report.xml

@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+    <data>
+
+        <report
+            id="action_report_products"
+            string="Reporte de ranking de productos PDF"
+            model="report.abs_top_sold_products.report_products"
+            report_type="qweb-pdf"
+            file="abs_top_sold_products.report_products"
+            name="abs_top_sold_products.report_products"
+        />
+
+    </data>
+</openerp>

+ 46 - 0
report/selected_product_template.xml

@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+  <data>
+    <template id="report_products">
+        <t t-call="report.html_container">
+            <t t-foreach="docs" t-as="o">
+                <t t-call="report.internal_layout">
+                    <div class="page">
+                        <div style="text-align: center;">
+                        	<span style="font-size: 25px;">Productos más vendidos según las cantidades</span>
+                        </div>
+
+                        <div class="row mt32 mb32">
+                            <div class="col-xs-4">
+                                <p>
+                                    <t t-if="docs.start_date"><strong>Desde la fecha :</strong> <span t-esc="docs.start_date"/><br/></t>
+                                    <t t-if="docs.end_date"><strong>Hasta la fecha :</strong> <span t-esc="docs.end_date"/></t>
+                                </p>
+                            </div>
+                        </div>
+
+                        <table class="table table-condensed">
+                            <thead>
+                                <tr>
+                                    <th>Productos</th>
+                                    <th class="text-right">Total Cantidad</th>
+                                </tr>
+                            </thead>
+                            <tbody>
+                                <tr t-foreach="products" t-as="a">
+                                    <td>
+                                        <span t-esc="a['name']" />
+                                    </td>
+                                    <td class="text-right" style="white-space: text-nowrap;">
+                                        <span t-esc="a['qty']" />
+                                    </td>
+                                </tr>
+                            </tbody>
+                        </table>
+                    </div>
+                </t>
+            </t>
+        </t>
+      </template>
+    </data>
+</openerp>

BIN
static/description/banner.png


BIN
static/description/company-logo.png


BIN
static/description/icon.png


+ 59 - 0
static/description/index.html

@@ -0,0 +1,59 @@
+<html>
+<body>
+<section class="oe_container oe_dark">
+    <div class="oe_row">
+        <div class="oe_row">
+            <h2 class="oe_slogan oe_span10">Top Selling Products by Quantity and Sales Amount</h2>
+        </div>
+        <div class="oe_slogan" style="margin-top:10px !important;">
+         <a
+            class="btn btn-primary btn-lg mt8" style="color: #FFFFFF !important;"
+            href="https://youtu.be/Uh9lCCeyaMY"><i
+            class="fa fa-check-square" target="_blank"></i> Live Preview </a>
+        </div>
+    </div>
+</section>
+
+<section class="oe_container">
+
+    <h2 class="oe_slogan" style="margin-top:20px;">Need help?</h2>
+
+    <div style="margin: 16px 8%;">
+            <p class='oe_mt32 center-block' style="font-size: 15px;">
+                 Contact this module maintainer for any question, need support or request for the new feature : <br/>
+                 * Riken Bhorania  <i class="fa fa-whatsapp"></i> +91 9427425799,  <i class="fa fa-skype fa_custom"></i> <a href="skype:riken.bhorania?chat">riken.bhorania, </a> <i class="fa fa-envelope"></i> riken.bhorania@asceticbs.com <br/>
+                 * Bhaumin Chorera  <i class="fa fa-whatsapp"></i> +91 8530000384, <i class="fa fa-skype fa_custom"></i> <a href="skype:bhaumin.chorera?chat">bhaumin.chorera, </a> <i class="fa fa-envelope"></i> bhaumin.chorera@asceticbs.com <br/>
+            </p>
+    </div>
+
+    <div class="oe_slogan" style="margin-top:10px !important;"> 
+         <a class="btn btn-primary btn-lg mt8"
+            style="color: #FFFFFF !important;" href="http://www.asceticbs.com"><i
+            class="fa fa-envelope"></i> Website </a> 
+         <a class="btn btn-primary btn-lg mt8" style="color: #FFFFFF !important;"
+            href="http://www.asceticbs.com/contact-us"><i
+            class="fa fa-phone"></i> Contact Us </a> 
+         <a class="btn btn-primary btn-lg mt8" style="color: #FFFFFF !important;"
+            href="http://www.asceticbs.com/services"><i
+            class="fa fa-check-square"></i> Services </a> 
+         <a class="btn btn-primary btn-lg mt8" style="color: #FFFFFF !important;"
+            href="https://apps.odoo.com/apps/modules/browse?author=Ascetic%20Business%20Solution"><i
+            class="fa fa-binoculars"></i> More Apps </a>
+     </div>
+
+    <div class="oe_slogan" style="margin-top:10px !important;"> 
+      <img src="company-logo.png" style="width: 190px; margin-bottom: 20px;" class="center-block">
+    </div>
+
+    <div class="oe_slogan" style="margin-top:10px !important;">
+          <a href="https://twitter.com/asceticbs" target="_blank"><i class="fa fa-2x fa-twitter" style="color:white;background: #00a0d1;width:35px;"></i></a></td>
+          <a href="https://www.linkedin.com/company/ascetic-business-solution-llp" target="_blank"><i class="fa fa-2x fa-linkedin" style="color:white;background: #31a3d6;width:35px;padding-left: 3px;"></i></a></td>
+          <a href="https://www.facebook.com/asceticbs" target="_blank"><i class="fa fa-2x fa-facebook" style="color:white;background: #3b5998;width:35px;padding-left: 8px;"></i></a></td>
+          <a href="https://www.youtube.com/channel/UCsozahEAndQ2whjcuDIBNZQ" target="_blank"><i class="fa fa-2x fa-youtube-play" style="color:white;background: #c53c2c;width:35px;padding-left: 3px;"></i></a></td>
+     </div>
+
+    </div>
+</section>
+
+</body>
+</html>

+ 42 - 0
top_sales_view.xml

@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+    <data>
+
+        <record id="view_top_sales_form" model="ir.ui.view">
+            <field name="name">product.detail.form</field>
+            <field name="model">product.detail</field>
+            <field name="arch" type="xml">
+                <form string="Detalles del producto">
+                    <group>
+                      <group>
+                          <field name="start_date"/>
+                      </group>
+                      <group>
+                          <field name="end_date"/>
+                      </group>
+                      <group>
+                          <field name="top_products" widget="radio"/>
+                      </group>
+                      <group>
+                          <field name="no_of_products"/>
+                      </group>
+
+                    </group>
+                    <footer>
+                        <button string='Imprimir' name="check_report" type="object" default_focus="1" class="oe_highlight"/>
+                        <button string="Cancelar" class="btn-default" special="cancel"/>
+                    </footer>
+                </form>
+            </field>
+        </record>
+
+        <record id="open_top_sales_action" model="ir.actions.act_window">
+            <field name="name">Productos más vendidos</field>
+            <field name="res_model">product.detail</field>
+            <field name="view_type">form</field>
+            <field name="view_mode">form</field>
+            <field name="target">new</field>
+            <field name="view_id" ref="view_top_sales_form"/>
+        </record>
+      </data>
+</openerp>

+ 12 - 0
views/top_sold_view.xml

@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+    <data>
+
+        <menuitem
+            id="menu_top_sales"
+            name="Top Ventas"
+            parent="base.menu_sales"
+            sequence="11"
+            action="abs_top_sold_products.open_top_sales_action"/>
+      </data>
+  </openerp>

+ 24 - 0
wizard/__init__.py

@@ -0,0 +1,24 @@
+# -*- coding: utf-8 -*-
+#################################################################################
+#
+#    Odoo, Open Source Management Solution
+#    Copyright (C) 2018-Today Ascetic Business Solution <www.asceticbs.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/>.
+#
+#################################################################################
+
+import product_detail
+
+

BIN
wizard/__init__.pyc