lunch_cashmove_report.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. # -*- coding: utf-8 -*-
  2. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  3. from odoo import api, fields, models, tools, _
  4. class CashmoveReport(models.Model):
  5. _name = "lunch.cashmove.report"
  6. _description = 'Cashmoves report'
  7. _auto = False
  8. _order = "date desc"
  9. id = fields.Integer('ID')
  10. amount = fields.Float('Amount')
  11. date = fields.Date('Date')
  12. currency_id = fields.Many2one('res.currency', string='Currency')
  13. user_id = fields.Many2one('res.users', string='User')
  14. description = fields.Text('Description')
  15. def name_get(self):
  16. return [(cashmove.id, '%s %s' % (_('Lunch Cashmove'), '#%d' % cashmove.id)) for cashmove in self]
  17. def init(self):
  18. tools.drop_view_if_exists(self._cr, self._table)
  19. self._cr.execute("""
  20. CREATE or REPLACE view %s as (
  21. SELECT
  22. lc.id as id,
  23. lc.amount as amount,
  24. lc.date as date,
  25. lc.currency_id as currency_id,
  26. lc.user_id as user_id,
  27. lc.description as description
  28. FROM lunch_cashmove lc
  29. UNION ALL
  30. SELECT
  31. -lol.id as id,
  32. -lol.price as amount,
  33. lol.date as date,
  34. lol.currency_id as currency_id,
  35. lol.user_id as user_id,
  36. format('Order: %%s x %%s %%s', lol.quantity::text, lp.name->>'en_US', lol.display_toppings) as description
  37. FROM lunch_order lol
  38. JOIN lunch_product lp ON lp.id = lol.product_id
  39. WHERE
  40. lol.state in ('ordered', 'confirmed')
  41. AND lol.active = True
  42. );
  43. """ % self._table)