19.0 vanilla

This commit is contained in:
Ernad Husremovic 2026-03-09 09:32:43 +01:00
parent 4607ccbd2e
commit 825ff6514e
487 changed files with 184979 additions and 195262 deletions

View file

@ -1,16 +1,17 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import _, http, fields
from odoo.exceptions import AccessError
from odoo.fields import Domain
from odoo.http import request
from odoo.osv import expression
from odoo.tools import float_round, float_repr
class LunchController(http.Controller):
@http.route('/lunch/infos', type='json', auth='user')
def infos(self, user_id=None):
@http.route('/lunch/infos', type='jsonrpc', auth='user')
def infos(self, user_id=None, context=None):
if context:
request.update_context(**context)
self._check_user_impersonification(user_id)
user = request.env['res.users'].browse(user_id) if user_id else request.env.user
@ -19,24 +20,38 @@ class LunchController(http.Controller):
lines = self._get_current_lines(user)
if lines:
translated_states = dict(request.env['lunch.order']._fields['state']._description_selection(request.env))
lines = [{'id': line.id,
'product': (line.product_id.id, line.product_id.name, float_repr(float_round(line.price, 2), 2)),
'toppings': [(topping.name, float_repr(float_round(topping.price, 2), 2))
for topping in line.topping_ids_1 | line.topping_ids_2 | line.topping_ids_3],
'quantity': line.quantity,
'price': line.price,
'raw_state': line.state,
'state': translated_states[line.state],
'note': line.note} for line in lines.sorted('date')]
lines = [{
'id': line.id,
'product': (line.product_id.id, line.product_id.name, float_repr(
float_round(line.product_id.price, 2) * line.quantity, 2),
float_round(line.product_id.price, 2)),
'toppings': [(topping.name, float_repr(float_round(topping.price, 2) * line.quantity, 2),
float_round(topping.price, 2))
for topping in line.topping_ids_1 | line.topping_ids_2 | line.topping_ids_3],
'quantity': line.quantity,
'price': line.price,
'raw_state': line.state,
'state': translated_states[line.state],
'date': line.date,
'location': line.lunch_location_id.name,
'note': line.note
} for line in lines.sorted('date')]
total = float_round(sum(line['price'] for line in lines), 2)
paid_subtotal = float_round(sum(line['price'] for line in lines if line['raw_state'] != 'new'), 2)
unpaid_subtotal = total - paid_subtotal
infos.update({
'total': float_repr(float_round(sum(line['price'] for line in lines), 2), 2),
'total': float_repr(total, 2),
'paid_subtotal': float_repr(paid_subtotal, 2),
'unpaid_subtotal': float_repr(unpaid_subtotal, 2),
'raw_state': self._get_state(lines),
'lines': lines,
})
return infos
@http.route('/lunch/trash', type='json', auth='user')
def trash(self, user_id=None):
@http.route('/lunch/trash', type='jsonrpc', auth='user')
def trash(self, user_id=None, context=None):
if context:
request.update_context(**context)
self._check_user_impersonification(user_id)
user = request.env['res.users'].browse(user_id) if user_id else request.env.user
@ -45,34 +60,39 @@ class LunchController(http.Controller):
lines.action_cancel()
lines.unlink()
@http.route('/lunch/pay', type='json', auth='user')
def pay(self, user_id=None):
@http.route('/lunch/pay', type='jsonrpc', auth='user')
def pay(self, user_id=None, context=None):
if context:
request.update_context(**context)
self._check_user_impersonification(user_id)
user = request.env['res.users'].browse(user_id) if user_id else request.env.user
lines = self._get_current_lines(user)
if lines:
lines = lines.filtered(lambda line: line.state == 'new')
lines.action_order()
return True
return False
@http.route('/lunch/payment_message', type='json', auth='user')
@http.route('/lunch/payment_message', type='jsonrpc', auth='user')
def payment_message(self):
return {'message': request.env['ir.qweb']._render('lunch.lunch_payment_dialog', {})}
@http.route('/lunch/user_location_set', type='json', auth='user')
def set_user_location(self, location_id=None, user_id=None):
@http.route('/lunch/user_location_set', type='jsonrpc', auth='user')
def set_user_location(self, location_id=None, user_id=None, context=None):
if context:
request.update_context(**context)
self._check_user_impersonification(user_id)
user = request.env['res.users'].browse(user_id) if user_id else request.env.user
user.sudo().last_lunch_location_id = request.env['lunch.location'].browse(location_id)
return True
@http.route('/lunch/user_location_get', type='json', auth='user')
def get_user_location(self, user_id=None):
@http.route('/lunch/user_location_get', type='jsonrpc', auth='user')
def get_user_location(self, user_id=None, context=None):
if context:
request.update_context(**context)
self._check_user_impersonification(user_id)
user = request.env['res.users'].browse(user_id) if user_id else request.env.user
@ -95,6 +115,7 @@ class LunchController(http.Controller):
'username': user.sudo().name,
'userimage': '/web/image?model=res.users&id=%s&field=avatar_128' % user.id,
'wallet': request.env['lunch.cashmove'].get_wallet_balance(user, False),
'wallet_with_config': request.env['lunch.cashmove'].get_wallet_balance(user),
'is_manager': is_manager,
'group_portal_id': request.env.ref('base.group_portal').id,
'locations': request.env['lunch.location'].search_read([], ['name']),
@ -107,10 +128,10 @@ class LunchController(http.Controller):
if not user_location or not has_multi_company_access:
user.last_lunch_location_id = user_location = request.env['lunch.location'].search([], limit=1) or user_location
alert_domain = expression.AND([
[('available_today', '=', True)],
[('location_ids', 'in', user_location.id)],
[('mode', '=', 'alert')],
alert_domain = Domain.AND([
Domain('available_today', '=', True),
Domain('location_ids', 'in', user_location.id),
Domain('mode', '=', 'alert'),
])
res.update({
@ -126,7 +147,7 @@ class LunchController(http.Controller):
def _get_current_lines(self, user):
return request.env['lunch.order'].search(
[('user_id', '=', user.id), ('date', '=', fields.Date.context_today(user)), ('state', '!=', 'cancelled')]
[('user_id', '=', user.id), ('date', '>=', fields.Date.context_today(user)), ('state', '!=', 'cancelled')]
)
def _get_state(self, lines):