12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- # -*- 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
- from datetime import datetime
- import json
- class pos_reportgral1(osv.osv):
- _name = "pos.reportgral1"
- _description = "Listado General de Punto de Ventas"
- _auto = False
- _rec_name = 'date'
- _columns = {
- 'date': fields.datetime('Date Order', 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),
- 'product_id':fields.many2one('product.product', 'Producto', readonly=True),
- 'product_brand_id':fields.many2one('product.brands', 'Marca', readonly=True),
- 'state': fields.selection([('draft', 'Nuevo'), ('paid', 'Cerrado'), ('done', 'Sincronizado'), ('invoiced', 'Facturado'), ('cancel', 'Cancelado')],
- 'Estado'),
- '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),
- 'total_discount':fields.float('Total Desc.', readonly=True),
- 'average_price': fields.float('Prec.Promedio', readonly=True,group_operator="avg"),
- 'location_id':fields.many2one('stock.location', 'Location', readonly=True),
- 'company_id':fields.many2one('res.company', 'Compania', readonly=True),
- 'nbr':fields.integer('# de Lineas', readonly=True), # TDE FIXME master: rename into nbr_lines
- 'product_qty':fields.integer('Producto Cant.', readonly=True),
- 'journal_id': fields.many2one('account.journal', 'Diario'),
- 'delay_validation': fields.integer('Validacion Retraso'),
- 'product_categ_id': fields.many2one('product.category', 'Categoria', readonly=True),
- }
- _order = 'date desc'
- def init(self, cr):
- tools.drop_view_if_exists(cr,'pos_reportgral1')
- cr.execute("""
- create or replace view pos_reportgral1 as (
- select
- min(l.id) as id,
- count(*) as nbr,
- s.date_order as date,
- l.price_unit as price_unit,
- sum(l.qty * u.factor) as product_qty,
- sum(l.qty * l.price_unit) as price_total,
- sum((l.qty * l.price_unit) * (l.discount / 100)) as total_discount,
- (sum(l.qty*l.price_unit)/sum(l.qty * u.factor))::decimal as average_price,
- sum(cast(to_char(date_trunc('day',s.date_order) - date_trunc('day',s.create_date),'DD') as int)) as delay_validation,
- s.partner_id as partner_id,
- s.state as state,
- s.user_id as user_id,
- s.location_id as location_id,
- q.id as city_id,
- h.name as city,
- s.company_id as company_id,
- s.sale_journal as journal_id,
- l.product_id as product_id,
- pt.product_brand_id as product_brand_id,
- pt.categ_id as product_categ_id
- from pos_order_line as l
- left join pos_order s on (s.id=l.order_id)
- left join product_product p on (p.id=l.product_id)
- left join product_template pt on (pt.id=p.product_tmpl_id)
- left join product_brands r on (r.id=pt.product_brand_id)
- left join product_uom u on (u.id=pt.uom_id)
- left join res_partner q on (q.id=s.partner_id)
- left join res_country_state h on (h.id=q.state_id)
- group by
- s.date_order, s.partner_id,q.id,h.name,s.state, pt.categ_id, l.price_unit,pt.product_brand_id,
- s.user_id,s.location_id,s.company_id,q.city,s.sale_journal,l.product_id,s.create_date
- having
- sum(l.qty * u.factor) != 0)""")
- # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|