123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- # -*- 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
- class xsale_reportgral(osv.osv):
- _name = "xsale.reportgral"
- _description = "Listado General de Ventas"
- _auto = False
- _rec_name = 'date'
- _columns = {
- 'date': fields.datetime('Fecha de Orden', readonly=True), # TDE FIXME master: rename into date_order
- 'date_confirm': fields.date('Fecha Confirmada', readonly=True),
- 'product_id': fields.many2one('product.product', 'Producto', readonly=True),
- 'product_uom': fields.many2one('product.uom', 'Unidad de Medida', readonly=True),
- 'product_uom_qty': fields.float('# de Cant.', readonly=True),
- 'product_brand_id':fields.many2one('product.brands', 'Marca', readonly=True),
- 'partner_id': fields.many2one('res.partner', 'Cliente', readonly=True),
- 'city_id': fields.many2one('res.country.state', 'City', readonly=True),
- 'city': fields.char('Ciudad', readonly=True),
- 'company_id': fields.many2one('res.company', 'Compania', readonly=True),
- 'warehouse_id': fields.many2one('stock.warehouse', 'Sucursal', readonly=True),
- 'user_id': fields.many2one('res.users', 'Vendedor', readonly=True),
- 'price_unit': fields.float('Precio Unit.', readonly=True),
- 'price_total': fields.float('Precio Total', readonly=True),
- 'delay': fields.float('Retraso', digits=(16,2), readonly=True),
- 'product_categ_id': fields.many2one('product.category', 'Categoria', readonly=True),
- 'nbr': fields.integer('# de Lineas', readonly=True), # TDE FIXME master: rename into nbr_lines
- 'state': fields.selection([
- ('draft', 'Borrador'),
- ('waiting_date', 'Lista de espera'),
- ('manual', 'Manual En Progreso'),
- ('progress', 'En Progreso'),
- ('invoice_except', 'Excepción factura'),
- ('done', 'Realizado'),
- ('cancel', 'Cancelado')
- ], 'Order Status', readonly=True),
- 'pricelist_id': fields.many2one('product.pricelist', 'Lista de Precio', readonly=True),
- 'analytic_account_id': fields.many2one('account.analytic.account', 'Cuenta Analtica', readonly=True),
- 'section_id': fields.many2one('crm.case.section', 'Seccion'),
- }
- _order = 'date desc'
- def _select(self):
- select_str1 = """
- SELECT min(l.id) as id,
- l.product_id as product_id,
- l.price_unit as price_unit,
- t.uom_id as product_uom,
- q.id as city_id,
- h.name as city,
- sum(l.product_uom_qty / u.factor * u2.factor) as product_uom_qty,
- sum(l.product_uom_qty * l.price_unit * (100.0-l.discount) / 100.0) as price_total,
- count(*) as nbr,
- s.date_order as date,
- s.date_confirm as date_confirm,
- s.partner_id as partner_id,
- s.user_id as user_id,
- s.company_id as company_id,
- s.warehouse_id as warehouse_id,
- extract(epoch from avg(date_trunc('day',s.date_confirm)-date_trunc('day',s.create_date)))/(24*60*60)::decimal(16,2) as delay,
- s.state,
- t.categ_id as product_categ_id,
- t.product_brand_id as product_brand_id,
- s.pricelist_id as pricelist_id,
- s.project_id as analytic_account_id,
- s.section_id as section_id
- """
- return select_str1
- def _from(self):
- from_str1 = """
- sale_order_line l
- join sale_order s on (l.order_id=s.id)
- left join product_product p on (l.product_id=p.id)
- left join product_template t on (p.product_tmpl_id=t.id)
- left join product_brands r on (t.product_brand_id=r.id)
- left join stock_warehouse j on (s.warehouse_id=j.id)
- left join res_partner q on (q.id=s.partner_id)
- left join res_country_state h on (h.id=q.state_id)
- left join product_uom u on (u.id=l.product_uom)
- left join product_uom u2 on (u2.id=t.uom_id)
- """
- return from_str1
- def _group_by(self):
- group_by_str1 = """
- GROUP BY l.product_id,
- l.order_id,
- t.uom_id,
- l.price_unit,
- t.categ_id,
- s.date_order,
- s.date_confirm,
- s.partner_id,
- q.id,
- h.name,
- s.user_id,
- s.company_id,
- s.warehouse_id,
- s.state,
- s.pricelist_id,
- t.product_brand_id,
- s.project_id,
- s.section_id
- """
- return group_by_str1
- def init(self, cr):
- # self._table = sale_report
- tools.drop_view_if_exists(cr, self._table)
- cr.execute("""CREATE or REPLACE VIEW %s as (
- %s
- FROM ( %s )
- %s
- )""" % (self._table, self._select(), self._from(), self._group_by()))
- # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|