diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
| commit | 3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch) | |
| tree | a44932296ef4a9b71d5f010906253d8c53727726 /addons/lunch/report/lunch_cashmove_report.py | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
Diffstat (limited to 'addons/lunch/report/lunch_cashmove_report.py')
| -rw-r--r-- | addons/lunch/report/lunch_cashmove_report.py | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/addons/lunch/report/lunch_cashmove_report.py b/addons/lunch/report/lunch_cashmove_report.py new file mode 100644 index 00000000..16339369 --- /dev/null +++ b/addons/lunch/report/lunch_cashmove_report.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import api, fields, models, tools, _ + + +class CashmoveReport(models.Model): + _name = "lunch.cashmove.report" + _description = 'Cashmoves report' + _auto = False + _order = "date desc" + + id = fields.Integer('ID') + amount = fields.Float('Amount') + date = fields.Date('Date') + currency_id = fields.Many2one('res.currency', string='Currency') + user_id = fields.Many2one('res.users', string='User') + description = fields.Text('Description') + + def name_get(self): + return [(cashmove.id, '%s %s' % (_('Lunch Cashmove'), '#%d' % cashmove.id)) for cashmove in self] + + def init(self): + tools.drop_view_if_exists(self._cr, self._table) + + self._cr.execute(""" + CREATE or REPLACE view %s as ( + SELECT + lc.id as id, + lc.amount as amount, + lc.date as date, + lc.currency_id as currency_id, + lc.user_id as user_id, + lc.description as description + FROM lunch_cashmove lc + UNION ALL + SELECT + -lol.id as id, + -lol.price as amount, + lol.date as date, + lol.currency_id as currency_id, + lol.user_id as user_id, + format('Order: %%s x %%s %%s', lol.quantity::text, lp.name, lol.display_toppings) as description + FROM lunch_order lol + JOIN lunch_product lp ON lp.id = lol.product_id + WHERE + lol.state in ('ordered', 'confirmed') + AND lol.active = True + ); + """ % self._table) |
