diff --git a/addons/lunch/__init__.py b/addons/lunch/__init__.py
index 14977cd974f..fb4acc9982e 100644
--- a/addons/lunch/__init__.py
+++ b/addons/lunch/__init__.py
@@ -20,5 +20,5 @@
##############################################################################
import lunch
-import partner
-import report
\ No newline at end of file
+import report
+import wizard
diff --git a/addons/lunch/__openerp__.py b/addons/lunch/__openerp__.py
index f25e75028e0..c07f060b278 100644
--- a/addons/lunch/__openerp__.py
+++ b/addons/lunch/__openerp__.py
@@ -32,8 +32,7 @@ The base module to manage lunch.
keep track for the Lunch Order, Cash Moves and Product. Apply Different
Category for the product.
""",
- #TODO: remove `view´ folder. what's the use of partner_view.xml? what about lunch_validation_view.xml and lunch_cancel_view.xml? Couldn't that be merged in a single file?
- 'data': ['security/groups.xml','view/lunch_view.xml','view/partner_view.xml','view/lunch_validation_view.xml','view/lunch_cancel_view.xml','lunch_report.xml',
+ 'data': ['security/groups.xml','lunch_view.xml','wizard/lunch_validation_view.xml','wizard/lunch_cancel_view.xml','lunch_report.xml',
'report/report_lunch_order_view.xml',
'security/ir.model.access.csv',],
'css':['static/src/css/lunch_style.css'],
diff --git a/addons/lunch/lunch.py b/addons/lunch/lunch.py
index 2094985f7b1..b34bf52707c 100644
--- a/addons/lunch/lunch.py
+++ b/addons/lunch/lunch.py
@@ -37,12 +37,20 @@ class lunch_order(osv.Model):
result={}
for order in self.browse(cr, uid, ids, context=context):
value = 0.0
- for product in order.products: #TODO: use meaningful variable names `for order_line in ...´
+ for product in order.order_line_ids: #TODO: use meaningful variable names `for order_line in ...´
if product.state != 'cancelled':
value += product.product.price
result[order.id]=value
return result
+ def _compute_total(self, cr, uid, ids, name, context=None):
+ """ compute total"""
+ result= {}
+ value = 0.0
+ for order_line in self.browse(cr, uid, ids, context=context):
+ value+=order_line.price
+ result[order_line.order_id.id]=value
+ return result
def add_preference(self, cr, uid, ids, pref_id, context=None):
""" create a new order line based on the preference selected (pref_id)"""
@@ -62,12 +70,7 @@ class lunch_order(osv.Model):
'supplier': prod_ref.browse(cr,uid,pref["product"].id,context=context)['supplier'].id
}
new_id = orderline_ref.create(cr,uid,new_order_line)
- order.products.append(new_id)
- #TODO: total is a computed field, so the write is useless, no?
- # ---> If I remove it, the total for order are not good (I try many times)
- # use store = {...}
- total = self._price_get(cr,uid,ids," "," ",context=context)
- self.write(cr,uid,ids,{},context)
+ order.order_line_ids.append(new_id)
return True
def _alerts_get(self, cr, uid, ids, name, arg, context=None):
@@ -127,7 +130,7 @@ class lunch_order(osv.Model):
def _default_alerts_get(self,cr,uid,arg,context=None):
""" get the alerts to display on the order form """
alert_ref = self.pool.get('lunch.alert')
- alert_ids = alert_ref.search(cr,uid,[('active','=',True)],context=context) #TODO: active=True is automatically added by orm, so this param can be removed
+ alert_ids = alert_ref.search(cr,uid,[('lunch_active','=',True)],context=context)
alert_msg=""
for alert in alert_ref.browse(cr,uid,alert_ids,context=context):
if self.can_display_alert(alert):
@@ -155,12 +158,12 @@ class lunch_order(osv.Model):
alert_msg+='\n'
return alert_msg
- def onchange_price(self,cr,uid,ids,products,context=None):
+ def onchange_price(self,cr,uid,ids,order_line_ids,context=None):
""" Onchange methode that refresh the total price of order"""
res = {'value':{'total':0.0}}
- if products:
+ if order_line_ids:
tot = 0.0
- for prod in products:
+ for prod in order_line_ids:
orderline = {}
#TODO: that's weird. should truy to find another way to compute total on order lines when record is not saved...
# or at least put some comments
@@ -179,8 +182,8 @@ class lunch_order(osv.Model):
prod_ref = self.pool.get('lunch.product')
new_id = super(lunch_order, self).create(cr, uid, values, context=context)
#When we create a new order we also create new preference
- if len(values['products'])>0 and values['user_id']==uid:
- for prods in values['products']:
+ if len(values['order_line_ids'])>0 and values['user_id']==uid:
+ for prods in values['order_line_ids']:
already_exists = False #alreadyexist is used to check if a preferece already exists.
for pref in pref_ref.browse(cr,uid,pref_ids,context=context):
if pref['product'].id == prods[2]['product']:
@@ -264,8 +267,10 @@ class lunch_order(osv.Model):
_columns = {
'user_id' : fields.many2one('res.users','User Name',required=True,readonly=True, states={'new':[('readonly', False)]}),
'date': fields.date('Date', required=True,readonly=True, states={'new':[('readonly', False)]}),
- 'products' : fields.one2many('lunch.order.line','order_id','Products',ondelete="cascade",readonly=True,states={'new':[('readonly', False)]}), #TODO: a good naming convention is to finish your field names with `_ids´ for *2many fields. BTW, the field name should reflect more it's nature: `order_line_ids´ for example
- 'total' : fields.function(_price_get, string="Total",store=True),
+ 'order_line_ids' : fields.one2many('lunch.order.line','order_id','Products',ondelete="cascade",readonly=True,states={'new':[('readonly', False)]}), #TODO: a good naming convention is to finish your field names with `_ids´ for *2many fields. BTW, the field name should reflect more it's nature: `order_line_ids´ for example
+ 'total' : fields.function(_price_get, string="Total",store={
+ 'lunch.order.line': (_compute_total, ['price'], 20),
+ }),
'state': fields.selection([('new', 'New'),('confirmed','Confirmed'), ('cancelled','Cancelled'), ('partially','Partially Confirmed')],'Status', readonly=True, select=True), #TODO: parcially? #TODO: the labels are confusing. confirmed=='received' or 'delivered'...
'alerts': fields.function(_alerts_get, string="Alerts", type='text'),
'preferences': fields.many2many("lunch.preference",'lunch_preference_rel','preferences','order_id','Preferences'),
@@ -313,7 +318,7 @@ class lunch_order_line(osv.Model):
self.write(cr,uid,[order_line.id],{'cashmove':[('0',new_id)], 'state':'confirmed'},context)
for order_line in self.browse(cr,uid,ids,context=context):
isconfirmed = True
- for product in order_line.order_id.products:
+ for product in order_line.order_id.order_line_ids:
if product.state == 'new':
isconfirmed = False
if product.state == 'cancelled':
@@ -334,7 +339,7 @@ class lunch_order_line(osv.Model):
for order_line in self.browse(cr,uid,ids,context=context):
hasconfirmed = False
hasnew = False
- for product in order_line.order_id.products:
+ for product in order_line.order_id.order_line_ids:
if product.state=='confirmed':
hasconfirmed= True
if product.state=='new':
@@ -427,7 +432,7 @@ class lunch_alert(osv.Model):
_description = 'lunch alert'
_columns = {
'message' : fields.text('Message',size=256, required=True),
- 'active' : fields.boolean('Active'),
+ 'lunch_active' : fields.boolean('Active'),
'day' : fields.selection([('specific','Specific day'), ('week','Every Week'), ('days','Every Day')], 'Recurrency'),
'specific' : fields.date('Day'),
'monday' : fields.boolean('Monday'),
@@ -441,61 +446,8 @@ class lunch_alert(osv.Model):
'active_to': fields.float('And',required=True),
}
-class lunch_cancel(osv.Model):
- """ lunch cancel """
- _name = 'lunch.cancel'
- _description = 'cancel lunch order'
-
- def cancel(self,cr,uid,ids,context=None):
- #confirm one or more order.line, update order status and create new cashmove
- cashmove_ref = self.pool.get('lunch.cashmove')
- order_lines_ref = self.pool.get('lunch.order.line')
- orders_ref = self.pool.get('lunch.order')
- order_ids = context.get('active_ids', [])
-
- for order in order_lines_ref.browse(cr,uid,order_ids,context=context):
- order_lines_ref.write(cr,uid,[order.id],{'state':'cancelled'},context)
- for cash in order.cashmove:
- cashmove_ref.unlink(cr,uid,cash.id,context)
- for order in order_lines_ref.browse(cr,uid,order_ids,context=context):
- hasconfirmed = False
- hasnew = False
- for product in order.order_id.products:
- if product.state=='confirmed':
- hasconfirmed= True
- if product.state=='new':
- hasnew= True
- if hasnew == False:
- if hasconfirmed == False:
- orders_ref.write(cr,uid,[order.order_id.id],{'state':'cancelled'},context)
- return {}
- orders_ref.write(cr,uid,[order.order_id.id],{'state':'partially'},context)
- return {}
-
-class lunch_validation(osv.Model):
- """ lunch validation """
- _name = 'lunch.validation'
- _description = 'lunch validation for order'
-
- def confirm(self,cr,uid,ids,context=None):
- #confirm one or more order.line, update order status and create new cashmove
- cashmove_ref = self.pool.get('lunch.cashmove')
- order_lines_ref = self.pool.get('lunch.order.line')
- orders_ref = self.pool.get('lunch.order')
- order_ids = context.get('active_ids', [])
-
- for order in order_lines_ref.browse(cr,uid,order_ids,context=context):
- if order.state!='confirmed':
- new_id = cashmove_ref.create(cr,uid,{'user_id': order.user_id.id, 'amount':0 - order.price,'description':order.product.name, 'order_id':order.id, 'state':'order', 'date':order.date})
- order_lines_ref.write(cr,uid,[order.id],{'cashmove':[('0',new_id)], 'state':'confirmed'},context)
- for order in order_lines_ref.browse(cr,uid,order_ids,context=context):
- isconfirmed = True
- for product in order.order_id.products:
- if product.state == 'new':
- isconfirmed = False
- if product.state == 'cancelled':
- isconfirmed = False
- orders_ref.write(cr,uid,[order.order_id.id],{'state':'partially'},context)
- if isconfirmed == True:
- orders_ref.write(cr,uid,[order.order_id.id],{'state':'confirmed'},context)
- return {}
+class res_partner (osv.Model):
+ _inherit = 'res.partner'
+ _columns = {
+ 'supplier_lunch': fields.boolean('Lunch Supplier'),
+ }
diff --git a/addons/lunch/lunch_demo.xml b/addons/lunch/lunch_demo.xml
index 8b5b98b4960..7bac4bb5dad 100644
--- a/addons/lunch/lunch_demo.xml
+++ b/addons/lunch/lunch_demo.xml
@@ -110,28 +110,25 @@
-
+
new
1
- 7.70
-
+
confirmed
1
- 7.40
-
+
cancelled
1
- 2.50
@@ -142,7 +139,6 @@
+Emmental
- 7.70
@@ -153,7 +149,6 @@
+Champignons
- 7.40
@@ -164,7 +159,6 @@
+Salade +Tomates +Comcombres
- 2.50
@@ -217,7 +211,7 @@
Lunch must be ordered before 10h30 am
days
- t
+ t
0
0
diff --git a/addons/lunch/view/lunch_view.xml b/addons/lunch/lunch_view.xml
similarity index 96%
rename from addons/lunch/view/lunch_view.xml
rename to addons/lunch/lunch_view.xml
index 6bfa10898b0..c8f779ae182 100644
--- a/addons/lunch/view/lunch_view.xml
+++ b/addons/lunch/lunch_view.xml
@@ -275,7 +275,7 @@
-
+
@@ -308,7 +308,7 @@
-
+
@@ -419,7 +419,7 @@
-
+
@@ -460,7 +460,7 @@
-
+
@@ -469,5 +469,17 @@
+
+
+ partner.supplier.name.form
+ res.partner
+ form
+
+
+
+
+
+
+
diff --git a/addons/lunch/partner.py b/addons/lunch/partner.py
deleted file mode 100644
index c6eb3d681a7..00000000000
--- a/addons/lunch/partner.py
+++ /dev/null
@@ -1,7 +0,0 @@
-from osv import osv, fields
-
-class res_partner (osv.Model):
- _inherit = 'res.partner'
- _columns = {
- 'supplier_lunch': fields.boolean('Lunch Supplier'),
- }
diff --git a/addons/lunch/view/partner_view.xml b/addons/lunch/view/partner_view.xml
deleted file mode 100644
index c5cdb8c8995..00000000000
--- a/addons/lunch/view/partner_view.xml
+++ /dev/null
@@ -1,18 +0,0 @@
-
-
-
-
- partner.supplier.name.form
- res.partner
- form
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/addons/lunch/wizard/__init__.py b/addons/lunch/wizard/__init__.py
new file mode 100644
index 00000000000..5761debe4f9
--- /dev/null
+++ b/addons/lunch/wizard/__init__.py
@@ -0,0 +1,23 @@
+# -*- encoding: utf-8 -*-
+##############################################################################
+#
+# OpenERP, Open Source Management Solution
+# Copyright (C) 2004-2012 Tiny SPRL ().
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see .
+#
+##############################################################################
+
+import lunch_validation
+import lunch_cancel
diff --git a/addons/lunch/wizard/lunch_cancel.py b/addons/lunch/wizard/lunch_cancel.py
new file mode 100644
index 00000000000..4d7ff0336d1
--- /dev/null
+++ b/addons/lunch/wizard/lunch_cancel.py
@@ -0,0 +1,32 @@
+from osv import osv, fields
+
+class lunch_cancel(osv.Model):
+ """ lunch cancel """
+ _name = 'lunch.cancel'
+ _description = 'cancel lunch order'
+
+ def cancel(self,cr,uid,ids,context=None):
+ #confirm one or more order.line, update order status and create new cashmove
+ cashmove_ref = self.pool.get('lunch.cashmove')
+ order_lines_ref = self.pool.get('lunch.order.line')
+ orders_ref = self.pool.get('lunch.order')
+ order_ids = context.get('active_ids', [])
+
+ for order in order_lines_ref.browse(cr,uid,order_ids,context=context):
+ order_lines_ref.write(cr,uid,[order.id],{'state':'cancelled'},context)
+ for cash in order.cashmove:
+ cashmove_ref.unlink(cr,uid,cash.id,context)
+ for order in order_lines_ref.browse(cr,uid,order_ids,context=context):
+ hasconfirmed = False
+ hasnew = False
+ for product in order.order_id.products:
+ if product.state=='confirmed':
+ hasconfirmed= True
+ if product.state=='new':
+ hasnew= True
+ if hasnew == False:
+ if hasconfirmed == False:
+ orders_ref.write(cr,uid,[order.order_id.id],{'state':'cancelled'},context)
+ return {}
+ orders_ref.write(cr,uid,[order.order_id.id],{'state':'partially'},context)
+ return {}
\ No newline at end of file
diff --git a/addons/lunch/view/lunch_cancel_view.xml b/addons/lunch/wizard/lunch_cancel_view.xml
similarity index 100%
rename from addons/lunch/view/lunch_cancel_view.xml
rename to addons/lunch/wizard/lunch_cancel_view.xml
diff --git a/addons/lunch/wizard/lunch_validation.py b/addons/lunch/wizard/lunch_validation.py
new file mode 100644
index 00000000000..b5b8610a534
--- /dev/null
+++ b/addons/lunch/wizard/lunch_validation.py
@@ -0,0 +1,29 @@
+from osv import osv, fields
+
+class lunch_validation(osv.Model):
+ """ lunch validation """
+ _name = 'lunch.validation'
+ _description = 'lunch validation for order'
+
+ def confirm(self,cr,uid,ids,context=None):
+ #confirm one or more order.line, update order status and create new cashmove
+ cashmove_ref = self.pool.get('lunch.cashmove')
+ order_lines_ref = self.pool.get('lunch.order.line')
+ orders_ref = self.pool.get('lunch.order')
+ order_ids = context.get('active_ids', [])
+
+ for order in order_lines_ref.browse(cr,uid,order_ids,context=context):
+ if order.state!='confirmed':
+ new_id = cashmove_ref.create(cr,uid,{'user_id': order.user_id.id, 'amount':0 - order.price,'description':order.product.name, 'order_id':order.id, 'state':'order', 'date':order.date})
+ order_lines_ref.write(cr,uid,[order.id],{'cashmove':[('0',new_id)], 'state':'confirmed'},context)
+ for order in order_lines_ref.browse(cr,uid,order_ids,context=context):
+ isconfirmed = True
+ for product in order.order_id.products:
+ if product.state == 'new':
+ isconfirmed = False
+ if product.state == 'cancelled':
+ isconfirmed = False
+ orders_ref.write(cr,uid,[order.order_id.id],{'state':'partially'},context)
+ if isconfirmed == True:
+ orders_ref.write(cr,uid,[order.order_id.id],{'state':'confirmed'},context)
+ return {}
\ No newline at end of file
diff --git a/addons/lunch/view/lunch_validation_view.xml b/addons/lunch/wizard/lunch_validation_view.xml
similarity index 100%
rename from addons/lunch/view/lunch_validation_view.xml
rename to addons/lunch/wizard/lunch_validation_view.xml