my_report_partner.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # #
  2. # You should have received a copy of the GNU Affero General Public License #
  3. # along with this program. If not, see <http://www.gnu.org/licenses/>. #
  4. # #
  5. #################################################################################
  6. from openerp.osv import fields,osv
  7. from openerp import tools
  8. class my_partner_model(osv.osv):
  9. _name = "my.partner.model"
  10. _description = "Listado de Clientes"
  11. _auto = False
  12. _columns = {
  13. 'partner_id': fields.many2one('res.partner', string='Cliente', required=True, readonly=True),
  14. 'name': fields.char('Nombre', readonly=True),
  15. 'street': fields.char('Direccion', readonly=True),
  16. 'email': fields.char('Email', readonly=True),
  17. 'mobile': fields.char('Celular', readonly=True),
  18. 'phone': fields.char('Telefono', readonly=True),
  19. 'total_facturado': fields.float('Facturado', readonly=True),
  20. 'user_id':fields.many2one('res.users', 'Vendedor', readonly=True),
  21. 'date': fields.datetime('Fecha', readonly=True),
  22. 'company_id':fields.many2one('res.company', 'Compania', readonly=True),
  23. }
  24. _order = 'date asc'
  25. def init(self, cr):
  26. tools.sql.drop_view_if_exists(cr, 'my_partner_model')
  27. cr.execute("""
  28. CREATE OR REPLACE VIEW my_partner_model AS (
  29. SELECT a.id AS id,
  30. c.partner_id AS partner_id,
  31. a.name,
  32. a.street AS street,
  33. a.email AS email,
  34. a.mobile AS mobile,
  35. a.phone AS phone,
  36. c.price_total AS total_facturado,
  37. p.user_id as user_id,
  38. c.date AS date,
  39. c.company_id as company_id
  40. FROM res_partner a
  41. left join pos_order p on p.partner_id=a.id
  42. LEFT JOIN(select s.partner_id AS partner_id, sum(l.qty * l.price_unit) as price_total, MAX(l.create_date) AS date, s.company_id as company_id
  43. from pos_order_line as l
  44. left join pos_order s on s.id=l.order_id
  45. group by s.partner_id,s.company_id) c on c.partner_id=a.id
  46. WHERE a.customer= True and c.price_total>0
  47. )
  48. """)
  49. my_partner_model()