report_gposbrds.py 4.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # OpenERP, Open Source Management Solution
  5. # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU Affero General Public License as
  9. # published by the Free Software Foundation, either version 3 of the
  10. # License, or (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU Affero General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Affero General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. #
  20. ##############################################################################
  21. from openerp import tools
  22. from openerp.osv import fields, osv
  23. from datetime import datetime
  24. import json
  25. class pos_reportgral1(osv.osv):
  26. _name = "pos.reportgral1"
  27. _description = "Listado General de Punto de Ventas"
  28. _auto = False
  29. _rec_name = 'date'
  30. _columns = {
  31. 'date': fields.datetime('Date Order', readonly=True),
  32. 'partner_id':fields.many2one('res.partner', 'Cliente', readonly=True),
  33. 'city_id': fields.many2one('res.country.state', 'City', readonly=True),
  34. 'city': fields.char('Ciudad', readonly=True),
  35. 'product_id':fields.many2one('product.product', 'Producto', readonly=True),
  36. 'product_brand_id':fields.many2one('product.brands', 'Marca', readonly=True),
  37. 'state': fields.selection([('draft', 'Nuevo'), ('paid', 'Cerrado'), ('done', 'Sincronizado'), ('invoiced', 'Facturado'), ('cancel', 'Cancelado')],
  38. 'Estado'),
  39. 'user_id':fields.many2one('res.users', 'Vendedor', readonly=True),
  40. 'price_unit':fields.float('Precio Unit.', readonly=True),
  41. 'price_total':fields.float('Precio Total', readonly=True),
  42. 'total_discount':fields.float('Total Desc.', readonly=True),
  43. 'average_price': fields.float('Prec.Promedio', readonly=True,group_operator="avg"),
  44. 'location_id':fields.many2one('stock.location', 'Location', readonly=True),
  45. 'company_id':fields.many2one('res.company', 'Compania', readonly=True),
  46. 'nbr':fields.integer('# de Lineas', readonly=True), # TDE FIXME master: rename into nbr_lines
  47. 'product_qty':fields.integer('Producto Cant.', readonly=True),
  48. 'journal_id': fields.many2one('account.journal', 'Diario'),
  49. 'delay_validation': fields.integer('Validacion Retraso'),
  50. 'product_categ_id': fields.many2one('product.category', 'Categoria', readonly=True),
  51. }
  52. _order = 'date desc'
  53. def init(self, cr):
  54. tools.drop_view_if_exists(cr,'pos_reportgral1')
  55. cr.execute("""
  56. create or replace view pos_reportgral1 as (
  57. select
  58. min(l.id) as id,
  59. count(*) as nbr,
  60. s.date_order as date,
  61. l.price_unit as price_unit,
  62. sum(l.qty * u.factor) as product_qty,
  63. sum(l.qty * l.price_unit) as price_total,
  64. sum((l.qty * l.price_unit) * (l.discount / 100)) as total_discount,
  65. (sum(l.qty*l.price_unit)/sum(l.qty * u.factor))::decimal as average_price,
  66. sum(cast(to_char(date_trunc('day',s.date_order) - date_trunc('day',s.create_date),'DD') as int)) as delay_validation,
  67. s.partner_id as partner_id,
  68. s.state as state,
  69. s.user_id as user_id,
  70. s.location_id as location_id,
  71. q.id as city_id,
  72. h.name as city,
  73. s.company_id as company_id,
  74. s.sale_journal as journal_id,
  75. l.product_id as product_id,
  76. pt.product_brand_id as product_brand_id,
  77. pt.categ_id as product_categ_id
  78. from pos_order_line as l
  79. left join pos_order s on (s.id=l.order_id)
  80. left join product_product p on (p.id=l.product_id)
  81. left join product_template pt on (pt.id=p.product_tmpl_id)
  82. left join product_brands r on (r.id=pt.product_brand_id)
  83. left join product_uom u on (u.id=pt.uom_id)
  84. left join res_partner q on (q.id=s.partner_id)
  85. left join res_country_state h on (h.id=q.state_id)
  86. group by
  87. s.date_order, s.partner_id,q.id,h.name,s.state, pt.categ_id, l.price_unit,pt.product_brand_id,
  88. s.user_id,s.location_id,s.company_id,q.city,s.sale_journal,l.product_id,s.create_date
  89. having
  90. sum(l.qty * u.factor) != 0)""")
  91. # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: