From 54245deebda56a24f7a2b266cc93f72670f77eef Mon Sep 17 00:00:00 2001 From: Parth Mehta Date: Wed, 6 Jan 2016 18:45:29 +0530 Subject: [PATCH] [IMP] lunch: view improvement of previous orders. Purpose: 1/ In the lunch app, previous orders list: the products are not displayed. It is written X Records but you don't see the products name. Therefore the information is useless. 2/ It is dangerous to be able to delete a previous order that has been received (it changes the lunch account amount) What is done: In Previous Orders list : - The view should be based on the sales orders lines. In that case, each line = 1 product. - add a note column (between product and status) - add a user column (between status and total) - Rename Total into Price - If order.line status = ordered or received, it shouldn't be possible to delete it. An ir.rule has been added to achieve this. - An additional group access right check is made in the actions 'confirm' 'cancel' and 'order' because they can be called in batch under the Action button. --- addons/lunch/models/lunch.py | 33 ++++++++++------ addons/lunch/security/lunch_security.xml | 10 +++++ addons/lunch/views/lunch_views.xml | 50 +++++++----------------- 3 files changed, 45 insertions(+), 48 deletions(-) diff --git a/addons/lunch/models/lunch.py b/addons/lunch/models/lunch.py index 2f22f69659e..c4906072ad9 100644 --- a/addons/lunch/models/lunch.py +++ b/addons/lunch/models/lunch.py @@ -156,32 +156,41 @@ class LunchOrderLine(models.Model): """ The order_line is ordered to the vendor but isn't received yet """ - self.state = 'ordered' + if self.user_has_groups("lunch.group_lunch_manager"): + self.state = 'ordered' + else: + raise AccessError(_("Only your lunch manager processes the orders.")) @api.one def confirm(self): """ confirm one or more order line, update order status and create new cashmove """ - if self.state != 'confirmed': - values = { - 'user_id': self.user_id.id, - 'amount': -self.price, - 'description': self.product_id.name, - 'order_id': self.id, - 'state': 'order', - 'date': self.date, - } + if self.user_has_groups("lunch.group_lunch_manager"): + if self.state != 'confirmed': + values = { + 'user_id': self.user_id.id, + 'amount': -self.price, + 'description': self.product_id.name, + 'order_id': self.id, + 'state': 'order', + 'date': self.date, + } self.env['lunch.cashmove'].create(values) self.state = 'confirmed' + else: + raise AccessError(_("Only your lunch manager sets the orders as received.")) @api.one def cancel(self): """ cancel one or more order.line, update order status and unlink existing cashmoves """ - self.state = 'cancelled' - self.cashmove.unlink() + if self.user_has_groups("lunch.group_lunch_manager"): + self.state = 'cancelled' + self.cashmove.unlink() + else: + raise AccessError(_("Only your lunch manager cancels the orders.")) class LunchProduct(models.Model): diff --git a/addons/lunch/security/lunch_security.xml b/addons/lunch/security/lunch_security.xml index c622fed989c..40d7dc17268 100644 --- a/addons/lunch/security/lunch_security.xml +++ b/addons/lunch/security/lunch_security.xml @@ -32,4 +32,14 @@ [(1, '=', 1)] + + lunch.order.line: Only new and cancelled order lines deleted. + + [('state', 'in', ('new', 'cancelled'))] + + + + + + diff --git a/addons/lunch/views/lunch_views.xml b/addons/lunch/views/lunch_views.xml index 52c915cc585..4c62058a51d 100644 --- a/addons/lunch/views/lunch_views.xml +++ b/addons/lunch/views/lunch_views.xml @@ -12,6 +12,8 @@ lunch.order.line + + @@ -20,6 +22,7 @@ + @@ -57,26 +60,6 @@ - - - lunch.order.search - lunch.order - - - - - - - - - - - - - - - - lunch.alert.search lunch.alert @@ -129,24 +112,19 @@ - + Your Orders - lunch.order + lunch.order.line tree,form - - {"search_default_is_mine":1, "search_default_received":1} + + {"search_default_is_mine":1} -

- Click to create a lunch order. -

- A lunch order is defined by its user, date and order lines. - Each order line corresponds to a product, an additional note and a price. - Before selecting your order lines, don't forget to read the warnings displayed in the reddish area. + There is no previous order recorded. Click on "My Lunch" and then create a new lunch order.

- + lunch.cashmove.tree @@ -334,15 +312,15 @@ - - -