summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorParth Mehta <pme@odoo.com>2016-01-06 18:45:29 +0530
committerYannick Tivisse <yti@odoo.com>2016-03-10 10:18:17 +0100
commit54245deebda56a24f7a2b266cc93f72670f77eef (patch)
tree0d0d2dfc3ce1d705fb900b757767f6abdd049217
parent6db140d5d6f4bf6b9a0772ad75ceeb5721e773f0 (diff)
[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.
-rw-r--r--addons/lunch/models/lunch.py33
-rw-r--r--addons/lunch/security/lunch_security.xml10
-rw-r--r--addons/lunch/views/lunch_views.xml50
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 @@
<field name="groups" eval="[(4, ref('group_lunch_manager'))]"/>
<field name="domain_force">[(1, '=', 1)]</field>
</record>
+ <record id="lunch_order_line_rule_delete" model="ir.rule">
+ <field name="name">lunch.order.line: Only new and cancelled order lines deleted.</field>
+ <field name="model_id" ref="lunch.model_lunch_order_line"/>
+ <field name="domain_force">[('state', 'in', ('new', 'cancelled'))]</field>
+ <field name="perm_read" eval="0"/>
+ <field name="perm_write" eval="0"/>
+ <field name="perm_create" eval="0"/>
+ <field name="perm_unlink" eval="1" />
+ <field name="groups" eval="[(4,ref('lunch.group_lunch_user'))]"/>
+ </record>
</odoo>
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 @@
<field name="model">lunch.order.line</field>
<field name="arch" type="xml">
<search string="Search">
+ <filter name='is_mine' string="My Orders" domain="[('user_id','=',uid)]"/>
+ <separator/>
<field name="name" filter_domain="['|', ('name', 'ilike', self), ('note', 'ilike', self)]"/>
<filter name="not_confirmed" string="Not Received" domain="[('state','!=',('confirmed'))]"/>
<filter name="confirmed" string="Received" domain="[('state','=','confirmed')]"/>
@@ -20,6 +22,7 @@
<filter name="today" string="Today" domain="[('date','=',time.strftime('%%Y-%%m-%%d'))]"/>
<field name="user_id"/>
<group expand="0" string="Group By">
+ <filter name="group_by_order_id" string="By Order" context="{'group_by':'order_id'}"/>
<filter name="group_by_supplier" string="By Vendor" context="{'group_by':'supplier'}"/>
<filter name="group_by_date" string="Order Month" context="{'group_by':'date'}" help="Vendor Orders by Month"/>
</group>
@@ -57,26 +60,6 @@
</field>
</record>
- <!--View search for order-->
- <record id="lunch_order_view_search" model="ir.ui.view">
- <field name='name'>lunch.order.search</field>
- <field name='model'>lunch.order</field>
- <field name='arch' type='xml'>
- <search string="lunch orders">
- <field name="user_id"/>
- <field name="date"/>
- <field name="order_line_ids"/>
- <filter name='is_mine' string="My Orders" domain="[('user_id','=',uid)]"/>
- <separator/>
- <filter name="new" string="New" domain="[('state','=','new')]"/>
- <filter name="received" string="Received" domain="[('state','=','confirmed')]"/>
- <filter name="cancelled" string="Cancelled" domain="[('state','=','cancelled')]"/>
- <filter name='by_users' string="Users" context="{'group_by':'user_id'}"/>
- </search>
- </field>
- </record>
-
-
<record id="lunch_alert_view_search" model="ir.ui.view">
<field name="name">lunch.alert.search</field>
<field name="model">lunch.alert</field>
@@ -129,24 +112,19 @@
</record>
<menuitem name="New Order" parent="menu_lunch_title" id="lunch_order_menu_form" action="lunch_order_action_form" sequence="1"/>
- <record id="lunch_order_action_tree" model="ir.actions.act_window">
+ <record id="lunch_order_line_action" model="ir.actions.act_window">
<field name="name">Your Orders</field>
- <field name="res_model">lunch.order</field>
+ <field name="res_model">lunch.order.line</field>
<field name="view_mode">tree,form</field>
- <field name="search_view_id" ref="lunch_order_view_search"/>
- <field name="context">{"search_default_is_mine":1, "search_default_received":1}</field>
+ <field name="search_view_id" ref="lunch_order_line_view_search"/>
+ <field name="context">{"search_default_is_mine":1}</field>
<field name="help" type="html">
- <p class="oe_view_nocontent_create">
- Click to create a lunch order.
- </p>
<p>
- 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.
</p>
</field>
</record>
- <menuitem name="Previous Orders" parent="menu_lunch_title" id="lunch_order_menu_tree" action="lunch_order_action_tree" sequence="2"/>
+ <menuitem name="Previous Orders" parent="menu_lunch_title" id="lunch_order_menu_tree" action="lunch_order_line_action" sequence="2"/>
<record id="lunch_cashmove_view_tree_2" model="ir.ui.view">
<field name="name">lunch.cashmove.tree</field>
@@ -334,15 +312,15 @@
<field name="arch" type="xml">
<tree string="Order lines Tree" create="false" edit="false">
<field name='date'/>
- <field name='user_id'/>
<field name='supplier' invisible='1'/>
<field name='product_id'/>
<field name='note'/>
<field name='state'/>
- <field name='price' sum="Total"/>
- <button name="order" string="Order" type="object" icon="terp-call-start" attrs="{'invisible': ['|',('state','=','confirmed'),('state','=','ordered')]}"/>
- <button name="confirm" string="Receive" type="object" icon="gtk-apply" attrs="{'invisible': [('state','!=','ordered')]}"/>
- <button name="cancel" string="Cancel" type="object" icon="gtk-cancel" attrs="{'invisible': [('state','=','cancelled')]}"/>
+ <field name='user_id'/>
+ <field name='price' sum="Total" string="Price"/>
+ <button name="order" string="Order" type="object" icon="terp-call-start" attrs="{'invisible': ['|',('state','=','confirmed'),('state','=','ordered')]}" groups="lunch.group_lunch_manager"/>
+ <button name="confirm" string="Receive" type="object" icon="gtk-apply" attrs="{'invisible': [('state','!=','ordered')]}" groups="lunch.group_lunch_manager"/>
+ <button name="cancel" string="Cancel" type="object" icon="gtk-cancel" attrs="{'invisible': [('state','=','cancelled')]}" groups="lunch.group_lunch_manager"/>
</tree>
</field>
</record>