From 95eb2c5a013586b42a01d4ce60eeec7bd1355f39 Mon Sep 17 00:00:00 2001 From: Numerigraphe - Lionel Sausin Date: Tue, 13 Dec 2011 16:17:09 +0100 Subject: [PATCH 0001/1010] [IMP] sale_order_date: use requested date when creating pickings ; improved help texts bzr revid: ls@numerigraphe.fr-20111213151709-37cm140n28lh7lee --- addons/sale_order_dates/__openerp__.py | 2 +- addons/sale_order_dates/sale_order_dates.py | 24 +++++++++++++++++---- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/addons/sale_order_dates/__openerp__.py b/addons/sale_order_dates/__openerp__.py index 72aa496b6bc..a0a546840e5 100644 --- a/addons/sale_order_dates/__openerp__.py +++ b/addons/sale_order_dates/__openerp__.py @@ -22,7 +22,7 @@ { 'name': 'Dates on Sales Order', - 'version': '1.0', + 'version': '1.1', 'category': 'Sales Management', 'complexity': "easy", 'description': """ diff --git a/addons/sale_order_dates/sale_order_dates.py b/addons/sale_order_dates/sale_order_dates.py index ceb6d48755c..05dd0170d9b 100644 --- a/addons/sale_order_dates/sale_order_dates.py +++ b/addons/sale_order_dates/sale_order_dates.py @@ -25,9 +25,11 @@ from dateutil.relativedelta import relativedelta from osv import fields, osv class sale_order_dates(osv.osv): + """Add several date fields to Sale Orders, computed or user-entered""" _inherit = 'sale.order' def _get_effective_date(self, cr, uid, ids, name, arg, context=None): + """Read the shipping date from the related packings""" res = {} dates_list = [] for order in self.browse(cr, uid, ids, context=context): @@ -39,14 +41,23 @@ class sale_order_dates(osv.osv): else: res[order.id] = False return res + + def _prepare_order_picking(self, cr, uid, order, *args): + """Take the requested date into account when creating the picking""" + picking_data = super(sale_order_dates, self)._prepare_order_picking(cr, + uid, order, *args) + picking_data['date'] = order.requested_date + return picking_data def _get_commitment_date(self, cr, uid, ids, name, arg, context=None): + """Compute the commitment date""" res = {} dates_list = [] for order in self.browse(cr, uid, ids, context=context): dates_list = [] for line in order.order_line: - dt = datetime.strptime(order.date_order, '%Y-%m-%d') + relativedelta(days=line.delay or 0.0) + dt = (datetime.strptime(order.date_order, '%Y-%m-%d') + + relativedelta(days=line.delay or 0.0) ) dt_s = dt.strftime('%Y-%m-%d') dates_list.append(dt_s) if dates_list: @@ -54,9 +65,14 @@ class sale_order_dates(osv.osv): return res _columns = { - 'commitment_date': fields.function(_get_commitment_date, store=True, type='date', string='Commitment Date', help="Date on which delivery of products is to be made."), - 'requested_date': fields.date('Requested Date', help="Date on which customer has requested for sales."), - 'effective_date': fields.function(_get_effective_date, type='date', store=True, string='Effective Date',help="Date on which picking is created."), + 'commitment_date': fields.function(_get_commitment_date, store=True, + type='date', string='Commitment Date', + help="Date by which the products must be delivered."), + 'requested_date': fields.date('Requested Date', + help="Date by which the customer has requested the products to be delivered."), + 'effective_date': fields.function(_get_effective_date, type='date', + store=True, string='Effective Date', + help="Date on which shipping is created."), } sale_order_dates() From 1baca5880909a2146c5aac9b4af916caed2d89be Mon Sep 17 00:00:00 2001 From: Numerigraphe - Lionel Sausin Date: Tue, 13 Dec 2011 18:28:59 +0100 Subject: [PATCH 0002/1010] [IMP] sale_order_dates: warn users when the requested date is before the commitment date bzr revid: ls@numerigraphe.fr-20111213172859-06vmdnpzapu6kb0h --- addons/sale_order_dates/sale_order_dates.py | 41 ++++++++++++++++++- .../sale_order_dates_view.xml | 2 +- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/addons/sale_order_dates/sale_order_dates.py b/addons/sale_order_dates/sale_order_dates.py index 05dd0170d9b..71a436aa4b4 100644 --- a/addons/sale_order_dates/sale_order_dates.py +++ b/addons/sale_order_dates/sale_order_dates.py @@ -23,6 +23,8 @@ from datetime import datetime from dateutil.relativedelta import relativedelta from osv import fields, osv +from tools.translate import _ +from tools import DEFAULT_SERVER_DATE_FORMAT class sale_order_dates(osv.osv): """Add several date fields to Sale Orders, computed or user-entered""" @@ -56,14 +58,49 @@ class sale_order_dates(osv.osv): for order in self.browse(cr, uid, ids, context=context): dates_list = [] for line in order.order_line: - dt = (datetime.strptime(order.date_order, '%Y-%m-%d') + dt = (datetime.strptime(order.date_order, + DEFAULT_SERVER_DATE_FORMAT) + relativedelta(days=line.delay or 0.0) ) - dt_s = dt.strftime('%Y-%m-%d') + dt_s = dt.strftime(DEFAULT_SERVER_DATE_FORMAT) dates_list.append(dt_s) if dates_list: res[order.id] = min(dates_list) return res + def onchange_requested_date(self, cr, uid, ids, requested_date, + commitment_date, context=None): + """Warn if the requested dates is sooner than the commitment date""" + if requested_date < commitment_date: + lang = self.pool.get("res.users").browse(cr, uid, uid, + context=context).context_lang + if lang: + lang_ids = self.pool.get('res.lang').search(cr, uid, + [('code', '=', lang)]) + date_format = self.pool.get("res.lang").browse(cr, uid, + lang_ids, context=context)[0].date_format + # Parse the dates... + req_date_formated = datetime.strptime(requested_date, + DEFAULT_SERVER_DATE_FORMAT) + com_date_formated = datetime.strptime(commitment_date, + DEFAULT_SERVER_DATE_FORMAT) + # ... and reformat them according to the user's language + req_date_formated = req_date_formated.strftime(date_format) + com_date_formated = com_date_formated.strftime(date_format) + else: + req_date_formated = requested_date + com_date_formated = commitment_date + print lang, req_date_formated, com_date_formated + return {'warning': { + 'title': _('Requested date is too soon!'), + 'message': _("The date requested by the customer (%s) is " + "sooner than the commitment date (%s). You may be " + "unable to honor the customer's request." % + (req_date_formated, com_date_formated)) + } + } + else: + return {} + _columns = { 'commitment_date': fields.function(_get_commitment_date, store=True, type='date', string='Commitment Date', diff --git a/addons/sale_order_dates/sale_order_dates_view.xml b/addons/sale_order_dates/sale_order_dates_view.xml index c6544d5238f..f1be2e414f1 100644 --- a/addons/sale_order_dates/sale_order_dates_view.xml +++ b/addons/sale_order_dates/sale_order_dates_view.xml @@ -9,7 +9,7 @@ - + From 939177c4a4a5faa6e3eef611391e06a271450b0c Mon Sep 17 00:00:00 2001 From: "Ferdinand @ Camptocamp (office-chricar)" <> Date: Wed, 14 Dec 2011 09:41:34 +0100 Subject: [PATCH 0003/1010] [IMP] sale_order_dates - enhanced tree view lp bug: https://launchpad.net/bugs/753291 fixed bzr revid: ls@numerigraphe.fr-20111214084134-b3v3tqiwjys2kk9r --- addons/sale_order_dates/sale_order_dates_view.xml | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/addons/sale_order_dates/sale_order_dates_view.xml b/addons/sale_order_dates/sale_order_dates_view.xml index f1be2e414f1..9ed13a37211 100644 --- a/addons/sale_order_dates/sale_order_dates_view.xml +++ b/addons/sale_order_dates/sale_order_dates_view.xml @@ -17,6 +17,17 @@ + + sale.order.tree.inherit5 + sale.order + tree + + + + + + + - \ No newline at end of file + From aac17e39803d5d838d214ab0deaec05660f629bb Mon Sep 17 00:00:00 2001 From: Numerigraphe - Lionel Sausin Date: Wed, 14 Dec 2011 09:43:55 +0100 Subject: [PATCH 0004/1010] [IMP] sale_order_dates: display requested date in tree view too bzr revid: ls@numerigraphe.fr-20111214084355-j69ihsirz1dq5gdr --- addons/sale_order_dates/sale_order_dates_view.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/addons/sale_order_dates/sale_order_dates_view.xml b/addons/sale_order_dates/sale_order_dates_view.xml index 9ed13a37211..c57512c6d1e 100644 --- a/addons/sale_order_dates/sale_order_dates_view.xml +++ b/addons/sale_order_dates/sale_order_dates_view.xml @@ -24,6 +24,7 @@ + From dbfc97552f75b71fafb9cd8670a232693ccd343c Mon Sep 17 00:00:00 2001 From: Numerigraphe - Lionel Sausin Date: Wed, 14 Dec 2011 15:59:47 +0100 Subject: [PATCH 0005/1010] [REF] refactor the stock move date out of the main picking creation method so we can override it bzr revid: ls@numerigraphe.fr-20111214145947-fj0z84q3w1t37003 --- addons/sale/sale.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/addons/sale/sale.py b/addons/sale/sale.py index 9f53b5cfd24..f0c981bc13a 100644 --- a/addons/sale/sale.py +++ b/addons/sale/sale.py @@ -706,6 +706,16 @@ class sale_order(osv.osv): 'property_ids': [(6, 0, [x.id for x in line.property_ids])], 'company_id': order.company_id.id, } + + def _order_line_move_date(self, cr, uid, line): + """Compute the Stock Move date for the Sale Order Line""" + date_planned = datetime.strptime(line.order_id.date_order, + DEFAULT_SERVER_DATE_FORMAT) + # XXX shouldn't this be a timedelta() instead of a relativedelta()? + date_planned += relativedelta(days=line.delay or 0.0) + date_planned -= timedelta(days=line.order_id.company_id.security_lead) + return date_planned.strftime(DEFAULT_SERVER_DATETIME_FORMAT) + def _prepare_order_line_move(self, cr, uid, order, line, picking_id, date_planned, *args): location_id = order.shop_id.warehouse_id.lot_stock_id.id @@ -778,8 +788,7 @@ class sale_order(osv.osv): if line.state == 'done': continue - date_planned = datetime.strptime(order.date_order, DEFAULT_SERVER_DATE_FORMAT) + relativedelta(days=line.delay or 0.0) - date_planned = (date_planned - timedelta(days=order.company_id.security_lead)).strftime(DEFAULT_SERVER_DATETIME_FORMAT) + date_planned = self._order_line_move_date(cr, uid, line) if line.product_id: if line.product_id.product_tmpl_id.type in ('product', 'consu'): From e83bd89ca7d2be0220d1ccd95f8cfa35d3249c8f Mon Sep 17 00:00:00 2001 From: Numerigraphe - Lionel Sausin Date: Wed, 14 Dec 2011 16:37:43 +0100 Subject: [PATCH 0006/1010] [IMP] sale_order_date: use requested date as expected date for moves instead of order date for picking; fix the onchange for requested date becoming empty; improve help texts bzr revid: ls@numerigraphe.fr-20111214153743-ggpljq1z85ggeboh --- addons/sale_order_dates/sale_order_dates.py | 44 ++++++++++++++------- 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/addons/sale_order_dates/sale_order_dates.py b/addons/sale_order_dates/sale_order_dates.py index 71a436aa4b4..2435df92671 100644 --- a/addons/sale_order_dates/sale_order_dates.py +++ b/addons/sale_order_dates/sale_order_dates.py @@ -19,19 +19,31 @@ # ############################################################################## -from datetime import datetime +from datetime import datetime, timedelta from dateutil.relativedelta import relativedelta from osv import fields, osv from tools.translate import _ -from tools import DEFAULT_SERVER_DATE_FORMAT +from tools import DEFAULT_SERVER_DATE_FORMAT, DEFAULT_SERVER_DATETIME_FORMAT class sale_order_dates(osv.osv): """Add several date fields to Sale Orders, computed or user-entered""" _inherit = 'sale.order' - + + def _order_line_move_date(self, cr, uid, line): + """Compute the expected date from the requested date, not the order date""" + order=line.order_id + if order and order.requested_date: + date_planned = datetime.strptime(order.requested_date, + DEFAULT_SERVER_DATE_FORMAT) + date_planned -= timedelta(days=order.company_id.security_lead) + return date_planned.strftime(DEFAULT_SERVER_DATETIME_FORMAT) + else: + return super(sale_order_dates, self)._order_line_move_date(cr, uid, line) + def _get_effective_date(self, cr, uid, ids, name, arg, context=None): """Read the shipping date from the related packings""" + # XXX would be better if it returned the date the picking was processed res = {} dates_list = [] for order in self.browse(cr, uid, ids, context=context): @@ -43,13 +55,6 @@ class sale_order_dates(osv.osv): else: res[order.id] = False return res - - def _prepare_order_picking(self, cr, uid, order, *args): - """Take the requested date into account when creating the picking""" - picking_data = super(sale_order_dates, self)._prepare_order_picking(cr, - uid, order, *args) - picking_data['date'] = order.requested_date - return picking_data def _get_commitment_date(self, cr, uid, ids, name, arg, context=None): """Compute the commitment date""" @@ -70,7 +75,8 @@ class sale_order_dates(osv.osv): def onchange_requested_date(self, cr, uid, ids, requested_date, commitment_date, context=None): """Warn if the requested dates is sooner than the commitment date""" - if requested_date < commitment_date: + if (requested_date and commitment_date + and requested_date < commitment_date): lang = self.pool.get("res.users").browse(cr, uid, uid, context=context).context_lang if lang: @@ -104,12 +110,22 @@ class sale_order_dates(osv.osv): _columns = { 'commitment_date': fields.function(_get_commitment_date, store=True, type='date', string='Commitment Date', - help="Date by which the products must be delivered."), + help="Date by which the products is sure to be delivered. This is " + "a date that you can promise to the customer, based on the " + "Product Lead Times."), 'requested_date': fields.date('Requested Date', - help="Date by which the customer has requested the products to be delivered."), + help="Date by which the customer has requested the items to be " + "delivered.\n" + "When this Order gets confirmed, the Delivery Order's " + "expected date will be computed based on this date and the " + "Company's Security Delay.\n" + "Leave this field empty if you want the Delivery Order to be " + "processed as soon as possible. In that case the expected " + "date will be computed using the default method: based on " + "the Product Lead Times and the Company's Security Delay."), 'effective_date': fields.function(_get_effective_date, type='date', store=True, string='Effective Date', - help="Date on which shipping is created."), + help="Date on which the first Delivery Order was created."), } sale_order_dates() From 0e12b870f7eef3022c6216eba7f747343b477ed9 Mon Sep 17 00:00:00 2001 From: Numerigraphe - Lionel Sausin Date: Wed, 14 Dec 2011 16:41:06 +0100 Subject: [PATCH 0007/1010] [IMP] sale_delivery_date: don't copy the requested date when coying sale order. bzr revid: ls@numerigraphe.fr-20111214154106-lmsrlt8w211fsgc9 --- addons/sale_order_dates/sale_order_dates.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/addons/sale_order_dates/sale_order_dates.py b/addons/sale_order_dates/sale_order_dates.py index 2435df92671..8d3b9e3b232 100644 --- a/addons/sale_order_dates/sale_order_dates.py +++ b/addons/sale_order_dates/sale_order_dates.py @@ -29,6 +29,16 @@ from tools import DEFAULT_SERVER_DATE_FORMAT, DEFAULT_SERVER_DATETIME_FORMAT class sale_order_dates(osv.osv): """Add several date fields to Sale Orders, computed or user-entered""" _inherit = 'sale.order' + + def copy(self, cr, uid, id, default=None, context=None): + """Don't copy the requested date along with the Sale Order""" + if default is None: + default = {} + else: + default = default.copy() + default['requested_date'] = False + return super(sale_order_dates, self).copy(cr, uid, id, default=default, + context=context) def _order_line_move_date(self, cr, uid, line): """Compute the expected date from the requested date, not the order date""" From 0b4bb899ce303bf71ab590f74405ee5e33948443 Mon Sep 17 00:00:00 2001 From: Numerigraphe - Lionel Sausin Date: Wed, 14 Dec 2011 16:43:17 +0100 Subject: [PATCH 0008/1010] [IMP] sale_order_dates: requested date is readonly when order state is not draft. bzr revid: ls@numerigraphe.fr-20111214154317-05xy0q2np7cqrpg0 --- addons/sale_order_dates/sale_order_dates.py | 1 + 1 file changed, 1 insertion(+) diff --git a/addons/sale_order_dates/sale_order_dates.py b/addons/sale_order_dates/sale_order_dates.py index 8d3b9e3b232..d53e05010a2 100644 --- a/addons/sale_order_dates/sale_order_dates.py +++ b/addons/sale_order_dates/sale_order_dates.py @@ -124,6 +124,7 @@ class sale_order_dates(osv.osv): "a date that you can promise to the customer, based on the " "Product Lead Times."), 'requested_date': fields.date('Requested Date', + readonly=True, states={'draft': [('readonly', False)]}, help="Date by which the customer has requested the items to be " "delivered.\n" "When this Order gets confirmed, the Delivery Order's " From f49260dc5c764e823e5416d355df62da8e38ec35 Mon Sep 17 00:00:00 2001 From: Numerigraphe - Lionel Sausin Date: Wed, 14 Dec 2011 18:09:13 +0100 Subject: [PATCH 0009/1010] [IMP] sale_order_dates: add a test file to prove the required date is taken into account when creating the delivery order; fixed onchange parameters in view; removed a debugging print statement bzr revid: ls@numerigraphe.fr-20111214170913-1iwc8tsix19db2ky --- addons/sale_order_dates/__openerp__.py | 4 +- addons/sale_order_dates/sale_order_dates.py | 1 - .../sale_order_dates_view.xml | 2 +- .../sale_order_dates/test/requested_date.yml | 83 +++++++++++++++++++ 4 files changed, 87 insertions(+), 3 deletions(-) create mode 100644 addons/sale_order_dates/test/requested_date.yml diff --git a/addons/sale_order_dates/__openerp__.py b/addons/sale_order_dates/__openerp__.py index a0a546840e5..92f7bab5db3 100644 --- a/addons/sale_order_dates/__openerp__.py +++ b/addons/sale_order_dates/__openerp__.py @@ -46,7 +46,9 @@ You can add the following additional dates to a sale order: ], 'demo_xml': [ ], - 'test': [], + 'test': [ + 'test/requested_date.yml', + ], 'installable': True, 'active': False, 'certificate' : '00867497685972962845', diff --git a/addons/sale_order_dates/sale_order_dates.py b/addons/sale_order_dates/sale_order_dates.py index d53e05010a2..11e3483672b 100644 --- a/addons/sale_order_dates/sale_order_dates.py +++ b/addons/sale_order_dates/sale_order_dates.py @@ -105,7 +105,6 @@ class sale_order_dates(osv.osv): else: req_date_formated = requested_date com_date_formated = commitment_date - print lang, req_date_formated, com_date_formated return {'warning': { 'title': _('Requested date is too soon!'), 'message': _("The date requested by the customer (%s) is " diff --git a/addons/sale_order_dates/sale_order_dates_view.xml b/addons/sale_order_dates/sale_order_dates_view.xml index c57512c6d1e..f66f9e144c7 100644 --- a/addons/sale_order_dates/sale_order_dates_view.xml +++ b/addons/sale_order_dates/sale_order_dates_view.xml @@ -9,7 +9,7 @@ - + diff --git a/addons/sale_order_dates/test/requested_date.yml b/addons/sale_order_dates/test/requested_date.yml new file mode 100644 index 00000000000..07fb131a6cf --- /dev/null +++ b/addons/sale_order_dates/test/requested_date.yml @@ -0,0 +1,83 @@ +- + + I create Demanding Corp. +- + !record {model: res.partner, id: demanding}: + name: Demanding Corp. +- + I create contact address for Demanding Corp. +- + !record {model: res.partner.address, id: demanding_address}: + partner_id: demanding + street: Requirement St. 11 + type: contact +- + I define a product category +- + !record {model: product.category, id: categ_test}: + name: Products for test +- + I define a product. +- + !record {model: product.product, id: test_product}: + categ_id: categ_test + cost_method: standard + mes_type: fixed + name: Dummy Product + procure_method: make_to_order + supply_method: buy + type: product + uom_id: product.product_uom_unit + uom_po_id: product.product_uom_unit +- + In order to test the Requested Date feature in Sale Orders in OpenERP, + I create a Sale Order having Requested Date on 2010-12-20 +- + !record {model: sale.order, id: sale_order_requested_date1}: + date_order: '2010-12-01' + requested_date: '2010-07-17' + invoice_quantity: order + name: Test_ReqDate + order_line: + - name: Dummy product + price_unit: 200 + product_uom: product.product_uom_unit + product_uom_qty: 500.0 + state: draft + delay: 7.0 + product_id: test_product + product_uos_qty: 500.0 + type: make_to_order + order_policy: manual + partner_id: demanding + partner_invoice_id: demanding_address + partner_order_id: demanding_address + partner_shipping_id: demanding_address + picking_policy: direct + pricelist_id: product.list0 + shop_id: sale.shop +- + I confirm the Sale Order. +- + !workflow { + model: sale.order, action: order_confirm, + ref: sale_order_requested_date1 + } +- + I verify that the Procurements and Stock Moves have been generated with the + correct date +- + !python {model: sale.order}: | + from datetime import datetime, timedelta + from tools import DEFAULT_SERVER_DATE_FORMAT, DEFAULT_SERVER_DATETIME_FORMAT + + so = self.browse(cr, uid, ref("sale_order_requested_date1")) + security_delay = timedelta(days=so.shop_id.company_id.security_lead) + requested_date = datetime.strptime(so.requested_date, + DEFAULT_SERVER_DATE_FORMAT) + right_date = (requested_date - security_delay).strftime( + DEFAULT_SERVER_DATETIME_FORMAT) + for line in so.order_line: + assert line.procurement_id, "No Procurement was created" + assert line.procurement_id.date_planned == right_date, "The planned date for the Procurement Order is wrong" + assert line.procurement_id.move_id.date_expected == right_date, "The expected date for the Stock Move is wrong" From ce5d6ffe1d6bd94629fcf748f60ac43a0de35178 Mon Sep 17 00:00:00 2001 From: Numerigraphe - Lionel Sausin Date: Wed, 4 Jan 2012 16:55:14 +0100 Subject: [PATCH 0010/1010] [REF] sale: use timedelta. This was suggested by O. Dony: 'datetime.timedelta and dateutil.relativedelta are equivalent for our purpose here, so you can safely change to use the same one for both lines (relativedelta supports extended use cases, such as months/years deltas)' bzr revid: ls@numerigraphe.fr-20120104155514-357k2ky3tfbkmkpu --- addons/sale/sale.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/addons/sale/sale.py b/addons/sale/sale.py index f0c981bc13a..f06a7668309 100644 --- a/addons/sale/sale.py +++ b/addons/sale/sale.py @@ -20,7 +20,6 @@ ############################################################################## from datetime import datetime, timedelta -from dateutil.relativedelta import relativedelta import time import pooler from osv import fields, osv @@ -711,8 +710,7 @@ class sale_order(osv.osv): """Compute the Stock Move date for the Sale Order Line""" date_planned = datetime.strptime(line.order_id.date_order, DEFAULT_SERVER_DATE_FORMAT) - # XXX shouldn't this be a timedelta() instead of a relativedelta()? - date_planned += relativedelta(days=line.delay or 0.0) + date_planned += timedelta(days=line.delay or 0.0) date_planned -= timedelta(days=line.order_id.company_id.security_lead) return date_planned.strftime(DEFAULT_SERVER_DATETIME_FORMAT) From 69a132dd7eda0e1ed451bba84738fac61578cd6c Mon Sep 17 00:00:00 2001 From: Numerigraphe - Lionel Sausin Date: Wed, 4 Jan 2012 16:58:11 +0100 Subject: [PATCH 0011/1010] [REF] sale_order_date: use timedelta only. bzr revid: ls@numerigraphe.fr-20120104155811-2eofblu9zclr9brn --- addons/sale_order_dates/sale_order_dates.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/addons/sale_order_dates/sale_order_dates.py b/addons/sale_order_dates/sale_order_dates.py index 11e3483672b..118d2f2d320 100644 --- a/addons/sale_order_dates/sale_order_dates.py +++ b/addons/sale_order_dates/sale_order_dates.py @@ -20,7 +20,6 @@ ############################################################################## from datetime import datetime, timedelta -from dateutil.relativedelta import relativedelta from osv import fields, osv from tools.translate import _ @@ -75,7 +74,7 @@ class sale_order_dates(osv.osv): for line in order.order_line: dt = (datetime.strptime(order.date_order, DEFAULT_SERVER_DATE_FORMAT) - + relativedelta(days=line.delay or 0.0) ) + + timedelta(days=line.delay or 0.0) ) dt_s = dt.strftime(DEFAULT_SERVER_DATE_FORMAT) dates_list.append(dt_s) if dates_list: From f2235451f014019f08b53ffa962529dc3bfb4f87 Mon Sep 17 00:00:00 2001 From: Numerigraphe - Lionel Sausin Date: Wed, 4 Jan 2012 17:02:03 +0100 Subject: [PATCH 0012/1010] [IMP] sale_order_date: simplify the on_change method as suggested by O. Dony bzr revid: ls@numerigraphe.fr-20120104160203-98b4yquttjhgirjl --- addons/sale_order_dates/sale_order_dates.py | 25 +++------------------ 1 file changed, 3 insertions(+), 22 deletions(-) diff --git a/addons/sale_order_dates/sale_order_dates.py b/addons/sale_order_dates/sale_order_dates.py index 118d2f2d320..7b00d55267f 100644 --- a/addons/sale_order_dates/sale_order_dates.py +++ b/addons/sale_order_dates/sale_order_dates.py @@ -86,30 +86,11 @@ class sale_order_dates(osv.osv): """Warn if the requested dates is sooner than the commitment date""" if (requested_date and commitment_date and requested_date < commitment_date): - lang = self.pool.get("res.users").browse(cr, uid, uid, - context=context).context_lang - if lang: - lang_ids = self.pool.get('res.lang').search(cr, uid, - [('code', '=', lang)]) - date_format = self.pool.get("res.lang").browse(cr, uid, - lang_ids, context=context)[0].date_format - # Parse the dates... - req_date_formated = datetime.strptime(requested_date, - DEFAULT_SERVER_DATE_FORMAT) - com_date_formated = datetime.strptime(commitment_date, - DEFAULT_SERVER_DATE_FORMAT) - # ... and reformat them according to the user's language - req_date_formated = req_date_formated.strftime(date_format) - com_date_formated = com_date_formated.strftime(date_format) - else: - req_date_formated = requested_date - com_date_formated = commitment_date return {'warning': { 'title': _('Requested date is too soon!'), - 'message': _("The date requested by the customer (%s) is " - "sooner than the commitment date (%s). You may be " - "unable to honor the customer's request." % - (req_date_formated, com_date_formated)) + 'message': _("The date requested by the customer is " + "sooner than the commitment date. You may be " + "unable to honor the customer's request.") } } else: From 6b267821a54617a3b35f0b379990c5b375f54e84 Mon Sep 17 00:00:00 2001 From: Numerigraphe - Lionel Sausin Date: Wed, 4 Jan 2012 17:58:40 +0100 Subject: [PATCH 0013/1010] [FIX] sale_order_dates: allow the context to be passed to _order_line_move_date(). bzr revid: ls@numerigraphe.fr-20120104165840-f97w6mbdwcku6zpd --- addons/sale_order_dates/sale_order_dates.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/sale_order_dates/sale_order_dates.py b/addons/sale_order_dates/sale_order_dates.py index 7b00d55267f..5a48f1152b1 100644 --- a/addons/sale_order_dates/sale_order_dates.py +++ b/addons/sale_order_dates/sale_order_dates.py @@ -39,7 +39,7 @@ class sale_order_dates(osv.osv): return super(sale_order_dates, self).copy(cr, uid, id, default=default, context=context) - def _order_line_move_date(self, cr, uid, line): + def _order_line_move_date(self, cr, uid, line, context=None): """Compute the expected date from the requested date, not the order date""" order=line.order_id if order and order.requested_date: From 1146becd4dd76bae4a32e3c1c6fc5bb8380bda49 Mon Sep 17 00:00:00 2001 From: Numerigraphe - Lionel Sausin Date: Wed, 4 Jan 2012 18:05:58 +0100 Subject: [PATCH 0014/1010] [IMP] sale_order_date: simplify the test file. This was suggested by O. Dony: 'FYI due to the proliferation of yaml tests we're trying to enforce a stricter policy on the size of these tests, to make them easier to maintain. Therefore we ask developer to keep them as minimalist as possible, and not to introduce master data records (companies, partners, products, boms, etc.), and re-use the demo master data instead.' bzr revid: ls@numerigraphe.fr-20120104170558-td1geevul0ivb5s9 --- .../sale_order_dates/test/requested_date.yml | 62 ++----------------- 1 file changed, 5 insertions(+), 57 deletions(-) diff --git a/addons/sale_order_dates/test/requested_date.yml b/addons/sale_order_dates/test/requested_date.yml index 07fb131a6cf..cdeec445409 100644 --- a/addons/sale_order_dates/test/requested_date.yml +++ b/addons/sale_order_dates/test/requested_date.yml @@ -1,67 +1,15 @@ -- - - I create Demanding Corp. -- - !record {model: res.partner, id: demanding}: - name: Demanding Corp. -- - I create contact address for Demanding Corp. -- - !record {model: res.partner.address, id: demanding_address}: - partner_id: demanding - street: Requirement St. 11 - type: contact -- - I define a product category -- - !record {model: product.category, id: categ_test}: - name: Products for test -- - I define a product. -- - !record {model: product.product, id: test_product}: - categ_id: categ_test - cost_method: standard - mes_type: fixed - name: Dummy Product - procure_method: make_to_order - supply_method: buy - type: product - uom_id: product.product_uom_unit - uom_po_id: product.product_uom_unit - In order to test the Requested Date feature in Sale Orders in OpenERP, - I create a Sale Order having Requested Date on 2010-12-20 + I update a demo Sale Order with Requested Date on 2010-12-17 - - !record {model: sale.order, id: sale_order_requested_date1}: - date_order: '2010-12-01' - requested_date: '2010-07-17' - invoice_quantity: order - name: Test_ReqDate - order_line: - - name: Dummy product - price_unit: 200 - product_uom: product.product_uom_unit - product_uom_qty: 500.0 - state: draft - delay: 7.0 - product_id: test_product - product_uos_qty: 500.0 - type: make_to_order - order_policy: manual - partner_id: demanding - partner_invoice_id: demanding_address - partner_order_id: demanding_address - partner_shipping_id: demanding_address - picking_policy: direct - pricelist_id: product.list0 - shop_id: sale.shop + !python {model: sale.order}: | + so = self.write(cr, uid, ref("sale.order"), {'requested_date': '2010-07-12'}) - I confirm the Sale Order. - !workflow { model: sale.order, action: order_confirm, - ref: sale_order_requested_date1 + ref: sale.order } - I verify that the Procurements and Stock Moves have been generated with the @@ -71,7 +19,7 @@ from datetime import datetime, timedelta from tools import DEFAULT_SERVER_DATE_FORMAT, DEFAULT_SERVER_DATETIME_FORMAT - so = self.browse(cr, uid, ref("sale_order_requested_date1")) + so = self.browse(cr, uid, ref("sale.order")) security_delay = timedelta(days=so.shop_id.company_id.security_lead) requested_date = datetime.strptime(so.requested_date, DEFAULT_SERVER_DATE_FORMAT) From a5089441745ef2263b62bfeb2ba9921237d3fed5 Mon Sep 17 00:00:00 2001 From: Numerigraphe - Lionel Sausin Date: Thu, 5 Jan 2012 10:42:45 +0100 Subject: [PATCH 0015/1010] [IMP] module description for sale_order_date bzr revid: ls@numerigraphe.fr-20120105094245-2ovj0mkhz4clcgo0 --- addons/sale_order_dates/__openerp__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/sale_order_dates/__openerp__.py b/addons/sale_order_dates/__openerp__.py index 92f7bab5db3..605e100b8f5 100644 --- a/addons/sale_order_dates/__openerp__.py +++ b/addons/sale_order_dates/__openerp__.py @@ -30,7 +30,7 @@ Add additional date information to the sales order. =================================================== You can add the following additional dates to a sale order: - * Requested Date + * Requested Date (will be used as the expected date on pickings) * Commitment Date * Effective Date """, From f6d4e1451b56434d9b4abcd64dd6d865ec8a2b29 Mon Sep 17 00:00:00 2001 From: Numerigraphe - Lionel Sausin Date: Thu, 5 Jan 2012 10:53:51 +0100 Subject: [PATCH 0016/1010] [IMP] updated translation for sale_order_dates bzr revid: ls@numerigraphe.fr-20120105095351-y40njq7zpu70mc6a --- addons/sale_order_dates/i18n/es_MX.po.moved | 71 ------------------- addons/sale_order_dates/i18n/fr.po | 69 +++++++++--------- .../i18n/sale_order_dates.pot | 32 ++++++--- 3 files changed, 58 insertions(+), 114 deletions(-) delete mode 100644 addons/sale_order_dates/i18n/es_MX.po.moved diff --git a/addons/sale_order_dates/i18n/es_MX.po.moved b/addons/sale_order_dates/i18n/es_MX.po.moved deleted file mode 100644 index b682cb925d7..00000000000 --- a/addons/sale_order_dates/i18n/es_MX.po.moved +++ /dev/null @@ -1,71 +0,0 @@ -# Translation of OpenERP Server. -# This file contains the translation of the following modules: -# * sale_order_dates -# -msgid "" -msgstr "" -"Project-Id-Version: OpenERP Server 6.0.2\n" -"Report-Msgid-Bugs-To: support@openerp.com\n" -"POT-Creation-Date: 2011-07-05 16:02+0000\n" -"PO-Revision-Date: 2011-07-05 16:02+0000\n" -"Last-Translator: <>\n" -"Language-Team: \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: \n" -"Plural-Forms: \n" - -#. module: sale_order_dates -#: sql_constraint:sale.order:0 -msgid "Order Reference must be unique !" -msgstr "¡La referencia del pedido debe ser única!" - -#. module: sale_order_dates -#: help:sale.order,requested_date:0 -msgid "Date on which customer has requested for sales." -msgstr "Fecha en que el cliente ha solicitado la venta." - -#. module: sale_order_dates -#: field:sale.order,commitment_date:0 -msgid "Commitment Date" -msgstr "Fecha compromiso" - -#. module: sale_order_dates -#: field:sale.order,effective_date:0 -msgid "Effective Date" -msgstr "Fecha efectiva" - -#. module: sale_order_dates -#: model:ir.module.module,shortdesc:sale_order_dates.module_meta_information -msgid "Sales Order Dates" -msgstr "Fechas en pedidos de venta" - -#. module: sale_order_dates -#: help:sale.order,effective_date:0 -msgid "Date on which picking is created." -msgstr "Fecha en que la orden ha sido creada." - -#. module: sale_order_dates -#: field:sale.order,requested_date:0 -msgid "Requested Date" -msgstr "Fecha solicitud" - -#. module: sale_order_dates -#: model:ir.model,name:sale_order_dates.model_sale_order -msgid "Sales Order" -msgstr "Pedido de venta" - -#. module: sale_order_dates -#: model:ir.module.module,description:sale_order_dates.module_meta_information -msgid "\n" -"Add commitment, requested and effective dates on the sales order.\n" -"" -msgstr "\n" -"Añade las fechas de compromiso, solicitada y efectiva en el pedido de venta.\n" -"" - -#. module: sale_order_dates -#: help:sale.order,commitment_date:0 -msgid "Date on which delivery of products is to be made." -msgstr "Fecha en que la entrega de productos se va a realizar." - diff --git a/addons/sale_order_dates/i18n/fr.po b/addons/sale_order_dates/i18n/fr.po index 9a71e524ab4..fc2ff669a67 100644 --- a/addons/sale_order_dates/i18n/fr.po +++ b/addons/sale_order_dates/i18n/fr.po @@ -4,43 +4,57 @@ # msgid "" msgstr "" -"Project-Id-Version: OpenERP Server 6.0dev\n" -"Report-Msgid-Bugs-To: support@openerp.com\n" -"POT-Creation-Date: 2011-12-22 18:46+0000\n" -"PO-Revision-Date: 2011-01-13 12:19+0000\n" -"Last-Translator: Maxime Chambreuil (http://www.savoirfairelinux.com) " -"\n" +"Project-Id-Version: OpenERP Server 6.1beta\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2012-01-05 09:45+0000\n" +"PO-Revision-Date: 2012-01-05 09:45+0000\n" +"Last-Translator: <>\n" "Language-Team: \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" -"X-Launchpad-Export-Date: 2011-12-23 07:24+0000\n" -"X-Generator: Launchpad (build 14560)\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" #. module: sale_order_dates #: sql_constraint:sale.order:0 msgid "Order Reference must be unique per Company!" -msgstr "" - -#. module: sale_order_dates -#: help:sale.order,requested_date:0 -msgid "Date on which customer has requested for sales." -msgstr "Date à laquelle le client a fait une demande d'achat." +msgstr "La référence de commande doit être unique dans la société !" #. module: sale_order_dates #: field:sale.order,commitment_date:0 msgid "Commitment Date" msgstr "Date d'engagement" +#. module: sale_order_dates +#: help:sale.order,effective_date:0 +msgid "Date on which the first Delivery Order was created." +msgstr "Date de la première livraison." + +#. module: sale_order_dates +#: code:addons/sale_order_dates/sale_order_dates.py:91 +#, python-format +msgid "The date requested by the customer is sooner than the commitment date. You may be unable to honor the customer's request." +msgstr "La date demandée par le client est avant la date d'engagement : il vous sera peut-être impossible de respecter la demande du client." + +#. module: sale_order_dates +#: help:sale.order,requested_date:0 +msgid "Date by which the customer has requested the items to be delivered.\n" +"When this Order gets confirmed, the Delivery Order's expected date will be computed based on this date and the Company's Security Delay.\n" +"Leave this field empty if you want the Delivery Order to be processed as soon as possible. In that case the expected date will be computed using the default method: based on the Product Lead Times and the Company's Security Delay." +msgstr "Date à laquelle le client souhaite que les produits soient livrés.\n" +"Lorsque la commande sera validée, la date prévue pour le bon de livraison sera calculée en fonction de cette date et du délai de sécurité de la société.\n" +"Laissez ce champ vide si vous souhaitez que la livraison soit effectuée dès que possible. Dans ce cas la date prévue sera calculée selon la méthode par défaut : selon les délais de livraison des produits et le délai de sécurité de la société." + #. module: sale_order_dates #: field:sale.order,effective_date:0 msgid "Effective Date" msgstr "Date effective" #. module: sale_order_dates -#: help:sale.order,effective_date:0 -msgid "Date on which picking is created." -msgstr "Date à laquelle le prélèvement a été créé." +#: code:addons/sale_order_dates/sale_order_dates.py:90 +#, python-format +msgid "Requested date is too soon!" +msgstr "La date demandée est trop tôt !" #. module: sale_order_dates #: field:sale.order,requested_date:0 @@ -50,23 +64,10 @@ msgstr "Date demandée" #. module: sale_order_dates #: model:ir.model,name:sale_order_dates.model_sale_order msgid "Sales Order" -msgstr "Commande de ventes" +msgstr "Commande de vente" #. module: sale_order_dates #: help:sale.order,commitment_date:0 -msgid "Date on which delivery of products is to be made." -msgstr "Date à laquelle la livraison des produits doit être faite." +msgid "Date by which the products is sure to be delivered. This is a date that you can promise to the customer, based on the Product Lead Times." +msgstr "Date à laquelle on est certain que le produit sera livré. C'est une date que vous promettez de tenir au client, en fonction des délais de livraison des produits." -#~ msgid "Sales Order Dates" -#~ msgstr "Dates de commande de ventes" - -#~ msgid "" -#~ "\n" -#~ "Add commitment, requested and effective dates on the sales order.\n" -#~ msgstr "" -#~ "\n" -#~ "Ajoute les dates d'engagement, demandée et effective sur le bon de " -#~ "commande.\n" - -#~ msgid "Order Reference must be unique !" -#~ msgstr "La référence de la commande doit être unique !" diff --git a/addons/sale_order_dates/i18n/sale_order_dates.pot b/addons/sale_order_dates/i18n/sale_order_dates.pot index 57ededdfc3e..ebe9c6799c9 100644 --- a/addons/sale_order_dates/i18n/sale_order_dates.pot +++ b/addons/sale_order_dates/i18n/sale_order_dates.pot @@ -6,8 +6,8 @@ msgid "" msgstr "" "Project-Id-Version: OpenERP Server 6.1beta\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2011-12-22 18:46+0000\n" -"PO-Revision-Date: 2011-12-22 18:46+0000\n" +"POT-Creation-Date: 2012-01-05 09:44+0000\n" +"PO-Revision-Date: 2012-01-05 09:44+0000\n" "Last-Translator: <>\n" "Language-Team: \n" "MIME-Version: 1.0\n" @@ -21,13 +21,26 @@ msgid "Order Reference must be unique per Company!" msgstr "" #. module: sale_order_dates -#: help:sale.order,requested_date:0 -msgid "Date on which customer has requested for sales." +#: field:sale.order,commitment_date:0 +msgid "Commitment Date" msgstr "" #. module: sale_order_dates -#: field:sale.order,commitment_date:0 -msgid "Commitment Date" +#: help:sale.order,effective_date:0 +msgid "Date on which the first Delivery Order was created." +msgstr "" + +#. module: sale_order_dates +#: code:addons/sale_order_dates/sale_order_dates.py:91 +#, python-format +msgid "The date requested by the customer is sooner than the commitment date. You may be unable to honor the customer's request." +msgstr "" + +#. module: sale_order_dates +#: help:sale.order,requested_date:0 +msgid "Date by which the customer has requested the items to be delivered.\n" +"When this Order gets confirmed, the Delivery Order's expected date will be computed based on this date and the Company's Security Delay.\n" +"Leave this field empty if you want the Delivery Order to be processed as soon as possible. In that case the expected date will be computed using the default method: based on the Product Lead Times and the Company's Security Delay." msgstr "" #. module: sale_order_dates @@ -36,8 +49,9 @@ msgid "Effective Date" msgstr "" #. module: sale_order_dates -#: help:sale.order,effective_date:0 -msgid "Date on which picking is created." +#: code:addons/sale_order_dates/sale_order_dates.py:90 +#, python-format +msgid "Requested date is too soon!" msgstr "" #. module: sale_order_dates @@ -52,6 +66,6 @@ msgstr "" #. module: sale_order_dates #: help:sale.order,commitment_date:0 -msgid "Date on which delivery of products is to be made." +msgid "Date by which the products is sure to be delivered. This is a date that you can promise to the customer, based on the Product Lead Times." msgstr "" From bbf6810715560daa2c4e07523ad8f0f8f627fc62 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Fri, 8 Feb 2013 17:15:04 +0100 Subject: [PATCH 0017/1010] [IMP] survey: change kanban, remove Matrix of Drop-down Menus bzr revid: chm@openerp.com-20130208161504-9zfiwisrhe8y0xbn --- .../survey/report/survey_analysis_report.py | 48 -------------- .../survey/report/survey_browse_response.py | 10 +-- addons/survey/report/survey_form.py | 7 +- addons/survey/survey.py | 33 ++-------- addons/survey/survey_view.xml | 66 ++++++++----------- addons/survey/wizard/survey_answer.py | 21 +----- 6 files changed, 39 insertions(+), 146 deletions(-) diff --git a/addons/survey/report/survey_analysis_report.py b/addons/survey/report/survey_analysis_report.py index b4e7765346c..f7f08df3d65 100644 --- a/addons/survey/report/survey_analysis_report.py +++ b/addons/survey/report/survey_analysis_report.py @@ -330,54 +330,6 @@ class survey_analysis(report_rml): """ + tools.ustr(res_count) + """""" rml += """""" - elif que.type in['matrix_of_drop_down_menus']: - for column in que.column_heading_ids: - rml += """ - """ + to_xml(tools.ustr(column.title)) + """""" - menu_choices = column.menu_choice.split('\n') - cols_widhts = [] - cols_widhts.append(200) - for col in range(0, len(menu_choices) + 1): - cols_widhts.append(float(300 / (len(menu_choices) + 1))) - colWidths = ",".join(map(tools.ustr, cols_widhts)) - rml += """ - """ - - for menu in menu_choices: - rml += """""" + to_xml(tools.ustr(menu)) + """""" - rml += """Answer Count""" - cr.execute("select count(id), sra.answer_id from survey_response_answer sra \ - where sra.column_id='%s' group by sra.answer_id ", (column.id,)) - res_count = cr.dictfetchall() - cr.execute("select count(sra.id),sra.value_choice, sra.answer_id, sra.column_id from survey_response_answer sra \ - where sra.column_id='%s' group by sra.value_choice ,sra.answer_id, sra.column_id", (column.id,)) - calc_percantage = cr.dictfetchall() - - for ans in que.answer_choice_ids: - rml += """""" + to_xml(tools.ustr(ans.answer)) + """""" - for mat_col in range(0, len(menu_choices)): - calc = 0 - response = 0 - for res in res_count: - if res['answer_id'] == ans.id: response = res['count'] - for per in calc_percantage: - if ans.id == per['answer_id'] and menu_choices[mat_col] == per['value_choice']: - calc = per['count'] - percantage = 0.00 - - if calc and response: - percantage = round((float(calc)* 100) / response,2) - if calc: - rml += """""" +tools.ustr(percantage)+"% (" + tools.ustr(calc) + """)""" - else: - rml += """""" +tools.ustr(percantage)+"% (" + tools.ustr(calc) + """)""" - - response = 0 - for res in res_count: - if res['answer_id'] == ans.id: response = res['count'] - rml += """""" + tools.ustr(response) + """""" - rml += """""" - elif que.type in['numerical_textboxes']: rml += """ diff --git a/addons/survey/report/survey_browse_response.py b/addons/survey/report/survey_browse_response.py index f910140727d..507d7275c17 100644 --- a/addons/survey/report/survey_browse_response.py +++ b/addons/survey/report/survey_browse_response.py @@ -423,7 +423,7 @@ class survey_browse_response(report_rml): No Answer """ - elif que.type in ['matrix_of_choices_only_one_ans','matrix_of_choices_only_multi_ans', 'rating_scale', 'matrix_of_drop_down_menus']: + elif que.type in ['matrix_of_choices_only_one_ans','matrix_of_choices_only_multi_ans', 'rating_scale']: if len(answer) and answer[0].state == "done": if que.type in ['matrix_of_choices_only_one_ans', 'rating_scale'] and que.comment_column: pass @@ -478,9 +478,7 @@ class survey_browse_response(report_rml): for res_ans in answer[0].response_answer_ids: if res_ans.answer_id.id == ans.id and res_ans.column_id.id == matrix_ans[mat_col][0]: comment_value = to_xml(tools.ustr(res_ans.comment_field)) - if que.type in ['matrix_of_drop_down_menus']: - value = """""" + to_xml(tools.ustr(res_ans.value_choice)) + """""" - elif que.type in ['matrix_of_choices_only_one_ans', 'rating_scale']: + if que.type in ['matrix_of_choices_only_one_ans', 'rating_scale']: value = """ @@ -495,9 +493,7 @@ class survey_browse_response(report_rml): """ break else: - if que.type in ['matrix_of_drop_down_menus']: - value = """""" - elif que.type in ['matrix_of_choices_only_one_ans','rating_scale']: + if que.type in ['matrix_of_choices_only_one_ans','rating_scale']: value = """ """ diff --git a/addons/survey/report/survey_form.py b/addons/survey/report/survey_form.py index 8375df6acaf..e6c50947327 100644 --- a/addons/survey/report/survey_form.py +++ b/addons/survey/report/survey_form.py @@ -244,7 +244,7 @@ class survey_form(report_rml): rml += """ """ - elif que.type in ['matrix_of_choices_only_one_ans','rating_scale','matrix_of_choices_only_multi_ans','matrix_of_drop_down_menus']: + elif que.type in ['matrix_of_choices_only_one_ans','rating_scale','matrix_of_choices_only_multi_ans']: if len(que.column_heading_ids): cols_widhts.append(float(_tbl_widths.replace('cm',''))/float(2.0)) for col in que.column_heading_ids: @@ -290,10 +290,7 @@ class survey_form(report_rml): rec_width = float((sum-tmp)*10+100) value = "" - if que.type in ['matrix_of_drop_down_menus']: - value = """ - """ - elif que.type in ['matrix_of_choices_only_one_ans','rating_scale']: + if que.type in ['matrix_of_choices_only_one_ans','rating_scale']: value = """ """ else: diff --git a/addons/survey/survey.py b/addons/survey/survey.py index 241b9739016..be9003c805d 100644 --- a/addons/survey/survey.py +++ b/addons/survey/survey.py @@ -303,7 +303,6 @@ class survey_question(osv.osv): ('multiple_choice_multiple_ans','Multiple Choice (Multiple Answer)'), ('matrix_of_choices_only_one_ans','Matrix of Choices (Only One Answers Per Row)'), ('matrix_of_choices_only_multi_ans','Matrix of Choices (Multiple Answers Per Row)'), - ('matrix_of_drop_down_menus','Matrix of Drop-down Menus'), ('rating_scale','Rating Scale'),('single_textbox','Single Textbox'), ('multiple_textboxes','Multiple Textboxes'), ('multiple_textboxes_diff_type','Multiple Textboxes With Different Type'), @@ -388,10 +387,6 @@ class survey_question(osv.osv): val.update({'in_visible_rating_weight':False, 'in_visible_menu_choice':True}) return {'value': val} - elif type in ['matrix_of_drop_down_menus']: - val.update({'in_visible_rating_weight':True, 'in_visible_menu_choice':False}) - return {'value': val} - elif type in ['single_textbox']: val.update({'in_visible_rating_weight':True, 'in_visible_menu_choice':True}) return {'value': val} @@ -418,8 +413,7 @@ class survey_question(osv.osv): else: que_type = question['type'] - if que_type in ['matrix_of_choices_only_one_ans', 'matrix_of_choices_only_multi_ans',\ - 'matrix_of_drop_down_menus', 'rating_scale']: + if que_type in ['matrix_of_choices_only_one_ans', 'matrix_of_choices_only_multi_ans', 'rating_scale']: if not col_len: raise osv.except_osv(_('Warning!'),_('You must enter one or more column headings for question "%s" of page %s.') % (question['question'], question['page_id'][1])) ans_len = len(question['answer_choice_ids']) @@ -442,8 +436,8 @@ class survey_question(osv.osv): req_type = question['required_type'] if que_type in ['multiple_choice_multiple_ans','matrix_of_choices_only_one_ans', \ - 'matrix_of_choices_only_multi_ans', 'matrix_of_drop_down_menus',\ - 'rating_scale','multiple_textboxes','numerical_textboxes','date','date_and_time']: + 'matrix_of_choices_only_multi_ans', 'rating_scale','multiple_textboxes', \ + 'numerical_textboxes','date','date_and_time']: if req_type in ['at least', 'at most', 'exactly']: if vals.has_key('req_ans'): if not vals['req_ans'] or vals['req_ans'] > ans_len: @@ -487,16 +481,6 @@ class survey_question(osv.osv): raise osv.except_osv(_('Warning!'),_("Maximum Required Answer is greater \ than Minimum Required Answer")) - if question['type'] == 'matrix_of_drop_down_menus' and vals.has_key('column_heading_ids'): - for col in vals['column_heading_ids']: - if not col[2] or not col[2].has_key('menu_choice') or not col[2]['menu_choice']: - raise osv.except_osv(_('Warning!'),_("You must enter one or more menu choices\ - in column heading.")) - elif not col[2] or not col[2].has_key('menu_choice') or\ - col[2]['menu_choice'].strip() == '': - raise osv.except_osv(_('Warning!'),_("You must enter one or more menu \ - choices in column heading (white spaces not allowed).")) - return super(survey_question, self).write(cr, uid, ids, vals, context=context) def create(self, cr, uid, vals, context=None): @@ -508,10 +492,10 @@ class survey_question(osv.osv): raise osv.except_osv(_('Warning!'),_('You must enter one or more answers for question "%s" of page %s .') % (vals['question'], page)) if vals.has_key('column_heading_ids') and not len(vals['column_heading_ids']): - if vals.has_key('type') and vals['type'] in ['matrix_of_choices_only_one_ans', 'matrix_of_choices_only_multi_ans', 'matrix_of_drop_down_menus', 'rating_scale']: + if vals.has_key('type') and vals['type'] in ['matrix_of_choices_only_one_ans', 'matrix_of_choices_only_multi_ans', 'rating_scale']: raise osv.except_osv(_('Warning!'),_('You must enter one or more column headings for question "%s" of page %s.')% (vals['question'], page)) - if vals['type'] in ['multiple_choice_multiple_ans','matrix_of_choices_only_one_ans', 'matrix_of_choices_only_multi_ans', 'matrix_of_drop_down_menus', 'rating_scale','multiple_textboxes','numerical_textboxes','date','date_and_time']: + if vals['type'] in ['multiple_choice_multiple_ans','matrix_of_choices_only_one_ans', 'matrix_of_choices_only_multi_ans', 'rating_scale','multiple_textboxes','numerical_textboxes','date','date_and_time']: if vals.has_key('is_require_answer') and vals.has_key('required_type') and vals['required_type'] in ['at least', 'at most', 'exactly']: if vals.has_key('answer_choice_ids') and vals['req_ans'] > len(vals['answer_choice_ids']) or not vals['req_ans']: raise osv.except_osv(_('Warning!'),_("#Required Answer you entered is greater than the number of answer. Please use a number that is smaller than %d.") % (len(vals['answer_choice_ids'])+1)) @@ -526,13 +510,6 @@ class survey_question(osv.osv): if maximum_ans <= minimum_ans: raise osv.except_osv(_('Warning!'),_("Maximum Required Answer is greater than Minimum Required Answer.")) - if vals['type'] == 'matrix_of_drop_down_menus': - for col in vals['column_heading_ids']: - if not col[2] or not col[2].has_key('menu_choice') or not col[2]['menu_choice']: - raise osv.except_osv(_('Warning!'),_("You must enter one or more menu choices in column heading.")) - elif not col[2] or not col[2].has_key('menu_choice') or col[2]['menu_choice'].strip() == '': - raise osv.except_osv(_('Warning!'),_("You must enter one or more menu choices in column heading (white spaces not allowed).")) - res = super(survey_question, self).create(cr, uid, vals, context) return res diff --git a/addons/survey/survey_view.xml b/addons/survey/survey_view.xml index 7da3f26fc2f..639b5aec649 100644 --- a/addons/survey/survey_view.xml +++ b/addons/survey/survey_view.xml @@ -82,11 +82,11 @@ - + - + @@ -94,7 +94,7 @@ - + @@ -161,12 +161,12 @@ - + - + @@ -318,7 +318,12 @@ /
- Answer Survey + @@ -395,11 +400,11 @@ - + - + @@ -407,7 +412,7 @@ - + @@ -473,12 +478,12 @@ - + - + @@ -603,12 +608,12 @@ - + - + @@ -616,7 +621,7 @@ - + @@ -683,12 +688,12 @@ - + - + @@ -780,12 +785,12 @@ - + - + @@ -793,7 +798,7 @@ - + @@ -860,12 +865,12 @@ - + - + @@ -1037,25 +1042,6 @@ Survey Response Answer --> - - survey_response_answer_form - survey.response.answer - -
- - - - - -
-
- survey_response_answer_tree survey.response.answer diff --git a/addons/survey/wizard/survey_answer.py b/addons/survey/wizard/survey_answer.py index d935eb92ade..6c3604e22c3 100644 --- a/addons/survey/wizard/survey_answer.py +++ b/addons/survey/wizard/survey_answer.py @@ -257,21 +257,6 @@ class survey_question_wiz(osv.osv_memory): etree.SubElement(xml_group, 'field', {'readonly' :str(readonly), 'name': tools.ustr(que.id) + "_" + tools.ustr(row.id) + "_" + tools.ustr(col.id), 'nolabel':"1"}) fields[tools.ustr(que.id) + "_" + tools.ustr(row.id) + "_" + tools.ustr(col.id)] = {'type':'boolean', 'string': col.title} - elif que_rec.type == 'matrix_of_drop_down_menus': - xml_group = etree.SubElement(xml_group, 'group', {'col': str(len(que_rec.column_heading_ids) + 1), 'colspan': '4'}) - etree.SubElement(xml_group, 'separator', {'string': '.','colspan': '1'}) - for col in que_rec.column_heading_ids: - etree.SubElement(xml_group, 'separator', {'string': tools.ustr(col.title),'colspan': '1'}) - for row in ans_ids: - etree.SubElement(xml_group, 'label', {'string': to_xml(tools.ustr(row.answer))+' :-', 'align': '0.0'}) - for col in que_rec.column_heading_ids: - selection = [] - if col.menu_choice: - for item in col.menu_choice.split('\n'): - if item and not item.strip() == '': selection.append((item ,item)) - etree.SubElement(xml_group, 'field', {'readonly' :str(readonly), 'name': tools.ustr(que.id) + "_" + tools.ustr(row.id) + "_" + tools.ustr(col.id),'nolabel':'1'}) - fields[tools.ustr(que.id) + "_" + tools.ustr(row.id) + "_" + tools.ustr(col.id)] = {'type':'selection', 'string': col.title, 'selection':selection} - elif que_rec.type == 'multiple_textboxes': xml_group = etree.SubElement(xml_group, 'group', {'col': '4', 'colspan': '4'}) type = "char" @@ -348,7 +333,7 @@ class survey_question_wiz(osv.osv_memory): if item and not item.strip() == '': selection.append((item ,item)) fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"] = {'type':'selection', 'selection' : selection, 'string':ans.answer} - if que_rec.type in ['multiple_choice_only_one_ans', 'multiple_choice_multiple_ans', 'matrix_of_choices_only_one_ans', 'matrix_of_choices_only_multi_ans', 'matrix_of_drop_down_menus', 'rating_scale'] and que_rec.is_comment_require: + if que_rec.type in ['multiple_choice_only_one_ans', 'multiple_choice_multiple_ans', 'matrix_of_choices_only_one_ans', 'matrix_of_choices_only_multi_ans', 'rating_scale'] and que_rec.is_comment_require: if que_rec.type in ['multiple_choice_only_one_ans', 'multiple_choice_multiple_ans'] and que_rec.comment_field_type in ['char','text'] and que_rec.make_comment_field: etree.SubElement(xml_group, 'field', {'readonly' :str(readonly), 'name': tools.ustr(que.id) + "_otherfield", 'colspan':"4"}) fields[tools.ustr(que.id) + "_otherfield"] = {'type':'boolean', 'string':que_rec.comment_label, 'views':{}} @@ -807,7 +792,7 @@ class survey_question_wiz(osv.osv_memory): sur_name_read['store_ans'].pop(res) raise osv.except_osv(_('Warning!'), "'" + que_rec['question'] + "' " + tools.ustr(que_rec['numeric_required_sum_err_msg'])) - if que_rec['type'] in ['multiple_textboxes_diff_type', 'multiple_choice_multiple_ans','matrix_of_choices_only_one_ans','matrix_of_choices_only_multi_ans','matrix_of_drop_down_menus','rating_scale','multiple_textboxes','numerical_textboxes','date','date_and_time'] and que_rec['is_require_answer']: + if que_rec['type'] in ['multiple_textboxes_diff_type', 'multiple_choice_multiple_ans','matrix_of_choices_only_one_ans','matrix_of_choices_only_multi_ans','rating_scale','multiple_textboxes','numerical_textboxes','date','date_and_time'] and que_rec['is_require_answer']: if matrix_list: if (que_rec['required_type'] == 'all' and len(list(set(matrix_list))) < len(que_rec['answer_choice_ids'])) or \ (que_rec['required_type'] == 'at least' and len(list(set(matrix_list))) < que_rec['req_ans']) or \ @@ -997,7 +982,7 @@ class survey_question_wiz(osv.osv_memory): if not select_count: resp_obj.write(cr, uid, update, {'state': 'skip'}) - if que_rec['type'] in ['multiple_textboxes_diff_type','multiple_choice_multiple_ans','matrix_of_choices_only_one_ans','matrix_of_choices_only_multi_ans','matrix_of_drop_down_menus','rating_scale','multiple_textboxes','numerical_textboxes','date','date_and_time'] and que_rec['is_require_answer']: + if que_rec['type'] in ['multiple_textboxes_diff_type','multiple_choice_multiple_ans','matrix_of_choices_only_one_ans','matrix_of_choices_only_multi_ans','rating_scale','multiple_textboxes','numerical_textboxes','date','date_and_time'] and que_rec['is_require_answer']: if matrix_list: if (que_rec['required_type'] == 'all' and len(list(set(matrix_list))) < len(que_rec['answer_choice_ids'])) or \ (que_rec['required_type'] == 'at least' and len(list(set(matrix_list))) < que_rec['req_ans']) or \ From 1aa2d1178c7eb1b0bbf4fcae042db58dc68df89d Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Mon, 11 Feb 2013 09:26:13 +0100 Subject: [PATCH 0018/1010] [IMP] survey bzr revid: chm@openerp.com-20130211082613-k04ptw8jbt602xzb --- addons/survey/survey_view.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/survey/survey_view.xml b/addons/survey/survey_view.xml index 639b5aec649..53900b31df5 100644 --- a/addons/survey/survey_view.xml +++ b/addons/survey/survey_view.xml @@ -319,12 +319,12 @@
- From 9bd0f29fe1a426ee347d42f284a148c92ff6a434 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Tue, 12 Feb 2013 11:13:28 +0100 Subject: [PATCH 0019/1010] [IMP] survey: change in progress bzr revid: chm@openerp.com-20130212101328-j7s5c9jkln4pluvk --- addons/survey/__openerp__.py | 4 +- addons/survey/survey.py | 46 +++- addons/survey/survey_view.xml | 2 +- addons/survey/wizard/__init__.py | 1 - addons/survey/wizard/survey_answer.py | 24 +- addons/survey/wizard/survey_answer.xml | 9 + .../survey/wizard/survey_send_invitation.py | 240 ------------------ .../survey/wizard/survey_send_invitation.xml | 88 ++----- 8 files changed, 94 insertions(+), 320 deletions(-) delete mode 100644 addons/survey/wizard/survey_send_invitation.py diff --git a/addons/survey/__openerp__.py b/addons/survey/__openerp__.py index d5e4c3af10c..2545dc484c1 100644 --- a/addons/survey/__openerp__.py +++ b/addons/survey/__openerp__.py @@ -47,7 +47,7 @@ user name and password for the invitation of the survey. 'wizard/survey_print_answer.xml', 'wizard/survey_browse_answer.xml', 'wizard/survey_print.xml', - 'wizard/survey_send_invitation.xml' + 'survey_send_invitation.xml' ], 'demo': ['survey_demo.xml'], 'test': [ @@ -59,6 +59,6 @@ user name and password for the invitation of the survey. 'installable': True, 'auto_install': False, 'images': ['images/survey_answers.jpeg','images/survey_pages.jpeg','images/surveys.jpeg'], - 'css': ['static/src/css/survey.css','static/css/survey.css'], + 'css': ['static/src/css/survey.css'], } # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/survey/survey.py b/addons/survey/survey.py index be9003c805d..f0f20b54d2a 100644 --- a/addons/survey/survey.py +++ b/addons/survey/survey.py @@ -28,6 +28,7 @@ import os from openerp import netsvc, tools from openerp.osv import fields, osv from openerp.tools.translate import _ +import uuid # token = uuid.uuid4() class survey_type(osv.osv): _name = 'survey.type' @@ -151,12 +152,12 @@ class survey(osv.osv): if not pages: raise osv.except_osv(_('Warning!'), _('This survey has no question defined. Please define the questions and answers first.')) context.update({'active':False,'survey_id': ids[0]}) + return { 'view_type': 'form', 'view_mode': 'form', 'res_model': 'survey.question.wiz', 'type': 'ir.actions.act_window', - 'target': 'new', 'name': name, 'context': context } @@ -168,6 +169,8 @@ class survey(osv.osv): if not pages: raise osv.except_osv(_('Warning!'), _('This survey has no pages defined. Please define pages first.')) context.update({'active':False,'survey_id': ids[0]}) + + context.update({'ir_actions_act_window_target': 'new'}) return { 'view_type': 'form', 'view_mode': 'form', @@ -186,6 +189,8 @@ class survey(osv.osv): if not pages: raise osv.except_osv(_('Warning!'), _('This survey has no question defined. Please define the questions and answers first.')) context.update({'survey_id': ids[0]}) + + context.update({'ir_actions_act_window_target': 'new'}) return { 'view_type': 'form', 'view_mode': 'form', @@ -196,6 +201,41 @@ class survey(osv.osv): 'context': context } + def action_survey_sent(self, cr, uid, ids, context=None): + ''' + This function opens a window to compose an email, with the survey template message loaded by default + ''' + assert len(ids) == 1, 'This option should only be used for a single id at a time.' + ir_model_data = self.pool.get('ir.model.data') + try: + template_id = ir_model_data.get_object_reference(cr, uid, 'survey', 'email_template_survey')[1] + except ValueError: + template_id = False + try: + compose_form_id = ir_model_data.get_object_reference(cr, uid, 'mail', 'email_compose_message_wizard_form')[1] + except ValueError: + compose_form_id = False + ctx = dict(context) + + ctx.update({ + 'default_model': 'survey', + 'default_res_id': ids[0], + 'default_use_template': bool(template_id), + 'default_template_id': template_id, + 'default_composition_mode': 'comment', + 'mark_invoice_as_sent': True, + }) + return { + 'type': 'ir.actions.act_window', + 'view_type': 'form', + 'view_mode': 'form', + 'res_model': 'mail.compose.message', + 'views': [(compose_form_id, 'form')], + 'view_id': compose_form_id, + 'target': 'new', + 'context': ctx, + } + survey() class survey_history(osv.osv): @@ -249,7 +289,7 @@ class survey_page(osv.osv): 'res_model': 'survey.question.wiz', 'type': 'ir.actions.act_window', 'target': 'new', - 'search_view_id': search_id[0], + #'search_view_id': search_id[0], 'context': context } @@ -526,7 +566,7 @@ class survey_question(osv.osv): 'res_model': 'survey.question.wiz', 'type': 'ir.actions.act_window', 'target': 'new', - 'search_view_id': search_id[0], + #'search_view_id': search_id[0], 'context': context } diff --git a/addons/survey/survey_view.xml b/addons/survey/survey_view.xml index 53900b31df5..14d894335e5 100644 --- a/addons/survey/survey_view.xml +++ b/addons/survey/survey_view.xml @@ -321,7 +321,7 @@ diff --git a/addons/survey/wizard/__init__.py b/addons/survey/wizard/__init__.py index 0ea0e5cd424..2da1bfa616f 100644 --- a/addons/survey/wizard/__init__.py +++ b/addons/survey/wizard/__init__.py @@ -19,7 +19,6 @@ # ############################################################################## -import survey_send_invitation import survey_print_statistics import survey_print_answer import survey_browse_answer diff --git a/addons/survey/wizard/survey_answer.py b/addons/survey/wizard/survey_answer.py index 6c3604e22c3..19b151e4999 100644 --- a/addons/survey/wizard/survey_answer.py +++ b/addons/survey/wizard/survey_answer.py @@ -41,10 +41,20 @@ class survey_question_wiz(osv.osv_memory): """ Fields View Get method :- generate the new view and display the survey pages of selected survey. """ + + print "" + print "" + print view_id, view_type, context, toolbar, submenu + print "" + print "" + + if not view_id and not context.get('survey_id', None) and context.get('default_survey_id', None): + context['survey_id'] = context['active_id'] = context.get('default_survey_id') + + if context is None: context = {} - result = super(survey_question_wiz, self).fields_view_get(cr, uid, view_id, \ - view_type, context, toolbar,submenu) + result = super(survey_question_wiz, self).fields_view_get(cr, uid, view_id, view_type, context, toolbar,submenu) surv_name_wiz = self.pool.get('survey.name.wiz') survey_obj = self.pool.get('survey') @@ -213,6 +223,7 @@ class survey_question_wiz(osv.osv_memory): ans_ids = que_rec.answer_choice_ids xml_group = etree.SubElement(xml_form, 'group', {'col': '1', 'colspan': '4'}) + # TODO convert selection field into radio input if que_rec.type == 'multiple_choice_only_one_ans': selection = [] for ans in ans_ids: @@ -373,8 +384,9 @@ class survey_question_wiz(osv.osv_memory): else: etree.SubElement(xml_footer, 'label', {'string': ""}) etree.SubElement(xml_footer, 'button', {'name':"action_next",'string': tools.ustr(but_string) ,'type':"object",'context' : tools.ustr(context), 'class':"oe_highlight"}) - etree.SubElement(xml_footer, 'label', {'string': "or"}) - etree.SubElement(xml_footer, 'button', {'special': "cancel",'string':"Exit",'class':"oe_link"}) + if context.get('ir_actions_act_window_target', None): + etree.SubElement(xml_footer, 'label', {'string': "or"}) + etree.SubElement(xml_footer, 'button', {'special': "cancel",'string':"Exit",'class':"oe_link"}) etree.SubElement(xml_footer, 'label', {'string': tools.ustr(page_number+ 1) + "/" + tools.ustr(total_pages), 'class':"oe_survey_title_page oe_right"}) root = xml_form.getroottree() @@ -1211,7 +1223,7 @@ class survey_question_wiz(osv.osv_memory): "view_mode": 'form', 'res_model': 'survey.question.wiz', 'type': 'ir.actions.act_window', - 'target': 'new', + 'target': context.get('ir_actions_act_window_target', None), 'search_view_id': search_id[0], 'context': context } @@ -1232,7 +1244,7 @@ class survey_question_wiz(osv.osv_memory): "view_mode": 'form', 'res_model': 'survey.question.wiz', 'type': 'ir.actions.act_window', - 'target': 'new', + 'target': context.get('ir_actions_act_window_target', None), 'search_view_id': search_id[0], 'context': context } diff --git a/addons/survey/wizard/survey_answer.xml b/addons/survey/wizard/survey_answer.xml index b02f9fb2be5..27d91d12642 100644 --- a/addons/survey/wizard/survey_answer.xml +++ b/addons/survey/wizard/survey_answer.xml @@ -33,5 +33,14 @@ new
+ + ir.actions.act_window + survey.question.wiz + form + form + new + {'survey_id': survey_id, 'survey_token': survey_token} + + diff --git a/addons/survey/wizard/survey_send_invitation.py b/addons/survey/wizard/survey_send_invitation.py deleted file mode 100644 index 4913ca09eab..00000000000 --- a/addons/survey/wizard/survey_send_invitation.py +++ /dev/null @@ -1,240 +0,0 @@ -# -*- coding: utf-8 -*- -############################################################################## -# -# OpenERP, Open Source Management Solution -# Copyright (C) 2004-2010 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 time -from random import choice -import string -import os -import datetime -import socket - -from openerp import addons, netsvc, tools -from openerp.osv import fields, osv -from openerp.tools.translate import _ - - -class survey_send_invitation(osv.osv_memory): - _name = 'survey.send.invitation' - _columns = { - 'partner_ids': fields.many2many('res.partner','survey_res_partner','partner_id',\ - 'survey_id', "Answer", required=1), - 'send_mail': fields.boolean('Send Mail for New User'), - 'send_mail_existing': fields.boolean('Send Reminder for Existing User'), - 'mail_subject': fields.char('Subject', size=256), - 'mail_subject_existing': fields.char('Subject', size=256), - 'mail_from': fields.char('From', size=256, required=1), - 'mail': fields.text('Body') - } - - _defaults = { - 'send_mail': lambda *a: 1, - 'send_mail_existing': lambda *a: 1, - } - - def genpasswd(self): - chars = string.letters + string.digits - return ''.join([choice(chars) for i in range(6)]) - - def default_get(self, cr, uid, fields_list, context=None): - if context is None: - context = {} - data = super(survey_send_invitation, self).default_get(cr, uid, fields_list, context) - survey_obj = self.pool.get('survey') - msg = "" - name = "" - for sur in survey_obj.browse(cr, uid, context.get('active_ids', []), context=context): - name += "\n --> " + sur.title + "\n" - if sur.state != 'open': - msg += sur.title + "\n" - data['mail_subject'] = _("Invitation for %s") % (sur.title) - data['mail_subject_existing'] = _("Invitation for %s") % (sur.title) - data['mail_from'] = sur.responsible_id.email - if msg: - raise osv.except_osv(_('Warning!'), _('The following surveys are not in open state: %s') % msg) - data['mail'] = _(''' -Hello %%(name)s, \n\n -Would you please spent some of your time to fill-in our survey: \n%s\n -You can access this survey with the following parameters: - URL: %s - Your login ID: %%(login)s\n - Your password: %%(passwd)s\n -\n\n -Thanks,''') % (name, self.pool.get('ir.config_parameter').get_param(cr, uid, 'web.base.url', default='http://localhost:8069', context=context)) - return data - - def create_report(self, cr, uid, res_ids, report_name=False, file_name=False): - if not report_name or not res_ids: - return (False, Exception('Report name and Resources ids are required !!!')) - try: - ret_file_name = addons.get_module_resource('survey', 'report') + file_name + '.pdf' - service = netsvc.LocalService(report_name); - (result, format) = service.create(cr, uid, res_ids, {}, {}) - fp = open(ret_file_name, 'wb+'); - fp.write(result); - fp.close(); - except Exception,e: - print 'Exception in create report:',e - return (False, str(e)) - return (True, ret_file_name) - - - def action_send(self, cr, uid, ids, context=None): - if context is None: - context = {} - record = self.read(cr, uid, ids, [],context=context) - survey_ids = context.get('active_ids', []) - record = record and record[0] - partner_ids = record['partner_ids'] - user_ref= self.pool.get('res.users') - survey_ref= self.pool.get('survey') - mail_message = self.pool.get('mail.message') - - model_data_obj = self.pool.get('ir.model.data') - group_id = model_data_obj._get_id(cr, uid, 'base', 'group_survey_user') - group_id = model_data_obj.browse(cr, uid, group_id, context=context).res_id - - act_id = self.pool.get('ir.actions.act_window') - act_id = act_id.search(cr, uid, [('res_model', '=' , 'survey.name.wiz'), \ - ('view_type', '=', 'form')]) - out = "login,password\n" - skipped = 0 - existing = "" - created = "" - error = "" - new_user = [] - attachments = {} - current_sur = survey_ref.browse(cr, uid, context.get('active_id'), context=context) - exist_user = current_sur.invited_user_ids - if exist_user: - for use in exist_user: - new_user.append(use.id) - for id in survey_ref.browse(cr, uid, survey_ids): - report = self.create_report(cr, uid, [id.id], 'report.survey.form', id.title) - file = open(addons.get_module_resource('survey', 'report') + id.title +".pdf") - file_data = "" - while 1: - line = file.readline() - file_data += line - if not line: - break - file.close() - attachments[id.title +".pdf"] = file_data - os.remove(addons.get_module_resource('survey', 'report') + id.title +".pdf") - - for partner in self.pool.get('res.partner').browse(cr, uid, partner_ids): - if not partner.email: - skipped+= 1 - continue - user = user_ref.search(cr, uid, [('login', "=", partner.email)]) - if user: - if user[0] not in new_user: - new_user.append(user[0]) - user = user_ref.browse(cr, uid, user[0]) - user_ref.write(cr, uid, user.id, {'survey_id':[[6, 0, survey_ids]]}) - mail = record['mail']%{'login':partner.email, 'passwd':user.password, \ - 'name' : partner.name} - if record['send_mail_existing']: - vals = { - 'state': 'outgoing', - 'subject': record['mail_subject_existing'], - 'body_html': '
%s
' % mail, - 'email_to': partner.email, - 'email_from': record['mail_from'], - } - self.pool.get('mail.mail').create(cr, uid, vals, context=context) - existing+= "- %s (Login: %s, Password: %s)\n" % (user.name, partner.email, \ - user.password) - continue - - passwd= self.genpasswd() - out+= partner.email + ',' + passwd + '\n' - mail= record['mail'] % {'login' : partner.email, 'passwd' : passwd, 'name' : partner.name} - if record['send_mail']: - vals = { - 'state': 'outgoing', - 'subject': record['mail_subject'], - 'body_html': '
%s
' % mail, - 'email_to': partner.email, - 'email_from': record['mail_from'], - } - if attachments: - vals['attachment_ids'] = [(0,0,{'name': a_name, - 'datas_fname': a_name, - 'datas': str(a_content).encode('base64')}) - for a_name, a_content in attachments.items()] - ans = self.pool.get('mail.mail').create(cr, uid, vals, context=context) - if ans: - res_data = {'name': partner.name or _('Unknown'), - 'login': partner.email, - 'password': passwd, - 'address_id': partner.id, - 'groups_id': [[6, 0, [group_id]]], - 'action_id': act_id[0], - 'survey_id': [[6, 0, survey_ids]] - } - user = user_ref.create(cr, uid, res_data) - if user not in new_user: - new_user.append(user) - created+= "- %s (Login: %s, Password: %s)\n" % (partner.name or _('Unknown'),\ - partner.email, passwd) - else: - error+= "- %s (Login: %s, Password: %s)\n" % (partner.name or _('Unknown'),\ - partner.email, passwd) - - new_vals = {} - new_vals.update({'invited_user_ids':[[6,0,new_user]]}) - survey_ref.write(cr, uid, context.get('active_id'),new_vals) - note= "" - if created: - note += 'Created users:\n%s\n\n' % (created) - if existing: - note +='Already existing users:\n%s\n\n' % (existing) - if skipped: - note += "%d contacts where ignored (an email address is missing).\n\n" % (skipped) - if error: - note += 'Email not send successfully:\n====================\n%s\n' % (error) - context.update({'note' : note}) - return { - 'view_type': 'form', - "view_mode": 'form', - 'res_model': 'survey.send.invitation.log', - 'type': 'ir.actions.act_window', - 'target': 'new', - 'context': context - } -survey_send_invitation() - -class survey_send_invitation_log(osv.osv_memory): - _name = 'survey.send.invitation.log' - _columns = { - 'note' : fields.text('Log', readonly=1) - } - - def default_get(self, cr, uid, fields_list, context=None): - if context is None: - context = {} - data = super(survey_send_invitation_log, self).default_get(cr, uid, fields_list, context) - data['note'] = context.get('note', '') - return data - -survey_send_invitation_log() - -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/survey/wizard/survey_send_invitation.xml b/addons/survey/wizard/survey_send_invitation.xml index a611973d772..f2879990b9c 100644 --- a/addons/survey/wizard/survey_send_invitation.xml +++ b/addons/survey/wizard/survey_send_invitation.xml @@ -1,74 +1,28 @@ - - - - - Send Invitation - survey.send.invitation - -
-
-
- - - - - - - - - - - - - - -
-
+ + + Survey - Send by Email + ${object.responsible_id and object.responsible_id.company_id and object.responsible_id.company_id.email or object.responsible_id.email or ''} + ${object.title} + ${object.lang} + + + +

Hello,

+

+ Would you please spent some of your time to fill-in our survey: + ${object.title} +

+ % if object.responsible_id: +

Thank you for choosing ${object.responsible_id.company_id.name or 'us'}!

+ % endif +
+ + ]]>
- - - - Send Invitation - survey.send.invitation - form - form - new - - - - - - - - survey send invitation log - survey.send.invitation.log - -
- - - -
-
-
- - - - - survey.send.invitation.log - survey.send.invitation.log - form - form - new -
From 859a4c58e8d207b26f7bfe4cf71fddf1d25a903b Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Tue, 12 Feb 2013 15:29:32 +0100 Subject: [PATCH 0020/1010] [IMP] survey: in progress; external link OK, target=inline bzr revid: chm@openerp.com-20130212142932-ma63q3y6p7ev0j9s --- addons/survey/wizard/survey_answer.xml | 4 ++-- addons/survey/wizard/survey_send_invitation.xml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/addons/survey/wizard/survey_answer.xml b/addons/survey/wizard/survey_answer.xml index 27d91d12642..a0f5fa10482 100644 --- a/addons/survey/wizard/survey_answer.xml +++ b/addons/survey/wizard/survey_answer.xml @@ -38,8 +38,8 @@ survey.question.wiz form form - new - {'survey_id': survey_id, 'survey_token': survey_token} + inline + {'survey_id': active_id, 'survey_token': params, 'ir_actions_act_window_target': 'inline'} diff --git a/addons/survey/wizard/survey_send_invitation.xml b/addons/survey/wizard/survey_send_invitation.xml index f2879990b9c..be7e73e278c 100644 --- a/addons/survey/wizard/survey_send_invitation.xml +++ b/addons/survey/wizard/survey_send_invitation.xml @@ -14,7 +14,7 @@

Hello,

Would you please spent some of your time to fill-in our survey: - ${object.title} + ${object.title}

% if object.responsible_id:

Thank you for choosing ${object.responsible_id.company_id.name or 'us'}!

From f71cbfcd3f39091262ef67610c46a34a3c602c63 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Wed, 13 Feb 2013 14:09:26 +0100 Subject: [PATCH 0021/1010] [IMP] survey: wizard and template for survey.mail.compose.message; change user_id into partner_id bzr revid: chm@openerp.com-20130213130926-1g014ib4w0bz0dqm --- addons/survey/__openerp__.py | 4 +- addons/survey/survey.py | 48 +++++++++---------- addons/survey/survey_view.xml | 24 +++++----- addons/survey/wizard/__init__.py | 1 + addons/survey/wizard/survey_answer.py | 42 ++++++++-------- addons/survey/wizard/survey_selection.py | 2 +- .../survey/wizard/survey_send_invitation.xml | 28 ----------- 7 files changed, 62 insertions(+), 87 deletions(-) delete mode 100644 addons/survey/wizard/survey_send_invitation.xml diff --git a/addons/survey/__openerp__.py b/addons/survey/__openerp__.py index 2545dc484c1..9c9f47ff098 100644 --- a/addons/survey/__openerp__.py +++ b/addons/survey/__openerp__.py @@ -34,7 +34,7 @@ question and according to that survey is done. Partners are also sent mails with user name and password for the invitation of the survey. """, 'author': 'OpenERP SA', - 'depends': ['mail'], + 'depends': ['email_template'], 'data': [ 'survey_report.xml', 'survey_data.xml', @@ -47,7 +47,7 @@ user name and password for the invitation of the survey. 'wizard/survey_print_answer.xml', 'wizard/survey_browse_answer.xml', 'wizard/survey_print.xml', - 'survey_send_invitation.xml' + 'wizard/survey_email_compose_message.xml', ], 'demo': ['survey_demo.xml'], 'test': [ diff --git a/addons/survey/survey.py b/addons/survey/survey.py index f0f20b54d2a..61f507137b9 100644 --- a/addons/survey/survey.py +++ b/addons/survey/survey.py @@ -28,7 +28,6 @@ import os from openerp import netsvc, tools from openerp.osv import fields, osv from openerp.tools.translate import _ -import uuid # token = uuid.uuid4() class survey_type(osv.osv): _name = 'survey.type' @@ -56,26 +55,26 @@ class survey(osv.osv): 'date_close': fields.datetime('Survey Close Date', readonly=1), 'max_response_limit': fields.integer('Maximum Answer Limit', help="Set to one if survey is answerable only once"), - 'response_user': fields.integer('Maximum Answer per User', - help="Set to one if you require only one Answer per user"), + 'response_partner': fields.integer('Maximum Answer per partner', + help="Set to one if you require only one Answer per partner"), 'state': fields.selection([('open', 'Open'), ('cancel', 'Cancelled'),('close', 'Closed') ], 'Status', readonly=True), 'responsible_id': fields.many2one('res.users', 'Responsible', help="User responsible for survey"), 'tot_start_survey': fields.integer("Total Started Survey", readonly=1), 'tot_comp_survey': fields.integer("Total Completed Survey", readonly=1), 'note': fields.text('Description', size=128), 'history': fields.one2many('survey.history', 'survey_id', 'History Lines', readonly=True), - 'users': fields.many2many('res.users', 'survey_users_rel', 'sid', 'uid', 'Users'), + 'partner_id': fields.many2many('res.partner', 'survey_partner_rel', 'sid', 'uid', 'Partners'), 'send_response': fields.boolean('Email Notification on Answer'), 'type': fields.many2one('survey.type', 'Type'), 'color': fields.integer('Color Index'), - 'invited_user_ids': fields.many2many('res.users', 'survey_invited_user_rel', 'sid', 'uid', 'Invited User'), + 'invited_partner_ids': fields.many2many('res.partner', 'survey_invited_partner_rel', 'sid', 'uid', 'Invited User'), } _defaults = { 'state': lambda * a: "open", 'tot_start_survey': lambda * a: 0, 'tot_comp_survey': lambda * a: 0, 'send_response': lambda * a: 1, - 'response_user': lambda * a:1, + 'response_partner': lambda * a:1, 'date_open': fields.datetime.now, } @@ -244,7 +243,7 @@ class survey_history(osv.osv): _rec_name = 'date' _columns = { 'survey_id': fields.many2one('survey', 'Survey'), - 'user_id': fields.many2one('res.users', 'User', readonly=True), + 'partner_id': fields.many2one('res.partner', 'Partner', readonly=True), 'date': fields.datetime('Date started', readonly=1), } _defaults = { @@ -657,9 +656,9 @@ class survey_answer(osv.osv): 'in_visible_answer_type': fields.boolean('Is Answer Type Invisible??') } _defaults = { -# 'sequence' : lambda * a: 1, - 'type' : lambda * a: 'char', - 'in_visible_answer_type':_get_in_visible_answer_type, + # 'sequence' : lambda * a: 1, + 'type' : lambda * a: 'char', + 'in_visible_answer_type':_get_in_visible_answer_type, } def default_get(self, cr, uid, fields, context=None): @@ -676,7 +675,7 @@ class survey_response(osv.osv): _columns = { 'survey_id' : fields.many2one('survey', 'Survey', required=1, ondelete='cascade'), 'date_create' : fields.datetime('Create Date', required=1), - 'user_id' : fields.many2one('res.users', 'User'), + 'partner_id' : fields.many2one('res.partner', 'Partner'), 'response_type' : fields.selection([('manually', 'Manually'), ('link', 'Link')], \ 'Answer Type', required=1, readonly=1), 'question_ids' : fields.one2many('survey.response.line', 'response_id', 'Answer'), @@ -691,10 +690,10 @@ class survey_response(osv.osv): def name_get(self, cr, uid, ids, context=None): if not len(ids): return [] - reads = self.read(cr, uid, ids, ['user_id','date_create'], context=context) + reads = self.read(cr, uid, ids, ['partner_id','date_create'], context=context) res = [] for record in reads: - name = (record['user_id'] and record['user_id'][1] or '' )+ ' (' + record['date_create'].split('.')[0] + ')' + name = (record['partner_id'] and record['partner_id'][1] or '' )+ ' (' + record['date_create'].split('.')[0] + ')' res.append((record['id'], name)) return res @@ -755,14 +754,13 @@ class survey_response_answer(osv.osv): survey_response_answer() -class res_users(osv.osv): - _inherit = "res.users" - _name = "res.users" +class res_partner(osv.osv): + _inherit = "res.partner" + _name = "res.partner" _columns = { - 'survey_id': fields.many2many('survey', 'survey_users_rel', 'uid', 'sid', 'Groups'), + 'survey_id': fields.many2many('survey', 'survey_partner_rel', 'uid', 'sid', 'Groups'), } - -res_users() +res_partner() class survey_request(osv.osv): _name = "survey.request" @@ -770,7 +768,7 @@ class survey_request(osv.osv): _rec_name = 'date_deadline' _columns = { 'date_deadline': fields.date("Deadline date"), - 'user_id': fields.many2one("res.users", "User"), + 'partner_id': fields.many2one("res.partner", "Partner"), 'email': fields.char("Email", size=64), 'survey_id': fields.many2one("survey", "Survey", required=1, ondelete='cascade'), 'response': fields.many2one('survey.response', 'Answer'), @@ -796,11 +794,11 @@ class survey_request(osv.osv): self.write(cr, uid, ids, { 'state' : 'cancel'}) return True - def on_change_user(self, cr, uid, ids, user_id, context=None): - if user_id: - user_obj = self.pool.get('res.users') - user = user_obj.browse(cr, uid, user_id, context=context) - return {'value': {'email': user.email}} + def on_change_partner(self, cr, uid, ids, partner_id, context=None): + if partner_id: + partner_obj = self.pool.get('res.partner') + partner = partner_obj.browse(cr, uid, partner_id, context=context) + return {'value': {'email': partner.email}} return {} survey_request() diff --git a/addons/survey/survey_view.xml b/addons/survey/survey_view.xml index 14d894335e5..7d1b07d15d6 100644 --- a/addons/survey/survey_view.xml +++ b/addons/survey/survey_view.xml @@ -50,7 +50,7 @@
- +
@@ -215,7 +215,7 @@
- + @@ -231,11 +231,11 @@ - +
- +
@@ -1016,7 +1016,7 @@
- + @@ -1031,7 +1031,7 @@ - + @@ -1110,7 +1110,7 @@ - + @@ -1125,7 +1125,7 @@ - + @@ -1144,11 +1144,11 @@ - + - + - + @@ -1161,7 +1161,7 @@ survey.request form tree,form - [('user_id','=',uid)] + [('partner_id','=',uid)] diff --git a/addons/survey/wizard/__init__.py b/addons/survey/wizard/__init__.py index 2da1bfa616f..6a7220f05b9 100644 --- a/addons/survey/wizard/__init__.py +++ b/addons/survey/wizard/__init__.py @@ -19,6 +19,7 @@ # ############################################################################## +import survey_email_compose_message import survey_print_statistics import survey_print_answer import survey_browse_answer diff --git a/addons/survey/wizard/survey_answer.py b/addons/survey/wizard/survey_answer.py index 19b151e4999..a92ab5ca28f 100644 --- a/addons/survey/wizard/survey_answer.py +++ b/addons/survey/wizard/survey_answer.py @@ -41,19 +41,21 @@ class survey_question_wiz(osv.osv_memory): """ Fields View Get method :- generate the new view and display the survey pages of selected survey. """ + if context is None: + context = {} print "" print "" - print view_id, view_type, context, toolbar, submenu + print view_id + print view_type + print context.get("survey_id", None) + print context.get("survey_token", None) print "" print "" if not view_id and not context.get('survey_id', None) and context.get('default_survey_id', None): context['survey_id'] = context['active_id'] = context.get('default_survey_id') - - if context is None: - context = {} result = super(survey_question_wiz, self).fields_view_get(cr, uid, view_id, view_type, context, toolbar,submenu) surv_name_wiz = self.pool.get('survey.name.wiz') @@ -64,6 +66,7 @@ class survey_question_wiz(osv.osv_memory): sur_response_obj = self.pool.get('survey.response') que_col_head = self.pool.get('survey.question.column.heading') user_obj = self.pool.get('res.users') + partner_obj = self.pool.get('res.partner') mail_message = self.pool.get('mail.message') if view_type in ['form']: @@ -125,13 +128,13 @@ class survey_question_wiz(osv.osv_memory): or not context.has_key('active')) and not sur_name_rec.page_no + 1: if sur_rec.state != "open" : raise osv.except_osv(_('Warning!'),_("You cannot answer because the survey is not open.")) - cr.execute('select count(id) from survey_history where user_id=%s\ + cr.execute('select count(id) from survey_history where partner_id=%s\ and survey_id=%s', (uid,survey_id)) res = cr.fetchone()[0] - user_limit = survey_obj.browse(cr, uid, survey_id) - user_limit = user_limit.response_user - if user_limit and res >= user_limit: - raise osv.except_osv(_('Warning!'),_("You cannot answer this survey more than %s times.") % (user_limit)) + partner_limit = survey_obj.browse(cr, uid, survey_id) + partner_limit = partner_limit.response_partner + if partner_limit and res >= partner_limit: + raise osv.except_osv(_('Warning!'),_("You cannot answer this survey more than %s times.") % (partner_limit)) if sur_rec.max_response_limit and sur_rec.max_response_limit <= sur_rec.tot_start_survey and not sur_name_rec.page_no + 1: survey_obj.write(cr, uid, survey_id, {'state':'close', 'date_close':strftime("%Y-%m-%d %H:%M:%S")}) @@ -181,7 +184,7 @@ class survey_question_wiz(osv.osv_memory): # TODO: l10n, cleanup this code to make it readable. Or template? xml_group = etree.SubElement(xml_form, 'group', {'col': '40', 'colspan': '4'}) record = sur_response_obj.browse(cr, uid, context['response_id'][context['response_no']]) - etree.SubElement(xml_group, 'label', {'string': to_xml(tools.ustr('Answer Of :- ' + record.user_id.name + ', Date :- ' + record.date_create.split('.')[0] )), 'align':"0.0"}) + etree.SubElement(xml_group, 'label', {'string': to_xml(tools.ustr('Answer Of :- ' + record.partner_id.name + ', Date :- ' + record.date_create.split('.')[0] )), 'align':"0.0"}) etree.SubElement(xml_group, 'label', {'string': to_xml(tools.ustr(" Answer :- " + str(context.get('response_no',0) + 1) +"/" + str(len(context.get('response_id',0))) )), 'align':"0.0"}) if context.get('response_no',0) > 0: etree.SubElement(xml_group, 'button', {'colspan':"1",'icon':"gtk-go-back",'name':"action_forward_previous",'string': tools.ustr("Previous Answer"),'type':"object"}) @@ -421,17 +424,17 @@ class survey_question_wiz(osv.osv_memory): file.close() os.remove(addons.get_module_resource('survey', 'report') + survey_data.title + ".pdf") context.update({'response_id':response_id}) - user_email = user_obj.browse(cr, uid, uid, context).email + partner_email = user_obj.browse(cr, uid, uid, context).partner_email.email resp_email = survey_data.responsible_id and survey_data.responsible_id.email or False - if user_email and resp_email: - user_name = user_obj.browse(cr, uid, uid, context=context).name - mail = "Hello " + survey_data.responsible_id.name + ",\n\n " + str(user_name) + " has given the Response Of " + survey_data.title + " Survey.\nThe Response has been attached herewith.\n\n Thanks." + if partner_email and resp_email: + partner_name = partner_obj.browse(cr, uid, uid, context=context).name + mail = "Hello " + survey_data.responsible_id.name + ",\n\n " + str(partner_name) + " has given the Response Of " + survey_data.title + " Survey.\nThe Response has been attached herewith.\n\n Thanks." vals = {'state': 'outgoing', - 'subject': "Survey Answer Of " + user_name, + 'subject': "Survey Answer Of " + partner_name, 'body_html': '
%s
' % mail, 'email_to': [resp_email], - 'email_from': user_email} + 'email_from': partner_email} if attachments: vals['attachment_ids'] = [(0,0,{'name': a_name, 'datas_fname': a_name, @@ -585,21 +588,22 @@ class survey_question_wiz(osv.osv_memory): res_ans_obj = self.pool.get('survey.response.answer') que_obj = self.pool.get('survey.question') sur_name_read = surv_name_wiz.read(cr, uid, context.get('sur_name_id',False), []) + partner_id = self.pool.get('res.users').browse(cr, uid, uid, context).partner_email.id response_id = 0 if not sur_name_read['response']: - response_id = surv_all_resp_obj.create(cr, uid, {'response_type':'link', 'user_id':uid, 'date_create':datetime.datetime.now(), 'survey_id' : context['survey_id']}) + response_id = surv_all_resp_obj.create(cr, uid, {'response_type':'link', 'partner_id':partner_id, 'date_create':datetime.datetime.now(), 'survey_id' : context['survey_id']}) surv_name_wiz.write(cr, uid, [context.get('sur_name_id', False)], {'response' : tools.ustr(response_id)}) else: response_id = int(sur_name_read['response']) if response_id not in surv_all_resp_obj.search(cr, uid, []): - response_id = surv_all_resp_obj.create(cr, uid, {'response_type':'link', 'user_id':uid, 'date_create':datetime.datetime.now(), 'survey_id' : context.get('survey_id',False)}) + response_id = surv_all_resp_obj.create(cr, uid, {'response_type':'link', 'partner_id':partner_id, 'date_create':datetime.datetime.now(), 'survey_id' : context.get('survey_id',False)}) surv_name_wiz.write(cr, uid, [context.get('sur_name_id',False)], {'response' : tools.ustr(response_id)}) #click first time on next button then increemnet on total start suvey if not safe_eval(sur_name_read['store_ans']): - his_id = self.pool.get('survey.history').create(cr, uid, {'user_id': uid, \ + his_id = self.pool.get('survey.history').create(cr, uid, {'partner_id': partner_id, \ 'date': strftime('%Y-%m-%d %H:%M:%S'), 'survey_id': sur_name_read['survey_id'][0]}) survey_id = sur_name_read['survey_id'][0] sur_rec = survey_obj.read(cr, uid, survey_id) diff --git a/addons/survey/wizard/survey_selection.py b/addons/survey/wizard/survey_selection.py index a8f83ba0361..0c9f4d85866 100644 --- a/addons/survey/wizard/survey_selection.py +++ b/addons/survey/wizard/survey_selection.py @@ -49,7 +49,7 @@ class survey_name_wiz(osv.osv_memory): res = super(survey_name_wiz, self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar, submenu=False) if uid != 1: survey_obj = self.pool.get('survey') - line_ids = survey_obj.search(cr, uid, [('invited_user_ids','in',uid)], context=context) + line_ids = survey_obj.search(cr, uid, [('invited_partner_ids','in',uid)], context=context) domain = str([('id', 'in', line_ids)]) doc = etree.XML(res['arch']) nodes = doc.xpath("//field[@name='survey_id']") diff --git a/addons/survey/wizard/survey_send_invitation.xml b/addons/survey/wizard/survey_send_invitation.xml deleted file mode 100644 index be7e73e278c..00000000000 --- a/addons/survey/wizard/survey_send_invitation.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - Survey - Send by Email - ${object.responsible_id and object.responsible_id.company_id and object.responsible_id.company_id.email or object.responsible_id.email or ''} - ${object.title} - ${object.lang} - - - -

Hello,

-

- Would you please spent some of your time to fill-in our survey: - ${object.title} -

- % if object.responsible_id: -

Thank you for choosing ${object.responsible_id.company_id.name or 'us'}!

- % endif -
- - ]]>
-
- -
-
From b144d732530e383a74e800e8be8fb33d4a3d765e Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Wed, 13 Feb 2013 15:56:28 +0100 Subject: [PATCH 0022/1010] [IMP] survey: 'response' to 'response_id'; view 'survey.question.wiz' inline bzr revid: chm@openerp.com-20130213145628-1zkvj02g963j5bff --- addons/survey/survey.py | 15 ++++++--------- addons/survey/survey_view.xml | 12 ++++++------ addons/survey/wizard/survey_answer.py | 8 ++++---- 3 files changed, 16 insertions(+), 19 deletions(-) diff --git a/addons/survey/survey.py b/addons/survey/survey.py index 61f507137b9..36791e6ada3 100644 --- a/addons/survey/survey.py +++ b/addons/survey/survey.py @@ -157,6 +157,7 @@ class survey(osv.osv): 'view_mode': 'form', 'res_model': 'survey.question.wiz', 'type': 'ir.actions.act_window', + 'target': 'inline', 'name': name, 'context': context } @@ -175,7 +176,7 @@ class survey(osv.osv): 'view_mode': 'form', 'res_model': 'survey.question.wiz', 'type': 'ir.actions.act_window', - 'target': 'new', + 'target': 'inline', 'name': name, 'context': context } @@ -210,10 +211,6 @@ class survey(osv.osv): template_id = ir_model_data.get_object_reference(cr, uid, 'survey', 'email_template_survey')[1] except ValueError: template_id = False - try: - compose_form_id = ir_model_data.get_object_reference(cr, uid, 'mail', 'email_compose_message_wizard_form')[1] - except ValueError: - compose_form_id = False ctx = dict(context) ctx.update({ @@ -228,9 +225,7 @@ class survey(osv.osv): 'type': 'ir.actions.act_window', 'view_type': 'form', 'view_mode': 'form', - 'res_model': 'mail.compose.message', - 'views': [(compose_form_id, 'form')], - 'view_id': compose_form_id, + 'res_model': 'survey.mail.compose.message', 'target': 'new', 'context': ctx, } @@ -766,12 +761,14 @@ class survey_request(osv.osv): _name = "survey.request" _order = 'date_deadline' _rec_name = 'date_deadline' + _columns = { 'date_deadline': fields.date("Deadline date"), + 'token': fields.char("Indentification token"), 'partner_id': fields.many2one("res.partner", "Partner"), 'email': fields.char("Email", size=64), 'survey_id': fields.many2one("survey", "Survey", required=1, ondelete='cascade'), - 'response': fields.many2one('survey.response', 'Answer'), + 'response_id': fields.many2one('survey.response', 'Answer'), 'state': fields.selection([('draft','Draft'),('cancel', 'Cancelled'),('waiting_answer', 'Waiting Answer'),('done', 'Done')], 'Status', readonly=1) } _defaults = { diff --git a/addons/survey/survey_view.xml b/addons/survey/survey_view.xml index 7d1b07d15d6..deb68c3d0a1 100644 --- a/addons/survey/survey_view.xml +++ b/addons/survey/survey_view.xml @@ -1112,7 +1112,7 @@ - + @@ -1128,7 +1128,7 @@ - +
@@ -1140,15 +1140,15 @@ - + - + - + @@ -1161,7 +1161,7 @@ survey.request form tree,form - [('partner_id','=',uid)] + ['|', ('partner_id.user_id.id','=',uid), ('survey_id.responsible_id.id','=',uid)] diff --git a/addons/survey/wizard/survey_answer.py b/addons/survey/wizard/survey_answer.py index a92ab5ca28f..fea3ff63040 100644 --- a/addons/survey/wizard/survey_answer.py +++ b/addons/survey/wizard/survey_answer.py @@ -424,7 +424,7 @@ class survey_question_wiz(osv.osv_memory): file.close() os.remove(addons.get_module_resource('survey', 'report') + survey_data.title + ".pdf") context.update({'response_id':response_id}) - partner_email = user_obj.browse(cr, uid, uid, context).partner_email.email + partner_email = user_obj.browse(cr, uid, uid, context).email resp_email = survey_data.responsible_id and survey_data.responsible_id.email or False if partner_email and resp_email: @@ -588,7 +588,7 @@ class survey_question_wiz(osv.osv_memory): res_ans_obj = self.pool.get('survey.response.answer') que_obj = self.pool.get('survey.question') sur_name_read = surv_name_wiz.read(cr, uid, context.get('sur_name_id',False), []) - partner_id = self.pool.get('res.users').browse(cr, uid, uid, context).partner_email.id + partner_id = self.pool.get('res.users').browse(cr, uid, uid, context).partner_id.id response_id = 0 if not sur_name_read['response']: @@ -1227,7 +1227,7 @@ class survey_question_wiz(osv.osv_memory): "view_mode": 'form', 'res_model': 'survey.question.wiz', 'type': 'ir.actions.act_window', - 'target': context.get('ir_actions_act_window_target', None), + 'target': 'inline', 'search_view_id': search_id[0], 'context': context } @@ -1248,7 +1248,7 @@ class survey_question_wiz(osv.osv_memory): "view_mode": 'form', 'res_model': 'survey.question.wiz', 'type': 'ir.actions.act_window', - 'target': context.get('ir_actions_act_window_target', None), + 'target': 'inline', 'search_view_id': search_id[0], 'context': context } From ce983722918ad245ddaec8dd702ef55812f8bc67 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Wed, 13 Feb 2013 17:11:37 +0100 Subject: [PATCH 0023/1010] [IMP] survey: access or not to the survey with message bzr revid: chm@openerp.com-20130213161137-n42lgmefrdz1xg2c --- addons/survey/survey.py | 13 +- addons/survey/wizard/survey_answer.py | 637 ++++++++++++----------- addons/survey/wizard/survey_selection.py | 2 +- 3 files changed, 332 insertions(+), 320 deletions(-) diff --git a/addons/survey/survey.py b/addons/survey/survey.py index 36791e6ada3..08b4f6459b0 100644 --- a/addons/survey/survey.py +++ b/addons/survey/survey.py @@ -668,17 +668,18 @@ class survey_response(osv.osv): _name = "survey.response" _rec_name = 'date_create' _columns = { + 'date_deadline': fields.date("Deadline date", help="Date by which the person can respond to the survey"), 'survey_id' : fields.many2one('survey', 'Survey', required=1, ondelete='cascade'), 'date_create' : fields.datetime('Create Date', required=1), - 'partner_id' : fields.many2one('res.partner', 'Partner'), - 'response_type' : fields.selection([('manually', 'Manually'), ('link', 'Link')], \ - 'Answer Type', required=1, readonly=1), + 'response_type' : fields.selection([('manually', 'Manually'), ('link', 'Link')], 'Answer Type', required=1, readonly=1), 'question_ids' : fields.one2many('survey.response.line', 'response_id', 'Answer'), - 'state' : fields.selection([('done', 'Finished '),('skip', 'Not Finished')], \ - 'Status', readonly=True), + 'state' : fields.selection([('new', 'Not Started'),('done', 'Finished'),('skip', 'Not Finished')], 'Status', readonly=True), + 'token': fields.char("Indentification token"), + 'partner_id' : fields.many2one('res.partner', 'Partner'), + 'email': fields.char("Email", size=64), } _defaults = { - 'state' : lambda * a: "skip", + 'state' : lambda * a: "new", 'response_type' : lambda * a: "manually", } diff --git a/addons/survey/wizard/survey_answer.py b/addons/survey/wizard/survey_answer.py index fea3ff63040..a0ac9d87064 100644 --- a/addons/survey/wizard/survey_answer.py +++ b/addons/survey/wizard/survey_answer.py @@ -28,6 +28,7 @@ from time import strftime from openerp import addons, netsvc, tools from openerp.osv import fields, osv from openerp.tools import to_xml +from datetime import datetime from openerp.tools.translate import _ from openerp.tools.safe_eval import safe_eval @@ -44,18 +45,6 @@ class survey_question_wiz(osv.osv_memory): if context is None: context = {} - print "" - print "" - print view_id - print view_type - print context.get("survey_id", None) - print context.get("survey_token", None) - print "" - print "" - - if not view_id and not context.get('survey_id', None) and context.get('default_survey_id', None): - context['survey_id'] = context['active_id'] = context.get('default_survey_id') - result = super(survey_question_wiz, self).fields_view_get(cr, uid, view_id, view_type, context, toolbar,submenu) surv_name_wiz = self.pool.get('survey.name.wiz') @@ -66,6 +55,7 @@ class survey_question_wiz(osv.osv_memory): sur_response_obj = self.pool.get('survey.response') que_col_head = self.pool.get('survey.question.column.heading') user_obj = self.pool.get('res.users') + user_browse = user_obj.browse(cr, uid, uid, context=context) partner_obj = self.pool.get('res.partner') mail_message = self.pool.get('mail.message') @@ -122,337 +112,358 @@ class survey_question_wiz(osv.osv_memory): surv_name_wiz.write(cr, uid, [context['sur_name_id']], {'transfer':False}) flag = False fields = {} - if sur_name_read.page == "next" or sur_name_rec.page_no == -1: - if total_pages > sur_name_rec.page_no + 1: - if ((context.has_key('active') and not context.get('active', False)) \ - or not context.has_key('active')) and not sur_name_rec.page_no + 1: - if sur_rec.state != "open" : - raise osv.except_osv(_('Warning!'),_("You cannot answer because the survey is not open.")) - cr.execute('select count(id) from survey_history where partner_id=%s\ - and survey_id=%s', (uid,survey_id)) - res = cr.fetchone()[0] - partner_limit = survey_obj.browse(cr, uid, survey_id) - partner_limit = partner_limit.response_partner - if partner_limit and res >= partner_limit: - raise osv.except_osv(_('Warning!'),_("You cannot answer this survey more than %s times.") % (partner_limit)) - if sur_rec.max_response_limit and sur_rec.max_response_limit <= sur_rec.tot_start_survey and not sur_name_rec.page_no + 1: - survey_obj.write(cr, uid, survey_id, {'state':'close', 'date_close':strftime("%Y-%m-%d %H:%M:%S")}) + # get if the token of the partner or anonymous user is valid + validate_response = sur_rec.responsible_id.id == uid or sur_response_obj.search(cr, uid, [('survey_id','=',survey_id), ('state','=','new'), + '|', ('partner_id','=',user_browse.partner_id.id), ("token","=", context.get("survey_token", None)), + '|', ('date_deadline','=',None), ('date_deadline','<',datetime.now())], context=context, limit=1) + #validate_response = None + + # have acces to this survey + if validate_response: + if sur_name_read.page == "next" or sur_name_rec.page_no == -1: + if total_pages > sur_name_rec.page_no + 1: + if ((context.has_key('active') and not context.get('active', False)) \ + or not context.has_key('active')) and not sur_name_rec.page_no + 1: + if sur_rec.state != "open" : + raise osv.except_osv(_('Warning!'),_("You cannot answer because the survey is not open.")) + cr.execute('select count(id) from survey_history where partner_id=%s\ + and survey_id=%s', (uid,survey_id)) + res = cr.fetchone()[0] + partner_limit = survey_obj.browse(cr, uid, survey_id) + partner_limit = partner_limit.response_partner + if partner_limit and res >= partner_limit: + raise osv.except_osv(_('Warning!'),_("You cannot answer this survey more than %s times.") % (partner_limit)) - p_id = p_id[sur_name_rec.page_no + 1] - surv_name_wiz.write(cr, uid, [context['sur_name_id'],], {'page_no' : sur_name_rec.page_no + 1}) - flag = True - page_number += 1 - if sur_name_rec.page_no > - 1: - pre_button = True - else: - flag = True - else: - if sur_name_rec.page_no != 0: - p_id = p_id[sur_name_rec.page_no - 1] - surv_name_wiz.write(cr, uid, [context['sur_name_id'],],\ - {'page_no' : sur_name_rec.page_no - 1}) - flag = True - page_number -= 1 + if sur_rec.max_response_limit and sur_rec.max_response_limit <= sur_rec.tot_start_survey and not sur_name_rec.page_no + 1: + survey_obj.write(cr, uid, survey_id, {'state':'close', 'date_close':strftime("%Y-%m-%d %H:%M:%S")}) - if sur_name_rec.page_no > 1: - pre_button = True - if flag: - pag_rec = page_obj.browse(cr, uid, p_id, context=context) - note = False - question_ids = [] - if pag_rec: - title = pag_rec.title - note = pag_rec.note - question_ids = pag_rec.question_ids - else: - title = sur_rec.title - xml_form = etree.Element('form', {'string': tools.ustr(title)}) - if context.has_key('active') and context.get('active',False) and context.has_key('edit'): - context.update({'page_id' : tools.ustr(p_id),'page_number' : sur_name_rec.page_no , 'transfer' : sur_name_read.transfer}) - xml_group3 = etree.SubElement(xml_form, 'group', {'col': '4', 'colspan': '4'}) - etree.SubElement(xml_group3, 'button', {'string' :'Add Page','icon': "gtk-new", 'type' :'object','name':"action_new_page", 'context' : tools.ustr(context)}) - etree.SubElement(xml_group3, 'button', {'string' :'Edit Page','icon': "gtk-edit", 'type' :'object','name':"action_edit_page", 'context' : tools.ustr(context)}) - etree.SubElement(xml_group3, 'button', {'string' :'Delete Page','icon': "gtk-delete", 'type' :'object','name':"action_delete_page", 'context' : tools.ustr(context)}) - etree.SubElement(xml_group3, 'button', {'string' :'Add Question','icon': "gtk-new", 'type' :'object','name':"action_new_question", 'context' : tools.ustr(context)}) - - # FP Note - xml_group = xml_form - - if context.has_key('response_id') and context.get('response_id', False) \ - and int(context.get('response_id',0)[0]) > 0: - # TODO: l10n, cleanup this code to make it readable. Or template? - xml_group = etree.SubElement(xml_form, 'group', {'col': '40', 'colspan': '4'}) - record = sur_response_obj.browse(cr, uid, context['response_id'][context['response_no']]) - etree.SubElement(xml_group, 'label', {'string': to_xml(tools.ustr('Answer Of :- ' + record.partner_id.name + ', Date :- ' + record.date_create.split('.')[0] )), 'align':"0.0"}) - etree.SubElement(xml_group, 'label', {'string': to_xml(tools.ustr(" Answer :- " + str(context.get('response_no',0) + 1) +"/" + str(len(context.get('response_id',0))) )), 'align':"0.0"}) - if context.get('response_no',0) > 0: - etree.SubElement(xml_group, 'button', {'colspan':"1",'icon':"gtk-go-back",'name':"action_forward_previous",'string': tools.ustr("Previous Answer"),'type':"object"}) - if context.get('response_no',0) + 1 < len(context.get('response_id',0)): - etree.SubElement(xml_group, 'button', {'colspan':"1",'icon': "gtk-go-forward", 'name':"action_forward_next",'string': tools.ustr("Next Answer") ,'type':"object",'context' : tools.ustr(context)}) - - if wiz_id: - fields["wizardid_" + str(wiz_id)] = {'type':'char', 'size' : 255, 'string':"", 'views':{}} - etree.SubElement(xml_form, 'field', {'invisible':'1','name': "wizardid_" + str(wiz_id),'default':str(lambda *a: 0),'modifiers':'{"invisible":true}'}) - - if note: - xml_group_note = etree.SubElement(xml_form, 'group', {'col': '1','colspan': '4'}) - for que_test in note.split('\n'): - etree.SubElement(xml_group_note, 'label', {'string': to_xml(tools.ustr(que_test)), 'align':"0.0"}) - que_ids = question_ids - qu_no = 0 - - for que in que_ids: - qu_no += 1 - que_rec = que_obj.browse(cr, uid, que.id, context=context) - descriptive_text = "" - separator_string = tools.ustr(qu_no) + "." + tools.ustr(que_rec.question) - if ((context.has_key('active') and not context.get('active',False)) or not context.has_key('active')) and que_rec.is_require_answer: - star = '*' + p_id = p_id[sur_name_rec.page_no + 1] + surv_name_wiz.write(cr, uid, [context['sur_name_id'],], {'page_no' : sur_name_rec.page_no + 1}) + flag = True + page_number += 1 + if sur_name_rec.page_no > - 1: + pre_button = True else: - star = '' - if context.has_key('active') and context.get('active',False) and \ - context.has_key('edit'): - etree.SubElement(xml_form, 'separator', {'string': star+to_xml(separator_string)}) + flag = True + else: + if sur_name_rec.page_no != 0: + p_id = p_id[sur_name_rec.page_no - 1] + surv_name_wiz.write(cr, uid, [context['sur_name_id'],],\ + {'page_no' : sur_name_rec.page_no - 1}) + flag = True + page_number -= 1 - xml_group1 = etree.SubElement(xml_form, 'group', {'col': '2', 'colspan': '2'}) - context.update({'question_id' : tools.ustr(que.id),'page_number': sur_name_rec.page_no , 'transfer' : sur_name_read.transfer, 'page_id' : p_id}) - etree.SubElement(xml_group1, 'button', {'string':'','icon': "gtk-edit", 'type' :'object', 'name':"action_edit_question", 'context' : tools.ustr(context)}) - etree.SubElement(xml_group1, 'button', {'string':'','icon': "gtk-delete", 'type' :'object','name':"action_delete_question", 'context' : tools.ustr(context)}) + if sur_name_rec.page_no > 1: + pre_button = True + + # survey in progress + if flag: + pag_rec = page_obj.browse(cr, uid, p_id, context=context) + note = False + question_ids = [] + if pag_rec: + title = pag_rec.title + note = pag_rec.note + question_ids = pag_rec.question_ids else: - etree.SubElement(xml_form, 'newline') - etree.SubElement(xml_form, 'separator', {'string': star+to_xml(separator_string)}) + title = sur_rec.title + xml_form = etree.Element('form', {'string': tools.ustr(title)}) + if context.has_key('active') and context.get('active',False) and context.has_key('edit'): + context.update({'page_id' : tools.ustr(p_id),'page_number' : sur_name_rec.page_no , 'transfer' : sur_name_read.transfer}) + xml_group3 = etree.SubElement(xml_form, 'group', {'col': '4', 'colspan': '4'}) + etree.SubElement(xml_group3, 'button', {'string' :'Add Page','icon': "gtk-new", 'type' :'object','name':"action_new_page", 'context' : tools.ustr(context)}) + etree.SubElement(xml_group3, 'button', {'string' :'Edit Page','icon': "gtk-edit", 'type' :'object','name':"action_edit_page", 'context' : tools.ustr(context)}) + etree.SubElement(xml_group3, 'button', {'string' :'Delete Page','icon': "gtk-delete", 'type' :'object','name':"action_delete_page", 'context' : tools.ustr(context)}) + etree.SubElement(xml_group3, 'button', {'string' :'Add Question','icon': "gtk-new", 'type' :'object','name':"action_new_question", 'context' : tools.ustr(context)}) - ans_ids = que_rec.answer_choice_ids - xml_group = etree.SubElement(xml_form, 'group', {'col': '1', 'colspan': '4'}) + # FP Note + xml_group = xml_form - # TODO convert selection field into radio input - if que_rec.type == 'multiple_choice_only_one_ans': - selection = [] - for ans in ans_ids: - selection.append((tools.ustr(ans.id), ans.answer)) - xml_group = etree.SubElement(xml_group, 'group', {'col': '2', 'colspan': '2'}) - etree.SubElement(xml_group, 'field', {'readonly':str(readonly), 'name': tools.ustr(que.id) + "_selection"}) - fields[tools.ustr(que.id) + "_selection"] = {'type':'selection', 'selection' :selection, 'string':"Answer"} + if context.has_key('response_id') and context.get('response_id', False) \ + and int(context.get('response_id',0)[0]) > 0: + # TODO: l10n, cleanup this code to make it readable. Or template? + xml_group = etree.SubElement(xml_form, 'group', {'col': '40', 'colspan': '4'}) + record = sur_response_obj.browse(cr, uid, context['response_id'][context['response_no']]) + etree.SubElement(xml_group, 'label', {'string': to_xml(tools.ustr('Answer Of :- ' + record.partner_id.name + ', Date :- ' + record.date_create.split('.')[0] )), 'align':"0.0"}) + etree.SubElement(xml_group, 'label', {'string': to_xml(tools.ustr(" Answer :- " + str(context.get('response_no',0) + 1) +"/" + str(len(context.get('response_id',0))) )), 'align':"0.0"}) + if context.get('response_no',0) > 0: + etree.SubElement(xml_group, 'button', {'colspan':"1",'icon':"gtk-go-back",'name':"action_forward_previous",'string': tools.ustr("Previous Answer"),'type':"object"}) + if context.get('response_no',0) + 1 < len(context.get('response_id',0)): + etree.SubElement(xml_group, 'button', {'colspan':"1",'icon': "gtk-go-forward", 'name':"action_forward_next",'string': tools.ustr("Next Answer") ,'type':"object",'context' : tools.ustr(context)}) - elif que_rec.type == 'multiple_choice_multiple_ans': - xml_group = etree.SubElement(xml_group, 'group', {'col': '4', 'colspan': '4'}) - for ans in ans_ids: - etree.SubElement(xml_group, 'field', {'readonly':str(readonly), 'name': tools.ustr(que.id) + "_" + tools.ustr(ans.id)}) - fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id)] = {'type':'boolean', 'string':ans.answer} + if wiz_id: + fields["wizardid_" + str(wiz_id)] = {'type':'char', 'size' : 255, 'string':"", 'views':{}} + etree.SubElement(xml_form, 'field', {'invisible':'1','name': "wizardid_" + str(wiz_id),'default':str(lambda *a: 0),'modifiers':'{"invisible":true}'}) - elif que_rec.type in ['matrix_of_choices_only_one_ans', 'rating_scale']: - if que_rec.comment_column: - col = "4" - colspan = "4" + if note: + xml_group_note = etree.SubElement(xml_form, 'group', {'col': '1','colspan': '4'}) + for que_test in note.split('\n'): + etree.SubElement(xml_group_note, 'label', {'string': to_xml(tools.ustr(que_test)), 'align':"0.0"}) + que_ids = question_ids + qu_no = 0 + + for que in que_ids: + qu_no += 1 + que_rec = que_obj.browse(cr, uid, que.id, context=context) + descriptive_text = "" + separator_string = tools.ustr(qu_no) + "." + tools.ustr(que_rec.question) + if ((context.has_key('active') and not context.get('active',False)) or not context.has_key('active')) and que_rec.is_require_answer: + star = '*' else: - col = "2" - colspan = "2" - xml_group = etree.SubElement(xml_group, 'group', {'col': tools.ustr(col), 'colspan': tools.ustr(colspan)}) - for row in ans_ids: - etree.SubElement(xml_group, 'newline') - etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'name': tools.ustr(que.id) + "_selection_" + tools.ustr(row.id),'string':to_xml(tools.ustr(row.answer))}) - selection = [('','')] - for col in que_rec.column_heading_ids: - selection.append((str(col.id), col.title)) - fields[tools.ustr(que.id) + "_selection_" + tools.ustr(row.id)] = {'type':'selection', 'selection' : selection, 'string': "Answer"} + star = '' + if context.has_key('active') and context.get('active',False) and \ + context.has_key('edit'): + etree.SubElement(xml_form, 'separator', {'string': star+to_xml(separator_string)}) + + xml_group1 = etree.SubElement(xml_form, 'group', {'col': '2', 'colspan': '2'}) + context.update({'question_id' : tools.ustr(que.id),'page_number': sur_name_rec.page_no , 'transfer' : sur_name_read.transfer, 'page_id' : p_id}) + etree.SubElement(xml_group1, 'button', {'string':'','icon': "gtk-edit", 'type' :'object', 'name':"action_edit_question", 'context' : tools.ustr(context)}) + etree.SubElement(xml_group1, 'button', {'string':'','icon': "gtk-delete", 'type' :'object','name':"action_delete_question", 'context' : tools.ustr(context)}) + else: + etree.SubElement(xml_form, 'newline') + etree.SubElement(xml_form, 'separator', {'string': star+to_xml(separator_string)}) + + ans_ids = que_rec.answer_choice_ids + xml_group = etree.SubElement(xml_form, 'group', {'col': '1', 'colspan': '4'}) + + # TODO convert selection field into radio input + if que_rec.type == 'multiple_choice_only_one_ans': + selection = [] + for ans in ans_ids: + selection.append((tools.ustr(ans.id), ans.answer)) + xml_group = etree.SubElement(xml_group, 'group', {'col': '2', 'colspan': '2'}) + etree.SubElement(xml_group, 'field', {'readonly':str(readonly), 'name': tools.ustr(que.id) + "_selection"}) + fields[tools.ustr(que.id) + "_selection"] = {'type':'selection', 'selection' :selection, 'string':"Answer"} + + elif que_rec.type == 'multiple_choice_multiple_ans': + xml_group = etree.SubElement(xml_group, 'group', {'col': '4', 'colspan': '4'}) + for ans in ans_ids: + etree.SubElement(xml_group, 'field', {'readonly':str(readonly), 'name': tools.ustr(que.id) + "_" + tools.ustr(ans.id)}) + fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id)] = {'type':'boolean', 'string':ans.answer} + + elif que_rec.type in ['matrix_of_choices_only_one_ans', 'rating_scale']: if que_rec.comment_column: - fields[tools.ustr(que.id) + "_commentcolumn_"+tools.ustr(row.id) + "_field"] = {'type':'char', 'size' : 255, 'string':tools.ustr(que_rec.column_name), 'views':{}} - etree.SubElement(xml_group, 'field', {'readonly' :str(readonly), 'name': tools.ustr(que.id) + "_commentcolumn_"+tools.ustr(row.id)+ "_field"}) - - elif que_rec.type == 'matrix_of_choices_only_multi_ans': - xml_group = etree.SubElement(xml_group, 'group', {'col': str(len(que_rec.column_heading_ids) + 1), 'colspan': '4'}) - etree.SubElement(xml_group, 'separator', {'string': '.','colspan': '1'}) - for col in que_rec.column_heading_ids: - etree.SubElement(xml_group, 'separator', {'string': tools.ustr(col.title),'colspan': '1'}) - for row in ans_ids: - etree.SubElement(xml_group, 'label', {'string': to_xml(tools.ustr(row.answer)) +' :-', 'align': '0.0'}) - for col in que_col_head.browse(cr, uid, [head.id for head in que_rec.column_heading_ids]): - etree.SubElement(xml_group, 'field', {'readonly' :str(readonly), 'name': tools.ustr(que.id) + "_" + tools.ustr(row.id) + "_" + tools.ustr(col.id), 'nolabel':"1"}) - fields[tools.ustr(que.id) + "_" + tools.ustr(row.id) + "_" + tools.ustr(col.id)] = {'type':'boolean', 'string': col.title} - - elif que_rec.type == 'multiple_textboxes': - xml_group = etree.SubElement(xml_group, 'group', {'col': '4', 'colspan': '4'}) - type = "char" - if que_rec.is_validation_require: - if que_rec.validation_type in ['must_be_whole_number']: - type = "integer" - elif que_rec.validation_type in ['must_be_decimal_number']: - type = "float" - elif que_rec.validation_type in ['must_be_date']: - type = "date" - for ans in ans_ids: - etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'width':"300",'colspan': '1','name': tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"}) - if type == "char" : - fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"] = {'type':'char', 'size':255, 'string':ans.answer} + col = "4" + colspan = "4" else: - fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"] = {'type': str(type), 'string':ans.answer} + col = "2" + colspan = "2" + xml_group = etree.SubElement(xml_group, 'group', {'col': tools.ustr(col), 'colspan': tools.ustr(colspan)}) + for row in ans_ids: + etree.SubElement(xml_group, 'newline') + etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'name': tools.ustr(que.id) + "_selection_" + tools.ustr(row.id),'string':to_xml(tools.ustr(row.answer))}) + selection = [('','')] + for col in que_rec.column_heading_ids: + selection.append((str(col.id), col.title)) + fields[tools.ustr(que.id) + "_selection_" + tools.ustr(row.id)] = {'type':'selection', 'selection' : selection, 'string': "Answer"} + if que_rec.comment_column: + fields[tools.ustr(que.id) + "_commentcolumn_"+tools.ustr(row.id) + "_field"] = {'type':'char', 'size' : 255, 'string':tools.ustr(que_rec.column_name), 'views':{}} + etree.SubElement(xml_group, 'field', {'readonly' :str(readonly), 'name': tools.ustr(que.id) + "_commentcolumn_"+tools.ustr(row.id)+ "_field"}) - elif que_rec.type == 'numerical_textboxes': - xml_group = etree.SubElement(xml_group, 'group', {'col': '4', 'colspan': '4'}) - for ans in ans_ids: - etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'width':"300",'colspan': '1','name': tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_numeric"}) - fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_numeric"] = {'type':'integer', 'string':ans.answer} - - elif que_rec.type == 'date': - xml_group = etree.SubElement(xml_group, 'group', {'col': '4', 'colspan': '4'}) - for ans in ans_ids: - etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'width':"300",'colspan': '1','name': tools.ustr(que.id) + "_" + tools.ustr(ans.id)}) - fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id)] = {'type':'date', 'string':ans.answer} - - elif que_rec.type == 'date_and_time': - xml_group = etree.SubElement(xml_group, 'group', {'col': '4', 'colspan': '4'}) - for ans in ans_ids: - etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'width':"300",'colspan': '1','name': tools.ustr(que.id) + "_" + tools.ustr(ans.id)}) - fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id)] = {'type':'datetime', 'string':ans.answer} - - elif que_rec.type == 'descriptive_text': - if que_rec.descriptive_text: - for que_test in que_rec.descriptive_text.split('\n'): - etree.SubElement(xml_group, 'label', {'string': to_xml(tools.ustr(que_test)), 'align':"0.0"}) - - elif que_rec.type == 'single_textbox': - etree.SubElement(xml_group, 'field', {'readonly' :str(readonly), 'name': tools.ustr(que.id) + "_single", 'nolabel':"1" ,'colspan':"4"}) - fields[tools.ustr(que.id) + "_single"] = {'type':'char', 'size': 255, 'string':"single_textbox", 'views':{}} - - elif que_rec.type == 'comment': - etree.SubElement(xml_group, 'field', {'readonly' :str(readonly), 'name': tools.ustr(que.id) + "_comment", 'nolabel':"1" ,'colspan':"4"}) - fields[tools.ustr(que.id) + "_comment"] = {'type':'text', 'string':"Comment/Eassy Box", 'views':{}} - - elif que_rec.type == 'table': - xml_group = etree.SubElement(xml_group, 'group', {'col': str(len(que_rec.column_heading_ids)), 'colspan': '4'}) - for col in que_rec.column_heading_ids: - etree.SubElement(xml_group, 'separator', {'string': tools.ustr(col.title),'colspan': '1'}) - for row in range(0,que_rec.no_of_rows): + elif que_rec.type == 'matrix_of_choices_only_multi_ans': + xml_group = etree.SubElement(xml_group, 'group', {'col': str(len(que_rec.column_heading_ids) + 1), 'colspan': '4'}) + etree.SubElement(xml_group, 'separator', {'string': '.','colspan': '1'}) for col in que_rec.column_heading_ids: - etree.SubElement(xml_group, 'field', {'readonly' :str(readonly), 'name': tools.ustr(que.id) + "_table_" + tools.ustr(col.id) +"_"+ tools.ustr(row), 'nolabel':"1"}) - fields[tools.ustr(que.id) + "_table_" + tools.ustr(col.id) +"_"+ tools.ustr(row)] = {'type':'char','size':255,'views':{}} + etree.SubElement(xml_group, 'separator', {'string': tools.ustr(col.title),'colspan': '1'}) + for row in ans_ids: + etree.SubElement(xml_group, 'label', {'string': to_xml(tools.ustr(row.answer)) +' :-', 'align': '0.0'}) + for col in que_col_head.browse(cr, uid, [head.id for head in que_rec.column_heading_ids]): + etree.SubElement(xml_group, 'field', {'readonly' :str(readonly), 'name': tools.ustr(que.id) + "_" + tools.ustr(row.id) + "_" + tools.ustr(col.id), 'nolabel':"1"}) + fields[tools.ustr(que.id) + "_" + tools.ustr(row.id) + "_" + tools.ustr(col.id)] = {'type':'boolean', 'string': col.title} - elif que_rec.type == 'multiple_textboxes_diff_type': - xml_group = etree.SubElement(xml_group, 'group', {'col': '4', 'colspan': '4'}) - for ans in ans_ids: - if ans.type == "email" : - fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"] = {'type':'char', 'size':255, 'string':ans.answer} - etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'widget':'email','width':"300",'colspan': '1','name': tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"}) - else: + elif que_rec.type == 'multiple_textboxes': + xml_group = etree.SubElement(xml_group, 'group', {'col': '4', 'colspan': '4'}) + type = "char" + if que_rec.is_validation_require: + if que_rec.validation_type in ['must_be_whole_number']: + type = "integer" + elif que_rec.validation_type in ['must_be_decimal_number']: + type = "float" + elif que_rec.validation_type in ['must_be_date']: + type = "date" + for ans in ans_ids: etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'width':"300",'colspan': '1','name': tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"}) - if ans.type == "char" : + if type == "char" : fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"] = {'type':'char', 'size':255, 'string':ans.answer} - elif ans.type in ['integer','float','date','datetime']: - fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"] = {'type': str(ans.type), 'string':ans.answer} else: - selection = [] - if ans.menu_choice: - for item in ans.menu_choice.split('\n'): - if item and not item.strip() == '': selection.append((item ,item)) - fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"] = {'type':'selection', 'selection' : selection, 'string':ans.answer} + fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"] = {'type': str(type), 'string':ans.answer} - if que_rec.type in ['multiple_choice_only_one_ans', 'multiple_choice_multiple_ans', 'matrix_of_choices_only_one_ans', 'matrix_of_choices_only_multi_ans', 'rating_scale'] and que_rec.is_comment_require: - if que_rec.type in ['multiple_choice_only_one_ans', 'multiple_choice_multiple_ans'] and que_rec.comment_field_type in ['char','text'] and que_rec.make_comment_field: - etree.SubElement(xml_group, 'field', {'readonly' :str(readonly), 'name': tools.ustr(que.id) + "_otherfield", 'colspan':"4"}) - fields[tools.ustr(que.id) + "_otherfield"] = {'type':'boolean', 'string':que_rec.comment_label, 'views':{}} - if que_rec.comment_field_type == 'char': - etree.SubElement(xml_group, 'field', {'readonly' :str(readonly), 'name': tools.ustr(que.id) + "_other", 'nolabel':"1" ,'colspan':"4"}) - fields[tools.ustr(que.id) + "_other"] = {'type': 'char', 'string': '', 'size':255, 'views':{}} - elif que_rec.comment_field_type == 'text': - etree.SubElement(xml_group, 'field', {'readonly' :str(readonly), 'name': tools.ustr(que.id) + "_other", 'nolabel':"1" ,'colspan':"4"}) - fields[tools.ustr(que.id) + "_other"] = {'type': 'text', 'string': '', 'views':{}} - else: - if que_rec.comment_field_type == 'char': - etree.SubElement(xml_group, 'label', {'string': to_xml(tools.ustr(que_rec.comment_label)),'colspan':"4"}) - etree.SubElement(xml_group, 'field', {'readonly' :str(readonly), 'name': tools.ustr(que.id) + "_other", 'nolabel':"1" ,'colspan':"4"}) - fields[tools.ustr(que.id) + "_other"] = {'type': 'char', 'string': '', 'size':255, 'views':{}} - elif que_rec.comment_field_type == 'text': - etree.SubElement(xml_group, 'label', {'string': to_xml(tools.ustr(que_rec.comment_label)),'colspan':"4"}) - etree.SubElement(xml_group, 'field', {'readonly' :str(readonly), 'name': tools.ustr(que.id) + "_other", 'nolabel':"1" ,'colspan':"4"}) - fields[tools.ustr(que.id) + "_other"] = {'type': 'text', 'string': '', 'views':{}} + elif que_rec.type == 'numerical_textboxes': + xml_group = etree.SubElement(xml_group, 'group', {'col': '4', 'colspan': '4'}) + for ans in ans_ids: + etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'width':"300",'colspan': '1','name': tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_numeric"}) + fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_numeric"] = {'type':'integer', 'string':ans.answer} - xml_footer = etree.SubElement(xml_form, 'footer', {'col': '8', 'colspan': '1', 'width':"100%"}) + elif que_rec.type == 'date': + xml_group = etree.SubElement(xml_group, 'group', {'col': '4', 'colspan': '4'}) + for ans in ans_ids: + etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'width':"300",'colspan': '1','name': tools.ustr(que.id) + "_" + tools.ustr(ans.id)}) + fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id)] = {'type':'date', 'string':ans.answer} - if pre_button: - etree.SubElement(xml_footer, 'label', {'string': ""}) - etree.SubElement(xml_footer, 'button', {'name':"action_previous",'string':"Previous",'type':"object"}) - but_string = "Next" - if int(page_number) + 1 == total_pages: - but_string = "Done" - if context.has_key('active') and context.get('active',False) and int(page_number) + 1 == total_pages and context.has_key('response_id') and context.has_key('response_no') and context.get('response_no',0) + 1 == len(context.get('response_id',0)): - etree.SubElement(xml_footer, 'label', {'string': ""}) - etree.SubElement(xml_footer, 'button', {'special' : 'cancel','string': tools.ustr("Done") ,'context' : tools.ustr(context), 'class':"oe_highlight"}) - elif context.has_key('active') and context.get('active', False) and int(page_number) + 1 == total_pages and context.has_key('response_id'): - etree.SubElement(xml_footer, 'label', {'string': ""}) - etree.SubElement(xml_footer, 'button', {'name':"action_forward_next",'string': tools.ustr("Next Answer") ,'type':"object",'context' : tools.ustr(context), 'class':"oe_highlight"}) - elif context.has_key('active') and context.get('active',False) and int(page_number) + 1 == total_pages: - etree.SubElement(xml_footer, 'label', {'string': ""}) - etree.SubElement(xml_footer, 'button', {'special': "cancel", 'string' : 'Done', 'context' : tools.ustr(context), 'class':"oe_highlight"}) + elif que_rec.type == 'date_and_time': + xml_group = etree.SubElement(xml_group, 'group', {'col': '4', 'colspan': '4'}) + for ans in ans_ids: + etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'width':"300",'colspan': '1','name': tools.ustr(que.id) + "_" + tools.ustr(ans.id)}) + fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id)] = {'type':'datetime', 'string':ans.answer} + + elif que_rec.type == 'descriptive_text': + if que_rec.descriptive_text: + for que_test in que_rec.descriptive_text.split('\n'): + etree.SubElement(xml_group, 'label', {'string': to_xml(tools.ustr(que_test)), 'align':"0.0"}) + + elif que_rec.type == 'single_textbox': + etree.SubElement(xml_group, 'field', {'readonly' :str(readonly), 'name': tools.ustr(que.id) + "_single", 'nolabel':"1" ,'colspan':"4"}) + fields[tools.ustr(que.id) + "_single"] = {'type':'char', 'size': 255, 'string':"single_textbox", 'views':{}} + + elif que_rec.type == 'comment': + etree.SubElement(xml_group, 'field', {'readonly' :str(readonly), 'name': tools.ustr(que.id) + "_comment", 'nolabel':"1" ,'colspan':"4"}) + fields[tools.ustr(que.id) + "_comment"] = {'type':'text', 'string':"Comment/Eassy Box", 'views':{}} + + elif que_rec.type == 'table': + xml_group = etree.SubElement(xml_group, 'group', {'col': str(len(que_rec.column_heading_ids)), 'colspan': '4'}) + for col in que_rec.column_heading_ids: + etree.SubElement(xml_group, 'separator', {'string': tools.ustr(col.title),'colspan': '1'}) + for row in range(0,que_rec.no_of_rows): + for col in que_rec.column_heading_ids: + etree.SubElement(xml_group, 'field', {'readonly' :str(readonly), 'name': tools.ustr(que.id) + "_table_" + tools.ustr(col.id) +"_"+ tools.ustr(row), 'nolabel':"1"}) + fields[tools.ustr(que.id) + "_table_" + tools.ustr(col.id) +"_"+ tools.ustr(row)] = {'type':'char','size':255,'views':{}} + + elif que_rec.type == 'multiple_textboxes_diff_type': + xml_group = etree.SubElement(xml_group, 'group', {'col': '4', 'colspan': '4'}) + for ans in ans_ids: + if ans.type == "email" : + fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"] = {'type':'char', 'size':255, 'string':ans.answer} + etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'widget':'email','width':"300",'colspan': '1','name': tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"}) + else: + etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'width':"300",'colspan': '1','name': tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"}) + if ans.type == "char" : + fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"] = {'type':'char', 'size':255, 'string':ans.answer} + elif ans.type in ['integer','float','date','datetime']: + fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"] = {'type': str(ans.type), 'string':ans.answer} + else: + selection = [] + if ans.menu_choice: + for item in ans.menu_choice.split('\n'): + if item and not item.strip() == '': selection.append((item ,item)) + fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"] = {'type':'selection', 'selection' : selection, 'string':ans.answer} + + if que_rec.type in ['multiple_choice_only_one_ans', 'multiple_choice_multiple_ans', 'matrix_of_choices_only_one_ans', 'matrix_of_choices_only_multi_ans', 'rating_scale'] and que_rec.is_comment_require: + if que_rec.type in ['multiple_choice_only_one_ans', 'multiple_choice_multiple_ans'] and que_rec.comment_field_type in ['char','text'] and que_rec.make_comment_field: + etree.SubElement(xml_group, 'field', {'readonly' :str(readonly), 'name': tools.ustr(que.id) + "_otherfield", 'colspan':"4"}) + fields[tools.ustr(que.id) + "_otherfield"] = {'type':'boolean', 'string':que_rec.comment_label, 'views':{}} + if que_rec.comment_field_type == 'char': + etree.SubElement(xml_group, 'field', {'readonly' :str(readonly), 'name': tools.ustr(que.id) + "_other", 'nolabel':"1" ,'colspan':"4"}) + fields[tools.ustr(que.id) + "_other"] = {'type': 'char', 'string': '', 'size':255, 'views':{}} + elif que_rec.comment_field_type == 'text': + etree.SubElement(xml_group, 'field', {'readonly' :str(readonly), 'name': tools.ustr(que.id) + "_other", 'nolabel':"1" ,'colspan':"4"}) + fields[tools.ustr(que.id) + "_other"] = {'type': 'text', 'string': '', 'views':{}} + else: + if que_rec.comment_field_type == 'char': + etree.SubElement(xml_group, 'label', {'string': to_xml(tools.ustr(que_rec.comment_label)),'colspan':"4"}) + etree.SubElement(xml_group, 'field', {'readonly' :str(readonly), 'name': tools.ustr(que.id) + "_other", 'nolabel':"1" ,'colspan':"4"}) + fields[tools.ustr(que.id) + "_other"] = {'type': 'char', 'string': '', 'size':255, 'views':{}} + elif que_rec.comment_field_type == 'text': + etree.SubElement(xml_group, 'label', {'string': to_xml(tools.ustr(que_rec.comment_label)),'colspan':"4"}) + etree.SubElement(xml_group, 'field', {'readonly' :str(readonly), 'name': tools.ustr(que.id) + "_other", 'nolabel':"1" ,'colspan':"4"}) + fields[tools.ustr(que.id) + "_other"] = {'type': 'text', 'string': '', 'views':{}} + + xml_footer = etree.SubElement(xml_form, 'footer', {'col': '8', 'colspan': '1', 'width':"100%"}) + + if pre_button: + etree.SubElement(xml_footer, 'label', {'string': ""}) + etree.SubElement(xml_footer, 'button', {'name':"action_previous",'string':"Previous",'type':"object"}) + but_string = "Next" + if int(page_number) + 1 == total_pages: + but_string = "Done" + if context.has_key('active') and context.get('active',False) and int(page_number) + 1 == total_pages and context.has_key('response_id') and context.has_key('response_no') and context.get('response_no',0) + 1 == len(context.get('response_id',0)): + etree.SubElement(xml_footer, 'label', {'string': ""}) + etree.SubElement(xml_footer, 'button', {'special' : 'cancel','string': tools.ustr("Done") ,'context' : tools.ustr(context), 'class':"oe_highlight"}) + elif context.has_key('active') and context.get('active', False) and int(page_number) + 1 == total_pages and context.has_key('response_id'): + etree.SubElement(xml_footer, 'label', {'string': ""}) + etree.SubElement(xml_footer, 'button', {'name':"action_forward_next",'string': tools.ustr("Next Answer") ,'type':"object",'context' : tools.ustr(context), 'class':"oe_highlight"}) + elif context.has_key('active') and context.get('active',False) and int(page_number) + 1 == total_pages: + etree.SubElement(xml_footer, 'label', {'string': ""}) + etree.SubElement(xml_footer, 'button', {'special': "cancel", 'string' : 'Done', 'context' : tools.ustr(context), 'class':"oe_highlight"}) + else: + etree.SubElement(xml_footer, 'label', {'string': ""}) + etree.SubElement(xml_footer, 'button', {'name':"action_next",'string': tools.ustr(but_string) ,'type':"object",'context' : tools.ustr(context), 'class':"oe_highlight"}) + if context.get('ir_actions_act_window_target', None): + etree.SubElement(xml_footer, 'label', {'string': "or"}) + etree.SubElement(xml_footer, 'button', {'special': "cancel",'string':"Exit",'class':"oe_link"}) + etree.SubElement(xml_footer, 'label', {'string': tools.ustr(page_number+ 1) + "/" + tools.ustr(total_pages), 'class':"oe_survey_title_page oe_right"}) + + root = xml_form.getroottree() + result['arch'] = etree.tostring(root) + result['fields'] = fields + result['context'] = context + + # survey complete else: - etree.SubElement(xml_footer, 'label', {'string': ""}) - etree.SubElement(xml_footer, 'button', {'name':"action_next",'string': tools.ustr(but_string) ,'type':"object",'context' : tools.ustr(context), 'class':"oe_highlight"}) - if context.get('ir_actions_act_window_target', None): - etree.SubElement(xml_footer, 'label', {'string': "or"}) - etree.SubElement(xml_footer, 'button', {'special': "cancel",'string':"Exit",'class':"oe_link"}) - etree.SubElement(xml_footer, 'label', {'string': tools.ustr(page_number+ 1) + "/" + tools.ustr(total_pages), 'class':"oe_survey_title_page oe_right"}) + survey_obj.write(cr, uid, survey_id, {'tot_comp_survey' : sur_rec.tot_comp_survey + 1}) + sur_response_obj.write(cr, uid, [sur_name_read.response], {'state' : 'done'}) - root = xml_form.getroottree() - result['arch'] = etree.tostring(root) - result['fields'] = fields - result['context'] = context + if sur_rec.send_response: + survey_data = survey_obj.browse(cr, uid, survey_id) + response_id = surv_name_wiz.read(cr, uid, context.get('sur_name_id',False))['response'] + report = self.create_report(cr, uid, [survey_id], 'report.survey.browse.response', survey_data.title,context) + attachments = {} + pdf_filename = addons.get_module_resource('survey', 'report') + survey_data.title + ".pdf" + if os.path.exists(pdf_filename): + file = open(pdf_filename) + file_data = "" + while 1: + line = file.readline() + file_data += line + if not line: + break + + attachments[survey_data.title + ".pdf"] = file_data + file.close() + os.remove(addons.get_module_resource('survey', 'report') + survey_data.title + ".pdf") + context.update({'response_id':response_id}) + partner_email = user_browse.email + resp_email = survey_data.responsible_id and survey_data.responsible_id.email or False + + if partner_email and resp_email: + partner_name = partner_obj.browse(cr, uid, uid, context=context).name + mail = "Hello " + survey_data.responsible_id.name + ",\n\n " + str(partner_name) + " has given the Response Of " + survey_data.title + " Survey.\nThe Response has been attached herewith.\n\n Thanks." + vals = {'state': 'outgoing', + 'subject': "Survey Answer Of " + partner_name, + 'body_html': '
%s
' % mail, + 'email_to': [resp_email], + 'email_from': partner_email} + if attachments: + vals['attachment_ids'] = [(0,0,{'name': a_name, + 'datas_fname': a_name, + 'datas': str(a_content).encode('base64')}) + for a_name, a_content in attachments.items()] + self.pool.get('mail.mail').create(cr, uid, vals, context=context) + + xml_form = etree.Element('form', {'string': _('Complete Survey Answer')}) + xml_footer = etree.SubElement(xml_form, 'footer', {'col': '6', 'colspan': '4' ,'class': 'oe_survey_title_height'}) + + etree.SubElement(xml_form, 'separator', {'string': 'Survey Completed', 'colspan': "4"}) + etree.SubElement(xml_form, 'label', {'string': 'Thanks for your Answer'}) + etree.SubElement(xml_form, 'newline') + # etree.SubElement(xml_footer, 'button', {'special':"cancel",'string':"OK",'colspan':"2",'class':'oe_highlight'}) + root = xml_form.getroottree() + result['arch'] = etree.tostring(root) + result['fields'] = {} + result['context'] = context + + # don't have acces to this survey else: - survey_obj.write(cr, uid, survey_id, {'tot_comp_survey' : sur_rec.tot_comp_survey + 1}) - sur_response_obj.write(cr, uid, [sur_name_read.response], {'state' : 'done'}) - - # mark the survey request as done; call 'survey_req_done' on its actual model - survey_req_obj = self.pool.get(context.get('active_model')) - if survey_req_obj and hasattr(survey_req_obj, 'survey_req_done'): - survey_req_obj.survey_req_done(cr, uid, context.get('active_ids', []), context=context) - - if sur_rec.send_response: - survey_data = survey_obj.browse(cr, uid, survey_id) - response_id = surv_name_wiz.read(cr, uid, context.get('sur_name_id',False))['response'] - report = self.create_report(cr, uid, [survey_id], 'report.survey.browse.response', survey_data.title,context) - attachments = {} - pdf_filename = addons.get_module_resource('survey', 'report') + survey_data.title + ".pdf" - if os.path.exists(pdf_filename): - file = open(pdf_filename) - file_data = "" - while 1: - line = file.readline() - file_data += line - if not line: - break - - attachments[survey_data.title + ".pdf"] = file_data - file.close() - os.remove(addons.get_module_resource('survey', 'report') + survey_data.title + ".pdf") - context.update({'response_id':response_id}) - partner_email = user_obj.browse(cr, uid, uid, context).email - resp_email = survey_data.responsible_id and survey_data.responsible_id.email or False - - if partner_email and resp_email: - partner_name = partner_obj.browse(cr, uid, uid, context=context).name - mail = "Hello " + survey_data.responsible_id.name + ",\n\n " + str(partner_name) + " has given the Response Of " + survey_data.title + " Survey.\nThe Response has been attached herewith.\n\n Thanks." - vals = {'state': 'outgoing', - 'subject': "Survey Answer Of " + partner_name, - 'body_html': '
%s
' % mail, - 'email_to': [resp_email], - 'email_from': partner_email} - if attachments: - vals['attachment_ids'] = [(0,0,{'name': a_name, - 'datas_fname': a_name, - 'datas': str(a_content).encode('base64')}) - for a_name, a_content in attachments.items()] - self.pool.get('mail.mail').create(cr, uid, vals, context=context) - - xml_form = etree.Element('form', {'string': _('Complete Survey Answer')}) - xml_footer = etree.SubElement(xml_form, 'footer', {'col': '6', 'colspan': '4' ,'class': 'oe_survey_title_height'}) - - etree.SubElement(xml_form, 'separator', {'string': 'Survey Completed', 'colspan': "4"}) - etree.SubElement(xml_form, 'label', {'string': 'Thanks for your Answer'}) + xml_form = etree.Element('form', {'string': _('No access to this survey')}) + etree.SubElement(xml_form, 'separator', {'string': sur_rec.title, 'colspan': "4"}) + etree.SubElement(xml_form, 'label', {'string': "You don't have access to this survey."}) etree.SubElement(xml_form, 'newline') - etree.SubElement(xml_footer, 'button', {'special':"cancel",'string':"OK",'colspan':"2",'class':'oe_highlight'}) + etree.SubElement(xml_form, 'label', {'string': "The access you have not been given or the deadline has passed."}) root = xml_form.getroottree() result['arch'] = etree.tostring(root) result['fields'] = {} result['context'] = context + return result def create_report(self, cr, uid, res_ids, report_name=False, file_name=False, context=None): diff --git a/addons/survey/wizard/survey_selection.py b/addons/survey/wizard/survey_selection.py index 0c9f4d85866..1a84d3c5d5e 100644 --- a/addons/survey/wizard/survey_selection.py +++ b/addons/survey/wizard/survey_selection.py @@ -49,7 +49,7 @@ class survey_name_wiz(osv.osv_memory): res = super(survey_name_wiz, self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar, submenu=False) if uid != 1: survey_obj = self.pool.get('survey') - line_ids = survey_obj.search(cr, uid, [('invited_partner_ids','in',uid)], context=context) + line_ids = survey_obj.search(cr, uid, [('invited_partner_ids.user_id','in',uid)], context=context) domain = str([('id', 'in', line_ids)]) doc = etree.XML(res['arch']) nodes = doc.xpath("//field[@name='survey_id']") From 1aa5a49071fe6f25c6a887fb897dc4e05aa95903 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Thu, 14 Feb 2013 10:39:15 +0100 Subject: [PATCH 0024/1010] [IMP] survey: simplify python: functions for the different views bzr revid: chm@openerp.com-20130214093915-l71zi9ijmagytrv4 --- addons/survey/wizard/survey_answer.py | 288 +++++++++++++------------- 1 file changed, 145 insertions(+), 143 deletions(-) diff --git a/addons/survey/wizard/survey_answer.py b/addons/survey/wizard/survey_answer.py index a0ac9d87064..1f99c8f3df4 100644 --- a/addons/survey/wizard/survey_answer.py +++ b/addons/survey/wizard/survey_answer.py @@ -38,6 +38,144 @@ class survey_question_wiz(osv.osv_memory): 'name': fields.integer('Number'), } + def _view_multiple_choice_only_one_ans(self, xml_group, fields, readonly, que, que_rec): + selection = [] + for ans in que_rec.answer_choice_ids: + selection.append((tools.ustr(ans.id), ans.answer)) + xml_group = etree.SubElement(xml_group, 'group', {'col': '2', 'colspan': '2'}) + etree.SubElement(xml_group, 'field', {'readonly':str(readonly), 'name': tools.ustr(que.id) + "_selection"}) + fields[tools.ustr(que.id) + "_selection"] = {'type':'selection', 'selection' :selection, 'string':"Answer"} + # TODO convert selection field into radio input + def _view_multiple_choice_multiple_ans(self, xml_group, fields, readonly, que, que_rec): + xml_group = etree.SubElement(xml_group, 'group', {'col': '4', 'colspan': '4'}) + for ans in que_rec.answer_choice_ids: + etree.SubElement(xml_group, 'field', {'readonly':str(readonly), 'name': tools.ustr(que.id) + "_" + tools.ustr(ans.id)}) + fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id)] = {'type':'boolean', 'string':ans.answer} + + def _view_matrix_of_choices_only_multi_ans(self, xml_group, fields, readonly, que, que_rec): + xml_group = etree.SubElement(xml_group, 'group', {'col': str(len(que_rec.column_heading_ids) + 1), 'colspan': '4'}) + etree.SubElement(xml_group, 'separator', {'string': '.','colspan': '1'}) + for col in que_rec.column_heading_ids: + etree.SubElement(xml_group, 'separator', {'string': tools.ustr(col.title),'colspan': '1'}) + for row in que_rec.answer_choice_ids: + etree.SubElement(xml_group, 'label', {'string': to_xml(tools.ustr(row.answer)) +' :-', 'align': '0.0'}) + for col in que_col_head.browse(cr, uid, [head.id for head in que_rec.column_heading_ids]): + etree.SubElement(xml_group, 'field', {'readonly' :str(readonly), 'name': tools.ustr(que.id) + "_" + tools.ustr(row.id) + "_" + tools.ustr(col.id), 'nolabel':"1"}) + fields[tools.ustr(que.id) + "_" + tools.ustr(row.id) + "_" + tools.ustr(col.id)] = {'type':'boolean', 'string': col.title} + + def _view_multiple_textboxes(self, xml_group, fields, readonly, que, que_rec): + xml_group = etree.SubElement(xml_group, 'group', {'col': '4', 'colspan': '4'}) + type = "char" + if que_rec.is_validation_require: + if que_rec.validation_type in ['must_be_whole_number']: + type = "integer" + elif que_rec.validation_type in ['must_be_decimal_number']: + type = "float" + elif que_rec.validation_type in ['must_be_date']: + type = "date" + for ans in que_rec.answer_choice_ids: + etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'width':"300",'colspan': '1','name': tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"}) + if type == "char" : + fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"] = {'type':'char', 'size':255, 'string':ans.answer} + else: + fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"] = {'type': str(type), 'string':ans.answer} + + def _view_numerical_textboxes(self, xml_group, fields, readonly, que, que_rec): + xml_group = etree.SubElement(xml_group, 'group', {'col': '4', 'colspan': '4'}) + for ans in que_rec.answer_choice_ids: + etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'width':"300",'colspan': '1','name': tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_numeric"}) + fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_numeric"] = {'type':'integer', 'string':ans.answer} + + def _view_date(self, xml_group, fields, readonly, que, que_rec): + xml_group = etree.SubElement(xml_group, 'group', {'col': '4', 'colspan': '4'}) + for ans in que_rec.answer_choice_ids: + etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'width':"300",'colspan': '1','name': tools.ustr(que.id) + "_" + tools.ustr(ans.id)}) + fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id)] = {'type':'date', 'string':ans.answer} + + def _view_date_and_time(self, xml_group, fields, readonly, que, que_rec): + xml_group = etree.SubElement(xml_group, 'group', {'col': '4', 'colspan': '4'}) + for ans in que_rec.answer_choice_ids: + etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'width':"300",'colspan': '1','name': tools.ustr(que.id) + "_" + tools.ustr(ans.id)}) + fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id)] = {'type':'datetime', 'string':ans.answer} + + def _view_descriptive_text(self, xml_group, fields, readonly, que, que_rec): + if que_rec.descriptive_text: + for que_test in que_rec.descriptive_text.split('\n'): + etree.SubElement(xml_group, 'label', {'string': to_xml(tools.ustr(que_test)), 'align':"0.0"}) + + def _view_single_textbox(self, xml_group, fields, readonly, que, que_rec): + etree.SubElement(xml_group, 'field', {'readonly' :str(readonly), 'name': tools.ustr(que.id) + "_single", 'nolabel':"1" ,'colspan':"4"}) + fields[tools.ustr(que.id) + "_single"] = {'type':'char', 'size': 255, 'string':"single_textbox", 'views':{}} + + def _view_comment(self, xml_group, fields, readonly, que, que_rec): + etree.SubElement(xml_group, 'field', {'readonly' :str(readonly), 'name': tools.ustr(que.id) + "_comment", 'nolabel':"1" ,'colspan':"4"}) + fields[tools.ustr(que.id) + "_comment"] = {'type':'text', 'string':"Comment/Eassy Box", 'views':{}} + + def _view_table(self, xml_group, fields, readonly, que, que_rec): + xml_group = etree.SubElement(xml_group, 'group', {'col': str(len(que_rec.column_heading_ids)), 'colspan': '4'}) + for col in que_rec.column_heading_ids: + etree.SubElement(xml_group, 'separator', {'string': tools.ustr(col.title),'colspan': '1'}) + for row in range(0,que_rec.no_of_rows): + for col in que_rec.column_heading_ids: + etree.SubElement(xml_group, 'field', {'readonly' :str(readonly), 'name': tools.ustr(que.id) + "_table_" + tools.ustr(col.id) +"_"+ tools.ustr(row), 'nolabel':"1"}) + fields[tools.ustr(que.id) + "_table_" + tools.ustr(col.id) +"_"+ tools.ustr(row)] = {'type':'char','size':255,'views':{}} + + def _view_multiple_textboxes_diff_type(self, xml_group, fields, readonly, que, que_rec): + xml_group = etree.SubElement(xml_group, 'group', {'col': '4', 'colspan': '4'}) + for ans in que_rec.answer_choice_ids: + if ans.type == "email" : + fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"] = {'type':'char', 'size':255, 'string':ans.answer} + etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'widget':'email','width':"300",'colspan': '1','name': tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"}) + else: + etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'width':"300",'colspan': '1','name': tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"}) + if ans.type == "char" : + fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"] = {'type':'char', 'size':255, 'string':ans.answer} + elif ans.type in ['integer','float','date','datetime']: + fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"] = {'type': str(ans.type), 'string':ans.answer} + else: + selection = [] + if ans.menu_choice: + for item in ans.menu_choice.split('\n'): + if item and not item.strip() == '': selection.append((item ,item)) + fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"] = {'type':'selection', 'selection' : selection, 'string':ans.answer} + + def _view_matrix_of_choices_only_one_ans(self, xml_group, fields, readonly, que, que_rec): + if que_rec.comment_column: + col = "4" + colspan = "4" + else: + col = "2" + colspan = "2" + xml_group = etree.SubElement(xml_group, 'group', {'col': tools.ustr(col), 'colspan': tools.ustr(colspan)}) + for row in que_rec.answer_choice_ids: + etree.SubElement(xml_group, 'newline') + etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'name': tools.ustr(que.id) + "_selection_" + tools.ustr(row.id),'string':to_xml(tools.ustr(row.answer))}) + selection = [('','')] + for col in que_rec.column_heading_ids: + selection.append((str(col.id), col.title)) + fields[tools.ustr(que.id) + "_selection_" + tools.ustr(row.id)] = {'type':'selection', 'selection' : selection, 'string': "Answer"} + if que_rec.comment_column: + fields[tools.ustr(que.id) + "_commentcolumn_"+tools.ustr(row.id) + "_field"] = {'type':'char', 'size' : 255, 'string':tools.ustr(que_rec.column_name), 'views':{}} + etree.SubElement(xml_group, 'field', {'readonly' :str(readonly), 'name': tools.ustr(que.id) + "_commentcolumn_"+tools.ustr(row.id)+ "_field"}) + + def _view_rating_scale(self, xml_group, fields, readonly, que, que_rec): + self._view_matrix_of_choices_only_one_ans(xml_group, fields, readonly, que, que_rec) + + + + def _view_after_matrix_of_choices(self, xml_group, fields, readonly, que, que_rec): + if que_rec.is_comment_require: + if que_rec.type in ['multiple_choice_only_one_ans', 'multiple_choice_multiple_ans'] and que_rec.comment_field_type in ['char','text'] and que_rec.make_comment_field: + etree.SubElement(xml_group, 'field', {'readonly' :str(readonly), 'name': tools.ustr(que.id) + "_otherfield", 'colspan':"4"}) + fields[tools.ustr(que.id) + "_otherfield"] = {'type':'boolean', 'string':que_rec.comment_label, 'views':{}} + etree.SubElement(xml_group, 'field', {'readonly' :str(readonly), 'name': tools.ustr(que.id) + "_other", 'nolabel':"1" ,'colspan':"4"}) + fields[tools.ustr(que.id) + "_other"] = {'type': que_rec.comment_field_type, 'string': '', 'views':{}} + else: + etree.SubElement(xml_group, 'label', {'string': to_xml(tools.ustr(que_rec.comment_label)),'colspan':"4"}) + etree.SubElement(xml_group, 'field', {'readonly' :str(readonly), 'name': tools.ustr(que.id) + "_other", 'nolabel':"1" ,'colspan':"4"}) + fields[tools.ustr(que.id) + "_other"] = {'type': que_rec.comment_field_type, 'string': '', 'views':{}} + + def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False): """ Fields View Get method :- generate the new view and display the survey pages of selected survey. @@ -224,149 +362,13 @@ class survey_question_wiz(osv.osv_memory): etree.SubElement(xml_form, 'newline') etree.SubElement(xml_form, 'separator', {'string': star+to_xml(separator_string)}) - ans_ids = que_rec.answer_choice_ids xml_group = etree.SubElement(xml_form, 'group', {'col': '1', 'colspan': '4'}) - # TODO convert selection field into radio input - if que_rec.type == 'multiple_choice_only_one_ans': - selection = [] - for ans in ans_ids: - selection.append((tools.ustr(ans.id), ans.answer)) - xml_group = etree.SubElement(xml_group, 'group', {'col': '2', 'colspan': '2'}) - etree.SubElement(xml_group, 'field', {'readonly':str(readonly), 'name': tools.ustr(que.id) + "_selection"}) - fields[tools.ustr(que.id) + "_selection"] = {'type':'selection', 'selection' :selection, 'string':"Answer"} - - elif que_rec.type == 'multiple_choice_multiple_ans': - xml_group = etree.SubElement(xml_group, 'group', {'col': '4', 'colspan': '4'}) - for ans in ans_ids: - etree.SubElement(xml_group, 'field', {'readonly':str(readonly), 'name': tools.ustr(que.id) + "_" + tools.ustr(ans.id)}) - fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id)] = {'type':'boolean', 'string':ans.answer} - - elif que_rec.type in ['matrix_of_choices_only_one_ans', 'rating_scale']: - if que_rec.comment_column: - col = "4" - colspan = "4" - else: - col = "2" - colspan = "2" - xml_group = etree.SubElement(xml_group, 'group', {'col': tools.ustr(col), 'colspan': tools.ustr(colspan)}) - for row in ans_ids: - etree.SubElement(xml_group, 'newline') - etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'name': tools.ustr(que.id) + "_selection_" + tools.ustr(row.id),'string':to_xml(tools.ustr(row.answer))}) - selection = [('','')] - for col in que_rec.column_heading_ids: - selection.append((str(col.id), col.title)) - fields[tools.ustr(que.id) + "_selection_" + tools.ustr(row.id)] = {'type':'selection', 'selection' : selection, 'string': "Answer"} - if que_rec.comment_column: - fields[tools.ustr(que.id) + "_commentcolumn_"+tools.ustr(row.id) + "_field"] = {'type':'char', 'size' : 255, 'string':tools.ustr(que_rec.column_name), 'views':{}} - etree.SubElement(xml_group, 'field', {'readonly' :str(readonly), 'name': tools.ustr(que.id) + "_commentcolumn_"+tools.ustr(row.id)+ "_field"}) - - elif que_rec.type == 'matrix_of_choices_only_multi_ans': - xml_group = etree.SubElement(xml_group, 'group', {'col': str(len(que_rec.column_heading_ids) + 1), 'colspan': '4'}) - etree.SubElement(xml_group, 'separator', {'string': '.','colspan': '1'}) - for col in que_rec.column_heading_ids: - etree.SubElement(xml_group, 'separator', {'string': tools.ustr(col.title),'colspan': '1'}) - for row in ans_ids: - etree.SubElement(xml_group, 'label', {'string': to_xml(tools.ustr(row.answer)) +' :-', 'align': '0.0'}) - for col in que_col_head.browse(cr, uid, [head.id for head in que_rec.column_heading_ids]): - etree.SubElement(xml_group, 'field', {'readonly' :str(readonly), 'name': tools.ustr(que.id) + "_" + tools.ustr(row.id) + "_" + tools.ustr(col.id), 'nolabel':"1"}) - fields[tools.ustr(que.id) + "_" + tools.ustr(row.id) + "_" + tools.ustr(col.id)] = {'type':'boolean', 'string': col.title} - - elif que_rec.type == 'multiple_textboxes': - xml_group = etree.SubElement(xml_group, 'group', {'col': '4', 'colspan': '4'}) - type = "char" - if que_rec.is_validation_require: - if que_rec.validation_type in ['must_be_whole_number']: - type = "integer" - elif que_rec.validation_type in ['must_be_decimal_number']: - type = "float" - elif que_rec.validation_type in ['must_be_date']: - type = "date" - for ans in ans_ids: - etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'width':"300",'colspan': '1','name': tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"}) - if type == "char" : - fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"] = {'type':'char', 'size':255, 'string':ans.answer} - else: - fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"] = {'type': str(type), 'string':ans.answer} - - elif que_rec.type == 'numerical_textboxes': - xml_group = etree.SubElement(xml_group, 'group', {'col': '4', 'colspan': '4'}) - for ans in ans_ids: - etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'width':"300",'colspan': '1','name': tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_numeric"}) - fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_numeric"] = {'type':'integer', 'string':ans.answer} - - elif que_rec.type == 'date': - xml_group = etree.SubElement(xml_group, 'group', {'col': '4', 'colspan': '4'}) - for ans in ans_ids: - etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'width':"300",'colspan': '1','name': tools.ustr(que.id) + "_" + tools.ustr(ans.id)}) - fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id)] = {'type':'date', 'string':ans.answer} - - elif que_rec.type == 'date_and_time': - xml_group = etree.SubElement(xml_group, 'group', {'col': '4', 'colspan': '4'}) - for ans in ans_ids: - etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'width':"300",'colspan': '1','name': tools.ustr(que.id) + "_" + tools.ustr(ans.id)}) - fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id)] = {'type':'datetime', 'string':ans.answer} - - elif que_rec.type == 'descriptive_text': - if que_rec.descriptive_text: - for que_test in que_rec.descriptive_text.split('\n'): - etree.SubElement(xml_group, 'label', {'string': to_xml(tools.ustr(que_test)), 'align':"0.0"}) - - elif que_rec.type == 'single_textbox': - etree.SubElement(xml_group, 'field', {'readonly' :str(readonly), 'name': tools.ustr(que.id) + "_single", 'nolabel':"1" ,'colspan':"4"}) - fields[tools.ustr(que.id) + "_single"] = {'type':'char', 'size': 255, 'string':"single_textbox", 'views':{}} - - elif que_rec.type == 'comment': - etree.SubElement(xml_group, 'field', {'readonly' :str(readonly), 'name': tools.ustr(que.id) + "_comment", 'nolabel':"1" ,'colspan':"4"}) - fields[tools.ustr(que.id) + "_comment"] = {'type':'text', 'string':"Comment/Eassy Box", 'views':{}} - - elif que_rec.type == 'table': - xml_group = etree.SubElement(xml_group, 'group', {'col': str(len(que_rec.column_heading_ids)), 'colspan': '4'}) - for col in que_rec.column_heading_ids: - etree.SubElement(xml_group, 'separator', {'string': tools.ustr(col.title),'colspan': '1'}) - for row in range(0,que_rec.no_of_rows): - for col in que_rec.column_heading_ids: - etree.SubElement(xml_group, 'field', {'readonly' :str(readonly), 'name': tools.ustr(que.id) + "_table_" + tools.ustr(col.id) +"_"+ tools.ustr(row), 'nolabel':"1"}) - fields[tools.ustr(que.id) + "_table_" + tools.ustr(col.id) +"_"+ tools.ustr(row)] = {'type':'char','size':255,'views':{}} - - elif que_rec.type == 'multiple_textboxes_diff_type': - xml_group = etree.SubElement(xml_group, 'group', {'col': '4', 'colspan': '4'}) - for ans in ans_ids: - if ans.type == "email" : - fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"] = {'type':'char', 'size':255, 'string':ans.answer} - etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'widget':'email','width':"300",'colspan': '1','name': tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"}) - else: - etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'width':"300",'colspan': '1','name': tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"}) - if ans.type == "char" : - fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"] = {'type':'char', 'size':255, 'string':ans.answer} - elif ans.type in ['integer','float','date','datetime']: - fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"] = {'type': str(ans.type), 'string':ans.answer} - else: - selection = [] - if ans.menu_choice: - for item in ans.menu_choice.split('\n'): - if item and not item.strip() == '': selection.append((item ,item)) - fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"] = {'type':'selection', 'selection' : selection, 'string':ans.answer} - + # rendering different views + getattr(self, "_view_%s" % que_rec.type)(xml_group, fields, readonly, que, que_rec) if que_rec.type in ['multiple_choice_only_one_ans', 'multiple_choice_multiple_ans', 'matrix_of_choices_only_one_ans', 'matrix_of_choices_only_multi_ans', 'rating_scale'] and que_rec.is_comment_require: - if que_rec.type in ['multiple_choice_only_one_ans', 'multiple_choice_multiple_ans'] and que_rec.comment_field_type in ['char','text'] and que_rec.make_comment_field: - etree.SubElement(xml_group, 'field', {'readonly' :str(readonly), 'name': tools.ustr(que.id) + "_otherfield", 'colspan':"4"}) - fields[tools.ustr(que.id) + "_otherfield"] = {'type':'boolean', 'string':que_rec.comment_label, 'views':{}} - if que_rec.comment_field_type == 'char': - etree.SubElement(xml_group, 'field', {'readonly' :str(readonly), 'name': tools.ustr(que.id) + "_other", 'nolabel':"1" ,'colspan':"4"}) - fields[tools.ustr(que.id) + "_other"] = {'type': 'char', 'string': '', 'size':255, 'views':{}} - elif que_rec.comment_field_type == 'text': - etree.SubElement(xml_group, 'field', {'readonly' :str(readonly), 'name': tools.ustr(que.id) + "_other", 'nolabel':"1" ,'colspan':"4"}) - fields[tools.ustr(que.id) + "_other"] = {'type': 'text', 'string': '', 'views':{}} - else: - if que_rec.comment_field_type == 'char': - etree.SubElement(xml_group, 'label', {'string': to_xml(tools.ustr(que_rec.comment_label)),'colspan':"4"}) - etree.SubElement(xml_group, 'field', {'readonly' :str(readonly), 'name': tools.ustr(que.id) + "_other", 'nolabel':"1" ,'colspan':"4"}) - fields[tools.ustr(que.id) + "_other"] = {'type': 'char', 'string': '', 'size':255, 'views':{}} - elif que_rec.comment_field_type == 'text': - etree.SubElement(xml_group, 'label', {'string': to_xml(tools.ustr(que_rec.comment_label)),'colspan':"4"}) - etree.SubElement(xml_group, 'field', {'readonly' :str(readonly), 'name': tools.ustr(que.id) + "_other", 'nolabel':"1" ,'colspan':"4"}) - fields[tools.ustr(que.id) + "_other"] = {'type': 'text', 'string': '', 'views':{}} + self._view_after_matrix_of_choices(xml_group, fields, readonly, que, que_rec) + xml_footer = etree.SubElement(xml_form, 'footer', {'col': '8', 'colspan': '1', 'width':"100%"}) @@ -603,13 +605,13 @@ class survey_question_wiz(osv.osv_memory): response_id = 0 if not sur_name_read['response']: - response_id = surv_all_resp_obj.create(cr, uid, {'response_type':'link', 'partner_id':partner_id, 'date_create':datetime.datetime.now(), 'survey_id' : context['survey_id']}) + response_id = surv_all_resp_obj.create(cr, uid, {'response_type':'link', 'partner_id':partner_id, 'date_create':datetime.now(), 'survey_id' : context['survey_id']}) surv_name_wiz.write(cr, uid, [context.get('sur_name_id', False)], {'response' : tools.ustr(response_id)}) else: response_id = int(sur_name_read['response']) if response_id not in surv_all_resp_obj.search(cr, uid, []): - response_id = surv_all_resp_obj.create(cr, uid, {'response_type':'link', 'partner_id':partner_id, 'date_create':datetime.datetime.now(), 'survey_id' : context.get('survey_id',False)}) + response_id = surv_all_resp_obj.create(cr, uid, {'response_type':'link', 'partner_id':partner_id, 'date_create':datetime.now(), 'survey_id' : context.get('survey_id',False)}) surv_name_wiz.write(cr, uid, [context.get('sur_name_id',False)], {'response' : tools.ustr(response_id)}) #click first time on next button then increemnet on total start suvey @@ -645,7 +647,7 @@ class survey_question_wiz(osv.osv_memory): que_rec = que_obj.read(cr, uid, [int(que_id)], [])[0] res_data = { 'question_id': que_id, - 'date_create': datetime.datetime.now(), + 'date_create': datetime.now(), 'state': 'done', 'response_id': response_id } From fa836b36e6ea10ee66ce3e8b67c832f3f2290341 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Thu, 14 Feb 2013 12:02:25 +0100 Subject: [PATCH 0025/1010] [IMP] survey: simplify python fields_view_get bzr revid: chm@openerp.com-20130214110225-cdhr6lbf5dssu5vp --- addons/survey/wizard/survey_answer.py | 107 +++++++++++--------------- 1 file changed, 44 insertions(+), 63 deletions(-) diff --git a/addons/survey/wizard/survey_answer.py b/addons/survey/wizard/survey_answer.py index 1f99c8f3df4..83b44594e70 100644 --- a/addons/survey/wizard/survey_answer.py +++ b/addons/survey/wizard/survey_answer.py @@ -38,7 +38,7 @@ class survey_question_wiz(osv.osv_memory): 'name': fields.integer('Number'), } - def _view_multiple_choice_only_one_ans(self, xml_group, fields, readonly, que, que_rec): + def _view_field_multiple_choice_only_one_ans(self, xml_group, fields, readonly, que, que_rec): selection = [] for ans in que_rec.answer_choice_ids: selection.append((tools.ustr(ans.id), ans.answer)) @@ -46,13 +46,13 @@ class survey_question_wiz(osv.osv_memory): etree.SubElement(xml_group, 'field', {'readonly':str(readonly), 'name': tools.ustr(que.id) + "_selection"}) fields[tools.ustr(que.id) + "_selection"] = {'type':'selection', 'selection' :selection, 'string':"Answer"} # TODO convert selection field into radio input - def _view_multiple_choice_multiple_ans(self, xml_group, fields, readonly, que, que_rec): + def _view_field_multiple_choice_multiple_ans(self, xml_group, fields, readonly, que, que_rec): xml_group = etree.SubElement(xml_group, 'group', {'col': '4', 'colspan': '4'}) for ans in que_rec.answer_choice_ids: etree.SubElement(xml_group, 'field', {'readonly':str(readonly), 'name': tools.ustr(que.id) + "_" + tools.ustr(ans.id)}) fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id)] = {'type':'boolean', 'string':ans.answer} - def _view_matrix_of_choices_only_multi_ans(self, xml_group, fields, readonly, que, que_rec): + def _view_field_matrix_of_choices_only_multi_ans(self, xml_group, fields, readonly, que, que_rec): xml_group = etree.SubElement(xml_group, 'group', {'col': str(len(que_rec.column_heading_ids) + 1), 'colspan': '4'}) etree.SubElement(xml_group, 'separator', {'string': '.','colspan': '1'}) for col in que_rec.column_heading_ids: @@ -63,7 +63,7 @@ class survey_question_wiz(osv.osv_memory): etree.SubElement(xml_group, 'field', {'readonly' :str(readonly), 'name': tools.ustr(que.id) + "_" + tools.ustr(row.id) + "_" + tools.ustr(col.id), 'nolabel':"1"}) fields[tools.ustr(que.id) + "_" + tools.ustr(row.id) + "_" + tools.ustr(col.id)] = {'type':'boolean', 'string': col.title} - def _view_multiple_textboxes(self, xml_group, fields, readonly, que, que_rec): + def _view_field_multiple_textboxes(self, xml_group, fields, readonly, que, que_rec): xml_group = etree.SubElement(xml_group, 'group', {'col': '4', 'colspan': '4'}) type = "char" if que_rec.is_validation_require: @@ -80,38 +80,38 @@ class survey_question_wiz(osv.osv_memory): else: fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"] = {'type': str(type), 'string':ans.answer} - def _view_numerical_textboxes(self, xml_group, fields, readonly, que, que_rec): + def _view_field_numerical_textboxes(self, xml_group, fields, readonly, que, que_rec): xml_group = etree.SubElement(xml_group, 'group', {'col': '4', 'colspan': '4'}) for ans in que_rec.answer_choice_ids: etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'width':"300",'colspan': '1','name': tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_numeric"}) fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_numeric"] = {'type':'integer', 'string':ans.answer} - def _view_date(self, xml_group, fields, readonly, que, que_rec): + def _view_field_date(self, xml_group, fields, readonly, que, que_rec): xml_group = etree.SubElement(xml_group, 'group', {'col': '4', 'colspan': '4'}) for ans in que_rec.answer_choice_ids: etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'width':"300",'colspan': '1','name': tools.ustr(que.id) + "_" + tools.ustr(ans.id)}) fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id)] = {'type':'date', 'string':ans.answer} - def _view_date_and_time(self, xml_group, fields, readonly, que, que_rec): + def _view_field_date_and_time(self, xml_group, fields, readonly, que, que_rec): xml_group = etree.SubElement(xml_group, 'group', {'col': '4', 'colspan': '4'}) for ans in que_rec.answer_choice_ids: etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'width':"300",'colspan': '1','name': tools.ustr(que.id) + "_" + tools.ustr(ans.id)}) fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id)] = {'type':'datetime', 'string':ans.answer} - def _view_descriptive_text(self, xml_group, fields, readonly, que, que_rec): + def _view_field_descriptive_text(self, xml_group, fields, readonly, que, que_rec): if que_rec.descriptive_text: for que_test in que_rec.descriptive_text.split('\n'): etree.SubElement(xml_group, 'label', {'string': to_xml(tools.ustr(que_test)), 'align':"0.0"}) - def _view_single_textbox(self, xml_group, fields, readonly, que, que_rec): + def _view_field_single_textbox(self, xml_group, fields, readonly, que, que_rec): etree.SubElement(xml_group, 'field', {'readonly' :str(readonly), 'name': tools.ustr(que.id) + "_single", 'nolabel':"1" ,'colspan':"4"}) fields[tools.ustr(que.id) + "_single"] = {'type':'char', 'size': 255, 'string':"single_textbox", 'views':{}} - def _view_comment(self, xml_group, fields, readonly, que, que_rec): + def _view_field_comment(self, xml_group, fields, readonly, que, que_rec): etree.SubElement(xml_group, 'field', {'readonly' :str(readonly), 'name': tools.ustr(que.id) + "_comment", 'nolabel':"1" ,'colspan':"4"}) fields[tools.ustr(que.id) + "_comment"] = {'type':'text', 'string':"Comment/Eassy Box", 'views':{}} - def _view_table(self, xml_group, fields, readonly, que, que_rec): + def _view_field_table(self, xml_group, fields, readonly, que, que_rec): xml_group = etree.SubElement(xml_group, 'group', {'col': str(len(que_rec.column_heading_ids)), 'colspan': '4'}) for col in que_rec.column_heading_ids: etree.SubElement(xml_group, 'separator', {'string': tools.ustr(col.title),'colspan': '1'}) @@ -120,7 +120,7 @@ class survey_question_wiz(osv.osv_memory): etree.SubElement(xml_group, 'field', {'readonly' :str(readonly), 'name': tools.ustr(que.id) + "_table_" + tools.ustr(col.id) +"_"+ tools.ustr(row), 'nolabel':"1"}) fields[tools.ustr(que.id) + "_table_" + tools.ustr(col.id) +"_"+ tools.ustr(row)] = {'type':'char','size':255,'views':{}} - def _view_multiple_textboxes_diff_type(self, xml_group, fields, readonly, que, que_rec): + def _view_field_multiple_textboxes_diff_type(self, xml_group, fields, readonly, que, que_rec): xml_group = etree.SubElement(xml_group, 'group', {'col': '4', 'colspan': '4'}) for ans in que_rec.answer_choice_ids: if ans.type == "email" : @@ -139,7 +139,7 @@ class survey_question_wiz(osv.osv_memory): if item and not item.strip() == '': selection.append((item ,item)) fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"] = {'type':'selection', 'selection' : selection, 'string':ans.answer} - def _view_matrix_of_choices_only_one_ans(self, xml_group, fields, readonly, que, que_rec): + def _view_field_matrix_of_choices_only_one_ans(self, xml_group, fields, readonly, que, que_rec): if que_rec.comment_column: col = "4" colspan = "4" @@ -158,23 +158,19 @@ class survey_question_wiz(osv.osv_memory): fields[tools.ustr(que.id) + "_commentcolumn_"+tools.ustr(row.id) + "_field"] = {'type':'char', 'size' : 255, 'string':tools.ustr(que_rec.column_name), 'views':{}} etree.SubElement(xml_group, 'field', {'readonly' :str(readonly), 'name': tools.ustr(que.id) + "_commentcolumn_"+tools.ustr(row.id)+ "_field"}) - def _view_rating_scale(self, xml_group, fields, readonly, que, que_rec): - self._view_matrix_of_choices_only_one_ans(xml_group, fields, readonly, que, que_rec) - - - - def _view_after_matrix_of_choices(self, xml_group, fields, readonly, que, que_rec): - if que_rec.is_comment_require: - if que_rec.type in ['multiple_choice_only_one_ans', 'multiple_choice_multiple_ans'] and que_rec.comment_field_type in ['char','text'] and que_rec.make_comment_field: - etree.SubElement(xml_group, 'field', {'readonly' :str(readonly), 'name': tools.ustr(que.id) + "_otherfield", 'colspan':"4"}) - fields[tools.ustr(que.id) + "_otherfield"] = {'type':'boolean', 'string':que_rec.comment_label, 'views':{}} - etree.SubElement(xml_group, 'field', {'readonly' :str(readonly), 'name': tools.ustr(que.id) + "_other", 'nolabel':"1" ,'colspan':"4"}) - fields[tools.ustr(que.id) + "_other"] = {'type': que_rec.comment_field_type, 'string': '', 'views':{}} - else: - etree.SubElement(xml_group, 'label', {'string': to_xml(tools.ustr(que_rec.comment_label)),'colspan':"4"}) - etree.SubElement(xml_group, 'field', {'readonly' :str(readonly), 'name': tools.ustr(que.id) + "_other", 'nolabel':"1" ,'colspan':"4"}) - fields[tools.ustr(que.id) + "_other"] = {'type': que_rec.comment_field_type, 'string': '', 'views':{}} + def _view_field_rating_scale(self, xml_group, fields, readonly, que, que_rec): + self._view_field_matrix_of_choices_only_one_ans(xml_group, fields, readonly, que, que_rec) + def _view_field_after_matrix_of_choices(self, xml_group, fields, readonly, que, que_rec): + if que_rec.type in ['multiple_choice_only_one_ans', 'multiple_choice_multiple_ans'] and que_rec.comment_field_type in ['char','text'] and que_rec.make_comment_field: + etree.SubElement(xml_group, 'field', {'readonly' :str(readonly), 'name': tools.ustr(que.id) + "_otherfield", 'colspan':"4"}) + fields[tools.ustr(que.id) + "_otherfield"] = {'type':'boolean', 'string':que_rec.comment_label, 'views':{}} + etree.SubElement(xml_group, 'field', {'readonly' :str(readonly), 'name': tools.ustr(que.id) + "_other", 'nolabel':"1" ,'colspan':"4"}) + fields[tools.ustr(que.id) + "_other"] = {'type': que_rec.comment_field_type, 'string': '', 'views':{}} + else: + etree.SubElement(xml_group, 'label', {'string': to_xml(tools.ustr(que_rec.comment_label)),'colspan':"4"}) + etree.SubElement(xml_group, 'field', {'readonly' :str(readonly), 'name': tools.ustr(que.id) + "_other", 'nolabel':"1" ,'colspan':"4"}) + fields[tools.ustr(que.id) + "_other"] = {'type': que_rec.comment_field_type, 'string': '', 'views':{}} def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False): """ @@ -255,14 +251,13 @@ class survey_question_wiz(osv.osv_memory): validate_response = sur_rec.responsible_id.id == uid or sur_response_obj.search(cr, uid, [('survey_id','=',survey_id), ('state','=','new'), '|', ('partner_id','=',user_browse.partner_id.id), ("token","=", context.get("survey_token", None)), '|', ('date_deadline','=',None), ('date_deadline','<',datetime.now())], context=context, limit=1) - #validate_response = None - + active = context.get('active', False) + # have acces to this survey if validate_response: if sur_name_read.page == "next" or sur_name_rec.page_no == -1: if total_pages > sur_name_rec.page_no + 1: - if ((context.has_key('active') and not context.get('active', False)) \ - or not context.has_key('active')) and not sur_name_rec.page_no + 1: + if not active and not sur_name_rec.page_no + 1: if sur_rec.state != "open" : raise osv.except_osv(_('Warning!'),_("You cannot answer because the survey is not open.")) cr.execute('select count(id) from survey_history where partner_id=%s\ @@ -298,16 +293,8 @@ class survey_question_wiz(osv.osv_memory): # survey in progress if flag: pag_rec = page_obj.browse(cr, uid, p_id, context=context) - note = False - question_ids = [] - if pag_rec: - title = pag_rec.title - note = pag_rec.note - question_ids = pag_rec.question_ids - else: - title = sur_rec.title - xml_form = etree.Element('form', {'string': tools.ustr(title)}) - if context.has_key('active') and context.get('active',False) and context.has_key('edit'): + xml_form = etree.Element('form', {'string': tools.ustr( pag_rec and pag_rec.title or sur_rec.title )}) + if active and context.get('edit'): context.update({'page_id' : tools.ustr(p_id),'page_number' : sur_name_rec.page_no , 'transfer' : sur_name_read.transfer}) xml_group3 = etree.SubElement(xml_form, 'group', {'col': '4', 'colspan': '4'}) etree.SubElement(xml_group3, 'button', {'string' :'Add Page','icon': "gtk-new", 'type' :'object','name':"action_new_page", 'context' : tools.ustr(context)}) @@ -318,8 +305,7 @@ class survey_question_wiz(osv.osv_memory): # FP Note xml_group = xml_form - if context.has_key('response_id') and context.get('response_id', False) \ - and int(context.get('response_id',0)[0]) > 0: + if context.get('response_id') and int(context.get('response_id',0)[0]) > 0: # TODO: l10n, cleanup this code to make it readable. Or template? xml_group = etree.SubElement(xml_form, 'group', {'col': '40', 'colspan': '4'}) record = sur_response_obj.browse(cr, uid, context['response_id'][context['response_no']]) @@ -334,24 +320,19 @@ class survey_question_wiz(osv.osv_memory): fields["wizardid_" + str(wiz_id)] = {'type':'char', 'size' : 255, 'string':"", 'views':{}} etree.SubElement(xml_form, 'field', {'invisible':'1','name': "wizardid_" + str(wiz_id),'default':str(lambda *a: 0),'modifiers':'{"invisible":true}'}) - if note: + if pag_rec and pag_rec.note: xml_group_note = etree.SubElement(xml_form, 'group', {'col': '1','colspan': '4'}) - for que_test in note.split('\n'): + for que_test in pag_rec.note.split('\n'): etree.SubElement(xml_group_note, 'label', {'string': to_xml(tools.ustr(que_test)), 'align':"0.0"}) - que_ids = question_ids + qu_no = 0 - - for que in que_ids: + for que in (pag_rec and pag_rec.question_ids or []): qu_no += 1 que_rec = que_obj.browse(cr, uid, que.id, context=context) descriptive_text = "" separator_string = tools.ustr(qu_no) + "." + tools.ustr(que_rec.question) - if ((context.has_key('active') and not context.get('active',False)) or not context.has_key('active')) and que_rec.is_require_answer: - star = '*' - else: - star = '' - if context.has_key('active') and context.get('active',False) and \ - context.has_key('edit'): + star = (not active and que_rec.is_require_answer) and '*' or '' + if active and context.get('edit'): etree.SubElement(xml_form, 'separator', {'string': star+to_xml(separator_string)}) xml_group1 = etree.SubElement(xml_form, 'group', {'col': '2', 'colspan': '2'}) @@ -365,9 +346,9 @@ class survey_question_wiz(osv.osv_memory): xml_group = etree.SubElement(xml_form, 'group', {'col': '1', 'colspan': '4'}) # rendering different views - getattr(self, "_view_%s" % que_rec.type)(xml_group, fields, readonly, que, que_rec) + getattr(self, "_view_field_%s" % que_rec.type)(xml_group, fields, readonly, que, que_rec) if que_rec.type in ['multiple_choice_only_one_ans', 'multiple_choice_multiple_ans', 'matrix_of_choices_only_one_ans', 'matrix_of_choices_only_multi_ans', 'rating_scale'] and que_rec.is_comment_require: - self._view_after_matrix_of_choices(xml_group, fields, readonly, que, que_rec) + self._view_field_after_matrix_of_choices(xml_group, fields, readonly, que, que_rec) xml_footer = etree.SubElement(xml_form, 'footer', {'col': '8', 'colspan': '1', 'width':"100%"}) @@ -378,13 +359,13 @@ class survey_question_wiz(osv.osv_memory): but_string = "Next" if int(page_number) + 1 == total_pages: but_string = "Done" - if context.has_key('active') and context.get('active',False) and int(page_number) + 1 == total_pages and context.has_key('response_id') and context.has_key('response_no') and context.get('response_no',0) + 1 == len(context.get('response_id',0)): + if active and int(page_number) + 1 == total_pages and context.get('response_id') and context.get('response_no',0) + 1 == len(context.get('response_id',0)): etree.SubElement(xml_footer, 'label', {'string': ""}) etree.SubElement(xml_footer, 'button', {'special' : 'cancel','string': tools.ustr("Done") ,'context' : tools.ustr(context), 'class':"oe_highlight"}) - elif context.has_key('active') and context.get('active', False) and int(page_number) + 1 == total_pages and context.has_key('response_id'): + elif active and int(page_number) + 1 == total_pages and context.get('response_id'): etree.SubElement(xml_footer, 'label', {'string': ""}) etree.SubElement(xml_footer, 'button', {'name':"action_forward_next",'string': tools.ustr("Next Answer") ,'type':"object",'context' : tools.ustr(context), 'class':"oe_highlight"}) - elif context.has_key('active') and context.get('active',False) and int(page_number) + 1 == total_pages: + elif active and int(page_number) + 1 == total_pages: etree.SubElement(xml_footer, 'label', {'string': ""}) etree.SubElement(xml_footer, 'button', {'special': "cancel", 'string' : 'Done', 'context' : tools.ustr(context), 'class':"oe_highlight"}) else: @@ -581,7 +562,7 @@ class survey_question_wiz(osv.osv_memory): if context is None: context = {} survey_question_wiz_id = super(survey_question_wiz,self).create(cr, uid, {'name': vals.get('name')}, context=context) - if context.has_key('active') and context.get('active',False): + if context.get('active',False): return survey_question_wiz_id for key,val in vals.items(): @@ -622,7 +603,7 @@ class survey_question_wiz(osv.osv_memory): sur_rec = survey_obj.read(cr, uid, survey_id) survey_obj.write(cr, uid, survey_id, {'tot_start_survey' : sur_rec['tot_start_survey'] + 1}) if context.has_key('cur_id'): - if context.has_key('request') and context.get('request',False): + if context.get('request',False): self.pool.get(context.get('object',False)).write(cr, uid, [int(context.get('cur_id',False))], {'response' : response_id}) self.pool.get(context.get('object',False)).survey_req_done(cr, uid, [int(context.get('cur_id'))], context) else: From 2a6c6fe59d32ac2efb776f2eaa956becf4417718 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Thu, 14 Feb 2013 13:37:35 +0100 Subject: [PATCH 0026/1010] [IMP] survey: add files survey_email_compose_message bzr revid: chm@openerp.com-20130214123735-tupku3yptayabkd5 --- .../wizard/survey_email_compose_message.py | 129 ++++++++++++++++++ .../wizard/survey_email_compose_message.xml | 64 +++++++++ 2 files changed, 193 insertions(+) create mode 100644 addons/survey/wizard/survey_email_compose_message.py create mode 100644 addons/survey/wizard/survey_email_compose_message.xml diff --git a/addons/survey/wizard/survey_email_compose_message.py b/addons/survey/wizard/survey_email_compose_message.py new file mode 100644 index 00000000000..75c29e9b604 --- /dev/null +++ b/addons/survey/wizard/survey_email_compose_message.py @@ -0,0 +1,129 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2010-Today OpenERP SA () +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see +# +############################################################################## + +import re +from openerp.osv import osv +from openerp.osv import fields +from datetime import datetime +from openerp.tools.translate import _ +import uuid + +class survey_mail_compose_message(osv.TransientModel): + _name = 'survey.mail.compose.message' + _inherit = 'mail.compose.message' + _description = 'Email composition wizard for Survey' + _log_access = True + + _columns = { + 'partner_ids': fields.many2many('res.partner', + 'survey_mail_compose_message_res_partner_rel', + 'wizard_id', 'partner_id', 'Additional contacts'), + 'attachment_ids': fields.many2many('ir.attachment', + 'survey_mail_compose_message_ir_attachments_rel', + 'wizard_id', 'attachment_id', 'Attachments'), + 'multi_email': fields.text(string='List of emails', help="This list of emails of recipients will not converted in partner. Emails separated by commas, semicolons or newline."), + 'date_deadline': fields.date(string="Deadline date", help=""), + } + #------------------------------------------------------ + # Wizard validation and send + #------------------------------------------------------ + + def send_mail(self, cr, uid, ids, context=None): + """ Process the wizard content and proceed with sending the related + email(s), rendering any template patterns on the fly if needed. """ + if context is None: + context = {} + + emails_split = re.compile(r"[;,\n\r]+") + survey_response_obj = self.pool.get('survey.response') + partner_obj = self.pool.get('res.partner') + user = self.pool.get('res.users').browse(cr, uid, uid, context=context) + + def send_mail_survey(wizard, token, partner_id, email): + """ Create one mail by recipients and replace __URL__ by link with identification token + """ + if not partner_id: + partner_id = partner_obj.search(cr, uid, [('email', '=', email)], context=context) + partner_id = partner_id and partner_id[0] or None + + survey_response_obj.create(cr, uid, { + 'date_deadline': wizard.date_deadline, + 'survey_id': wizard.res_id, + 'date_create': datetime.now(), + 'response_type': 'link', + 'state': 'new', + 'token': token, + 'partner_id': partner_id, + 'email': email, + }) + + post_values = { + 'subject': wizard.subject, + 'body_html': wizard.body.replace("__URL__", "#active_id=%s¶ms=%s" % (wizard.res_id, token)), + 'parent_id': None, + 'partner_ids': partner_id and [partner_id] or None, + 'attachments': attachments, + 'email_from': wizard.email_from or user.partner_id.email or None, + 'email_to': email, + 'notification': False, + } + print "" + print post_values + print "" + + + # # post the message + # active_model_pool.message_post(cr, uid, [res_id], type='comment', subtype='mt_comment', context=context, **post_values) + + + for wizard in self.browse(cr, uid, ids, context=context): + if wizard.model == 'survey': + + # default values, according to the wizard options + attachments = [(attach.datas_fname or attach.name, base64.b64decode(attach.datas)) for attach in wizard.attachment_ids] + + # check if __URL__ is in the text + if wizard.body.find("__URL__") < 0: + raise osv.except_osv(_('Warning!'),_("The content of the text don't contain '__URL__'. \ + __URL__ is automaticaly converted into the special url of the survey.")) + + emails = list(set(emails_split.split( wizard.multi_email or "")) - set([partner.email for partner in wizard.partner_ids])) + + # quick check of email list + emails_checked = [] + for email in emails: + email = email.strip() + if email: + if not re.search(r"^[^@]+@[^@]+$", email): + raise osv.except_osv(_('Warning!'),_("An email address is incorrect: '%s'" % email)) + else: + emails_checked.append(email) + if not len(emails_checked) and not len(wizard.partner_ids): + raise osv.except_osv(_('Warning!'),_("Please enter at least one recipient.")) + + for email in emails_checked: + send_mail_survey(wizard, uuid.uuid4(), None, email) + for partner in wizard.partner_ids: + send_mail_survey(wizard, uuid.uuid4(), partner.id, partner.email) + + return None + return {'type': 'ir.actions.act_window_close'} + diff --git a/addons/survey/wizard/survey_email_compose_message.xml b/addons/survey/wizard/survey_email_compose_message.xml new file mode 100644 index 00000000000..ca33b28968c --- /dev/null +++ b/addons/survey/wizard/survey_email_compose_message.xml @@ -0,0 +1,64 @@ + + + + + + + Survey - Send by Email + ${object.responsible_id and object.responsible_id.company_id and object.responsible_id.company_id.email or object.responsible_id.email or ''} + ${object.title} + ${object.lang} + + + +

Hello,

+

+ Would you please spent some of your time to fill-in our survey: + ${object.title} +

+ % if object.responsible_id: +

Thank you for choosing ${object.responsible_id.company_id.name or 'us'}!

+ % endif +
+ + ]]>
+
+ + + survey.mail.compose.message.form + survey.mail.compose.message + +
+ + + + + + + + + + + + +
+
+ +
+
+ +
+
From 6225565d51fd4bb81c2ca8ede304748eae395ee1 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Fri, 15 Feb 2013 09:43:51 +0100 Subject: [PATCH 0027/1010] [IMP] survey: in progress (+_survey_complete function) bzr revid: chm@openerp.com-20130215084351-dqq3mht6puj3yyz8 --- addons/survey/survey.py | 6 +- addons/survey/wizard/survey_answer.py | 107 +++++++++-------------- addons/survey/wizard/survey_selection.py | 18 ++-- 3 files changed, 55 insertions(+), 76 deletions(-) diff --git a/addons/survey/survey.py b/addons/survey/survey.py index 08b4f6459b0..fdb1818bd69 100644 --- a/addons/survey/survey.py +++ b/addons/survey/survey.py @@ -63,11 +63,11 @@ class survey(osv.osv): 'tot_comp_survey': fields.integer("Total Completed Survey", readonly=1), 'note': fields.text('Description', size=128), 'history': fields.one2many('survey.history', 'survey_id', 'History Lines', readonly=True), - 'partner_id': fields.many2many('res.partner', 'survey_partner_rel', 'sid', 'uid', 'Partners'), + 'partner_id': fields.many2many('res.partner', 'survey_partner_rel', 'sid', 'partner_id', 'Partners'), 'send_response': fields.boolean('Email Notification on Answer'), 'type': fields.many2one('survey.type', 'Type'), 'color': fields.integer('Color Index'), - 'invited_partner_ids': fields.many2many('res.partner', 'survey_invited_partner_rel', 'sid', 'uid', 'Invited User'), + 'invited_partner_ids': fields.many2many('res.partner', 'survey_invited_partner_rel', 'sid', 'partner_id', 'Invited User'), } _defaults = { 'state': lambda * a: "open", @@ -754,7 +754,7 @@ class res_partner(osv.osv): _inherit = "res.partner" _name = "res.partner" _columns = { - 'survey_id': fields.many2many('survey', 'survey_partner_rel', 'uid', 'sid', 'Groups'), + 'survey_id': fields.many2many('survey', 'survey_partner_rel', 'partner_id', 'sid', 'Groups'), } res_partner() diff --git a/addons/survey/wizard/survey_answer.py b/addons/survey/wizard/survey_answer.py index 83b44594e70..f8a4ff47f39 100644 --- a/addons/survey/wizard/survey_answer.py +++ b/addons/survey/wizard/survey_answer.py @@ -161,17 +161,42 @@ class survey_question_wiz(osv.osv_memory): def _view_field_rating_scale(self, xml_group, fields, readonly, que, que_rec): self._view_field_matrix_of_choices_only_one_ans(xml_group, fields, readonly, que, que_rec) - def _view_field_after_matrix_of_choices(self, xml_group, fields, readonly, que, que_rec): - if que_rec.type in ['multiple_choice_only_one_ans', 'multiple_choice_multiple_ans'] and que_rec.comment_field_type in ['char','text'] and que_rec.make_comment_field: - etree.SubElement(xml_group, 'field', {'readonly' :str(readonly), 'name': tools.ustr(que.id) + "_otherfield", 'colspan':"4"}) - fields[tools.ustr(que.id) + "_otherfield"] = {'type':'boolean', 'string':que_rec.comment_label, 'views':{}} - etree.SubElement(xml_group, 'field', {'readonly' :str(readonly), 'name': tools.ustr(que.id) + "_other", 'nolabel':"1" ,'colspan':"4"}) - fields[tools.ustr(que.id) + "_other"] = {'type': que_rec.comment_field_type, 'string': '', 'views':{}} - else: - etree.SubElement(xml_group, 'label', {'string': to_xml(tools.ustr(que_rec.comment_label)),'colspan':"4"}) - etree.SubElement(xml_group, 'field', {'readonly' :str(readonly), 'name': tools.ustr(que.id) + "_other", 'nolabel':"1" ,'colspan':"4"}) - fields[tools.ustr(que.id) + "_other"] = {'type': que_rec.comment_field_type, 'string': '', 'views':{}} + def _view_survey_complete(self, result): + xml_form = etree.Element('form', {'string': _('Complete Survey Answer')}) + #xml_footer = etree.SubElement(xml_form, 'footer', {'col': '6', 'colspan': '4' ,'class': 'oe_survey_title_height'}) + etree.SubElement(xml_form, 'separator', {'string': 'Survey Completed', 'colspan': "4"}) + etree.SubElement(xml_form, 'label', {'string': 'Thanks for your Answer'}) + etree.SubElement(xml_form, 'newline') + root = xml_form.getroottree() + result['arch'] = etree.tostring(root) + result['fields'] = {} + result['context'] = context + + def _survey_complete(self, survey_id, partner_id, sur_rec): + survey_obj = self.pool.get('survey') + sur_response_obj = self.pool.get('survey.response') + # record complete + survey_obj.write(cr, uid, survey_id, {'tot_comp_survey' : sur_rec.tot_comp_survey + 1}) + sur_response_obj.write(cr, uid, [sur_name_read.response], {'state' : 'done'}) + + # send mail to the responsible + survey_data = survey_obj.browse(cr, uid, survey_id, context.context) + responsible_id = survey_data.responsible_id and survey_data.responsible_id.email or False + if sur_rec.send_response and responsible_id: + val = { + 'type': 'notification', + 'author_id': partner_id or None, + 'partner_ids': [responsible_id], + 'notified_partner_ids': [responsible_id], + 'model': 'survey', + 'res_id': survey_id, + 'record_name': _("Survey N° %s") % survey_id, + 'subject': survey_data.title, + 'body': _("A survey answer is completed."), + } + self.pool.get('mail.thread').create(cr, uid, val, context=context) + def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False): """ Fields View Get method :- generate the new view and display the survey pages of selected survey. @@ -190,6 +215,9 @@ class survey_question_wiz(osv.osv_memory): que_col_head = self.pool.get('survey.question.column.heading') user_obj = self.pool.get('res.users') user_browse = user_obj.browse(cr, uid, uid, context=context) + #todo + partner_id = 0 + partner_email = 'fqsdf@fdqsf' partner_obj = self.pool.get('res.partner') mail_message = self.pool.get('mail.message') @@ -249,7 +277,7 @@ class survey_question_wiz(osv.osv_memory): # get if the token of the partner or anonymous user is valid validate_response = sur_rec.responsible_id.id == uid or sur_response_obj.search(cr, uid, [('survey_id','=',survey_id), ('state','=','new'), - '|', ('partner_id','=',user_browse.partner_id.id), ("token","=", context.get("survey_token", None)), + '|', ('partner_id','=',partner_id), ("token","=", context.get("survey_token", None)), '|', ('date_deadline','=',None), ('date_deadline','<',datetime.now())], context=context, limit=1) active = context.get('active', False) @@ -383,57 +411,9 @@ class survey_question_wiz(osv.osv_memory): # survey complete else: - survey_obj.write(cr, uid, survey_id, {'tot_comp_survey' : sur_rec.tot_comp_survey + 1}) - sur_response_obj.write(cr, uid, [sur_name_read.response], {'state' : 'done'}) + self._survey_complete(survey_id, partner_id, sur_rec) + self._view_survey_complete(result): - if sur_rec.send_response: - survey_data = survey_obj.browse(cr, uid, survey_id) - response_id = surv_name_wiz.read(cr, uid, context.get('sur_name_id',False))['response'] - report = self.create_report(cr, uid, [survey_id], 'report.survey.browse.response', survey_data.title,context) - attachments = {} - pdf_filename = addons.get_module_resource('survey', 'report') + survey_data.title + ".pdf" - if os.path.exists(pdf_filename): - file = open(pdf_filename) - file_data = "" - while 1: - line = file.readline() - file_data += line - if not line: - break - - attachments[survey_data.title + ".pdf"] = file_data - file.close() - os.remove(addons.get_module_resource('survey', 'report') + survey_data.title + ".pdf") - context.update({'response_id':response_id}) - partner_email = user_browse.email - resp_email = survey_data.responsible_id and survey_data.responsible_id.email or False - - if partner_email and resp_email: - partner_name = partner_obj.browse(cr, uid, uid, context=context).name - mail = "Hello " + survey_data.responsible_id.name + ",\n\n " + str(partner_name) + " has given the Response Of " + survey_data.title + " Survey.\nThe Response has been attached herewith.\n\n Thanks." - vals = {'state': 'outgoing', - 'subject': "Survey Answer Of " + partner_name, - 'body_html': '
%s
' % mail, - 'email_to': [resp_email], - 'email_from': partner_email} - if attachments: - vals['attachment_ids'] = [(0,0,{'name': a_name, - 'datas_fname': a_name, - 'datas': str(a_content).encode('base64')}) - for a_name, a_content in attachments.items()] - self.pool.get('mail.mail').create(cr, uid, vals, context=context) - - xml_form = etree.Element('form', {'string': _('Complete Survey Answer')}) - xml_footer = etree.SubElement(xml_form, 'footer', {'col': '6', 'colspan': '4' ,'class': 'oe_survey_title_height'}) - - etree.SubElement(xml_form, 'separator', {'string': 'Survey Completed', 'colspan': "4"}) - etree.SubElement(xml_form, 'label', {'string': 'Thanks for your Answer'}) - etree.SubElement(xml_form, 'newline') - # etree.SubElement(xml_footer, 'button', {'special':"cancel",'string':"OK",'colspan':"2",'class':'oe_highlight'}) - root = xml_form.getroottree() - result['arch'] = etree.tostring(root) - result['fields'] = {} - result['context'] = context # don't have acces to this survey else: @@ -460,9 +440,8 @@ class survey_question_wiz(osv.osv_memory): service = netsvc.LocalService(report_name); (result, format) = service.create(cr, uid, res_ids, {}, context) ret_file_name = addons.get_module_resource('survey', 'report') + file_name + '.pdf' - fp = open(ret_file_name, 'wb+'); - fp.write(result); - fp.close(); + with open(ret_file_name, 'wb+') as fp: + fp.write(result) # hr.applicant: if survey answered directly in system: attach report to applicant if context.get('active_model') == 'hr.applicant': diff --git a/addons/survey/wizard/survey_selection.py b/addons/survey/wizard/survey_selection.py index 1a84d3c5d5e..496f871394c 100644 --- a/addons/survey/wizard/survey_selection.py +++ b/addons/survey/wizard/survey_selection.py @@ -47,15 +47,15 @@ class survey_name_wiz(osv.osv_memory): def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False): res = super(survey_name_wiz, self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar, submenu=False) - if uid != 1: - survey_obj = self.pool.get('survey') - line_ids = survey_obj.search(cr, uid, [('invited_partner_ids.user_id','in',uid)], context=context) - domain = str([('id', 'in', line_ids)]) - doc = etree.XML(res['arch']) - nodes = doc.xpath("//field[@name='survey_id']") - for node in nodes: - node.set('domain', domain) - res['arch'] = etree.tostring(doc) + partner_id = self.pool.get('res.partner').search(cr, uid, [("user_id","=",uid)], context=context)[0] + survey_obj = self.pool.get('survey') + line_ids = survey_obj.search(cr, uid, [('invited_partner_ids.partner_id','in',partner_id)], context=context) + domain = str([('id', 'in', line_ids)]) + doc = etree.XML(res['arch']) + nodes = doc.xpath("//field[@name='survey_id']") + for node in nodes: + node.set('domain', domain) + res['arch'] = etree.tostring(doc) return res def action_next(self, cr, uid, ids, context=None): From 70ebd35d629fba2e4228fc5f4d3ee6e144f4ce6b Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Fri, 15 Feb 2013 12:14:08 +0100 Subject: [PATCH 0028/1010] [IMP] survey: clean in progress bzr revid: chm@openerp.com-20130215111408-ggjm3vh3goqicy7y --- addons/survey/survey.py | 17 +- addons/survey/survey_demo.xml | 14 - addons/survey/survey_view.xml | 10 - addons/survey/wizard/survey_answer.py | 711 +++++++++++----------- addons/survey/wizard/survey_selection.py | 14 +- addons/survey/wizard/survey_selection.xml | 7 +- 6 files changed, 360 insertions(+), 413 deletions(-) diff --git a/addons/survey/survey.py b/addons/survey/survey.py index fdb1818bd69..79f30df1a37 100644 --- a/addons/survey/survey.py +++ b/addons/survey/survey.py @@ -62,7 +62,6 @@ class survey(osv.osv): 'tot_start_survey': fields.integer("Total Started Survey", readonly=1), 'tot_comp_survey': fields.integer("Total Completed Survey", readonly=1), 'note': fields.text('Description', size=128), - 'history': fields.one2many('survey.history', 'survey_id', 'History Lines', readonly=True), 'partner_id': fields.many2many('res.partner', 'survey_partner_rel', 'sid', 'partner_id', 'Partners'), 'send_response': fields.boolean('Email Notification on Answer'), 'type': fields.many2one('survey.type', 'Type'), @@ -95,7 +94,7 @@ class survey(osv.osv): current_rec = self.read(cr, uid, ids, context=context) title = _("%s (copy)") % (current_rec.get('title')) vals.update({'title':title}) - vals.update({'history':[],'tot_start_survey':0,'tot_comp_survey':0}) + vals.update({'tot_start_survey':0,'tot_comp_survey':0}) return super(survey, self).copy(cr, uid, ids, vals, context=context) def action_print_survey(self, cr, uid, ids, context=None): @@ -232,20 +231,6 @@ class survey(osv.osv): survey() -class survey_history(osv.osv): - _name = 'survey.history' - _description = 'Survey History' - _rec_name = 'date' - _columns = { - 'survey_id': fields.many2one('survey', 'Survey'), - 'partner_id': fields.many2one('res.partner', 'Partner', readonly=True), - 'date': fields.datetime('Date started', readonly=1), - } - _defaults = { - 'date': lambda * a: datetime.datetime.now() - } -survey_history() - class survey_page(osv.osv): _name = 'survey.page' _description = 'Survey Pages' diff --git a/addons/survey/survey_demo.xml b/addons/survey/survey_demo.xml index 6f89095c699..e235911bb01 100644 --- a/addons/survey/survey_demo.xml +++ b/addons/survey/survey_demo.xml @@ -2914,20 +2914,6 @@ - - - - - - - - - - - - - - diff --git a/addons/survey/survey_view.xml b/addons/survey/survey_view.xml index deb68c3d0a1..68b5cd575cb 100644 --- a/addons/survey/survey_view.xml +++ b/addons/survey/survey_view.xml @@ -228,16 +228,6 @@
- - - - - -
- - - -
diff --git a/addons/survey/wizard/survey_answer.py b/addons/survey/wizard/survey_answer.py index f8a4ff47f39..a6a5652ebca 100644 --- a/addons/survey/wizard/survey_answer.py +++ b/addons/survey/wizard/survey_answer.py @@ -2,7 +2,7 @@ ############################################################################## # # OpenERP, Open Source Management Solution -# Copyright (C) 2004-2010 Tiny SPRL (). +# Copyright (C) 2004-2010 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 @@ -15,14 +15,11 @@ # 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 . +# along with this program. If not, see . # ############################################################################## -import base64 -import datetime from lxml import etree -import os from time import strftime from openerp import addons, netsvc, tools @@ -32,38 +29,42 @@ from datetime import datetime from openerp.tools.translate import _ from openerp.tools.safe_eval import safe_eval + class survey_question_wiz(osv.osv_memory): _name = 'survey.question.wiz' _columns = { 'name': fields.integer('Number'), } - def _view_field_multiple_choice_only_one_ans(self, xml_group, fields, readonly, que, que_rec): + def _view_field_multiple_choice_only_one_ans(self, cr, uid, xml_group, fields, readonly, que, que_rec): selection = [] for ans in que_rec.answer_choice_ids: selection.append((tools.ustr(ans.id), ans.answer)) xml_group = etree.SubElement(xml_group, 'group', {'col': '2', 'colspan': '2'}) - etree.SubElement(xml_group, 'field', {'readonly':str(readonly), 'name': tools.ustr(que.id) + "_selection"}) - fields[tools.ustr(que.id) + "_selection"] = {'type':'selection', 'selection' :selection, 'string':"Answer"} - # TODO convert selection field into radio input - def _view_field_multiple_choice_multiple_ans(self, xml_group, fields, readonly, que, que_rec): + etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'name': tools.ustr(que.id) + "_selection"}) + fields[tools.ustr(que.id) + "_selection"] = {'type': 'selection', 'selection': selection, 'string': "Answer"} + + def _view_field_multiple_choice_multiple_ans(self, cr, uid, xml_group, fields, readonly, que, que_rec): + # TODO convert selection field into radio input xml_group = etree.SubElement(xml_group, 'group', {'col': '4', 'colspan': '4'}) for ans in que_rec.answer_choice_ids: - etree.SubElement(xml_group, 'field', {'readonly':str(readonly), 'name': tools.ustr(que.id) + "_" + tools.ustr(ans.id)}) - fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id)] = {'type':'boolean', 'string':ans.answer} + etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'name': tools.ustr(que.id) + "_" + tools.ustr(ans.id)}) + fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id)] = {'type': 'boolean', 'string': ans.answer} + + def _view_field_matrix_of_choices_only_multi_ans(self, cr, uid, xml_group, fields, readonly, que, que_rec): + que_col_head = self.pool.get('survey.question.column.heading') - def _view_field_matrix_of_choices_only_multi_ans(self, xml_group, fields, readonly, que, que_rec): xml_group = etree.SubElement(xml_group, 'group', {'col': str(len(que_rec.column_heading_ids) + 1), 'colspan': '4'}) - etree.SubElement(xml_group, 'separator', {'string': '.','colspan': '1'}) + etree.SubElement(xml_group, 'separator', {'string': '.', 'colspan': '1'}) for col in que_rec.column_heading_ids: - etree.SubElement(xml_group, 'separator', {'string': tools.ustr(col.title),'colspan': '1'}) + etree.SubElement(xml_group, 'separator', {'string': tools.ustr(col.title), 'colspan': '1'}) for row in que_rec.answer_choice_ids: - etree.SubElement(xml_group, 'label', {'string': to_xml(tools.ustr(row.answer)) +' :-', 'align': '0.0'}) - for col in que_col_head.browse(cr, uid, [head.id for head in que_rec.column_heading_ids]): - etree.SubElement(xml_group, 'field', {'readonly' :str(readonly), 'name': tools.ustr(que.id) + "_" + tools.ustr(row.id) + "_" + tools.ustr(col.id), 'nolabel':"1"}) - fields[tools.ustr(que.id) + "_" + tools.ustr(row.id) + "_" + tools.ustr(col.id)] = {'type':'boolean', 'string': col.title} + etree.SubElement(xml_group, 'label', {'string': to_xml(tools.ustr(row.answer)) + ': -', 'align': '0.0'}) + for col in que_col_head.browse(cr, uid, [head.id for head in que_rec.column_heading_ids]): + etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'name': tools.ustr(que.id) + "_" + tools.ustr(row.id) + "_" + tools.ustr(col.id), 'nolabel': "1"}) + fields[tools.ustr(que.id) + "_" + tools.ustr(row.id) + "_" + tools.ustr(col.id)] = {'type': 'boolean', 'string': col.title} - def _view_field_multiple_textboxes(self, xml_group, fields, readonly, que, que_rec): + def _view_field_multiple_textboxes(self, cr, uid, xml_group, fields, readonly, que, que_rec): xml_group = etree.SubElement(xml_group, 'group', {'col': '4', 'colspan': '4'}) type = "char" if que_rec.is_validation_require: @@ -74,96 +75,105 @@ class survey_question_wiz(osv.osv_memory): elif que_rec.validation_type in ['must_be_date']: type = "date" for ans in que_rec.answer_choice_ids: - etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'width':"300",'colspan': '1','name': tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"}) - if type == "char" : - fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"] = {'type':'char', 'size':255, 'string':ans.answer} - else: - fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"] = {'type': str(type), 'string':ans.answer} + etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'width': "300", 'colspan': '1', 'name': tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"}) + fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"] = {'type': str(type), 'string': ans.answer} - def _view_field_numerical_textboxes(self, xml_group, fields, readonly, que, que_rec): + def _view_field_numerical_textboxes(self, cr, uid, xml_group, fields, readonly, que, que_rec): xml_group = etree.SubElement(xml_group, 'group', {'col': '4', 'colspan': '4'}) for ans in que_rec.answer_choice_ids: - etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'width':"300",'colspan': '1','name': tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_numeric"}) - fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_numeric"] = {'type':'integer', 'string':ans.answer} + etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'width': "300", 'colspan': '1', 'name': tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_numeric"}) + fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_numeric"] = {'type': 'integer', 'string': ans.answer} - def _view_field_date(self, xml_group, fields, readonly, que, que_rec): + def _view_field_date(self, cr, uid, xml_group, fields, readonly, que, que_rec): xml_group = etree.SubElement(xml_group, 'group', {'col': '4', 'colspan': '4'}) for ans in que_rec.answer_choice_ids: - etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'width':"300",'colspan': '1','name': tools.ustr(que.id) + "_" + tools.ustr(ans.id)}) - fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id)] = {'type':'date', 'string':ans.answer} + etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'width': "300", 'colspan': '1', 'name': tools.ustr(que.id) + "_" + tools.ustr(ans.id)}) + fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id)] = {'type': 'date', 'string': ans.answer} - def _view_field_date_and_time(self, xml_group, fields, readonly, que, que_rec): + def _view_field_date_and_time(self, cr, uid, xml_group, fields, readonly, que, que_rec): xml_group = etree.SubElement(xml_group, 'group', {'col': '4', 'colspan': '4'}) for ans in que_rec.answer_choice_ids: - etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'width':"300",'colspan': '1','name': tools.ustr(que.id) + "_" + tools.ustr(ans.id)}) - fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id)] = {'type':'datetime', 'string':ans.answer} + etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'width': "300", 'colspan': '1', 'name': tools.ustr(que.id) + "_" + tools.ustr(ans.id)}) + fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id)] = {'type': 'datetime', 'string': ans.answer} - def _view_field_descriptive_text(self, xml_group, fields, readonly, que, que_rec): + def _view_field_descriptive_text(self, cr, uid, xml_group, fields, readonly, que, que_rec): if que_rec.descriptive_text: for que_test in que_rec.descriptive_text.split('\n'): - etree.SubElement(xml_group, 'label', {'string': to_xml(tools.ustr(que_test)), 'align':"0.0"}) + etree.SubElement(xml_group, 'label', {'string': to_xml(tools.ustr(que_test)), 'align': "0.0"}) - def _view_field_single_textbox(self, xml_group, fields, readonly, que, que_rec): - etree.SubElement(xml_group, 'field', {'readonly' :str(readonly), 'name': tools.ustr(que.id) + "_single", 'nolabel':"1" ,'colspan':"4"}) - fields[tools.ustr(que.id) + "_single"] = {'type':'char', 'size': 255, 'string':"single_textbox", 'views':{}} + def _view_field_single_textbox(self, cr, uid, xml_group, fields, readonly, que, que_rec): + etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'name': tools.ustr(que.id) + "_single", 'nolabel': "1", 'colspan': "4"}) + fields[tools.ustr(que.id) + "_single"] = {'type': 'char', 'size': 255, 'string': "single_textbox", 'views': {}} - def _view_field_comment(self, xml_group, fields, readonly, que, que_rec): - etree.SubElement(xml_group, 'field', {'readonly' :str(readonly), 'name': tools.ustr(que.id) + "_comment", 'nolabel':"1" ,'colspan':"4"}) - fields[tools.ustr(que.id) + "_comment"] = {'type':'text', 'string':"Comment/Eassy Box", 'views':{}} + def _view_field_comment(self, cr, uid, xml_group, fields, readonly, que, que_rec): + etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'name': tools.ustr(que.id) + "_comment", 'nolabel': "1", 'colspan': "4"}) + fields[tools.ustr(que.id) + "_comment"] = {'type': 'text', 'string': "Comment/Eassy Box", 'views': {}} - def _view_field_table(self, xml_group, fields, readonly, que, que_rec): + def _view_field_table(self, cr, uid, xml_group, fields, readonly, que, que_rec): xml_group = etree.SubElement(xml_group, 'group', {'col': str(len(que_rec.column_heading_ids)), 'colspan': '4'}) for col in que_rec.column_heading_ids: - etree.SubElement(xml_group, 'separator', {'string': tools.ustr(col.title),'colspan': '1'}) - for row in range(0,que_rec.no_of_rows): + etree.SubElement(xml_group, 'separator', {'string': tools.ustr(col.title), 'colspan': '1'}) + for row in range(0, que_rec.no_of_rows): for col in que_rec.column_heading_ids: - etree.SubElement(xml_group, 'field', {'readonly' :str(readonly), 'name': tools.ustr(que.id) + "_table_" + tools.ustr(col.id) +"_"+ tools.ustr(row), 'nolabel':"1"}) - fields[tools.ustr(que.id) + "_table_" + tools.ustr(col.id) +"_"+ tools.ustr(row)] = {'type':'char','size':255,'views':{}} + etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'name': tools.ustr(que.id) + "_table_" + tools.ustr(col.id) + "_" + tools.ustr(row), 'nolabel': "1"}) + fields[tools.ustr(que.id) + "_table_" + tools.ustr(col.id) + "_" + tools.ustr(row)] = {'type': 'char', 'size': 255, 'views': {}} - def _view_field_multiple_textboxes_diff_type(self, xml_group, fields, readonly, que, que_rec): + def _view_field_multiple_textboxes_diff_type(self, cr, uid, xml_group, fields, readonly, que, que_rec): xml_group = etree.SubElement(xml_group, 'group', {'col': '4', 'colspan': '4'}) for ans in que_rec.answer_choice_ids: - if ans.type == "email" : - fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"] = {'type':'char', 'size':255, 'string':ans.answer} - etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'widget':'email','width':"300",'colspan': '1','name': tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"}) + if ans.type == "email": + fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"] = {'type': 'char', 'size': 255, 'string': ans.answer} + etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'widget': 'email', 'width': "300", 'colspan': '1', 'name': tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"}) else: - etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'width':"300",'colspan': '1','name': tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"}) - if ans.type == "char" : - fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"] = {'type':'char', 'size':255, 'string':ans.answer} - elif ans.type in ['integer','float','date','datetime']: - fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"] = {'type': str(ans.type), 'string':ans.answer} + etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'width': "300", 'colspan': '1', 'name': tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"}) + if ans.type == "char": + fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"] = {'type': 'char', 'size': 255, 'string': ans.answer} + elif ans.type in ['integer', 'float', 'date', 'datetime']: + fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"] = {'type': str(ans.type), 'string': ans.answer} else: selection = [] if ans.menu_choice: for item in ans.menu_choice.split('\n'): - if item and not item.strip() == '': selection.append((item ,item)) - fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"] = {'type':'selection', 'selection' : selection, 'string':ans.answer} + if item and not item.strip() == '': + selection.append((item, item)) + fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"] = {'type': 'selection', 'selection': selection, 'string': ans.answer} - def _view_field_matrix_of_choices_only_one_ans(self, xml_group, fields, readonly, que, que_rec): + def _view_field_matrix_of_choices_only_one_ans(self, cr, uid, xml_group, fields, readonly, que, que_rec): if que_rec.comment_column: col = "4" colspan = "4" else: - col = "2" - colspan = "2" + col = "2" + colspan = "2" xml_group = etree.SubElement(xml_group, 'group', {'col': tools.ustr(col), 'colspan': tools.ustr(colspan)}) for row in que_rec.answer_choice_ids: etree.SubElement(xml_group, 'newline') - etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'name': tools.ustr(que.id) + "_selection_" + tools.ustr(row.id),'string':to_xml(tools.ustr(row.answer))}) - selection = [('','')] + etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'name': tools.ustr(que.id) + "_selection_" + tools.ustr(row.id), 'string': to_xml(tools.ustr(row.answer))}) + selection = [('', '')] for col in que_rec.column_heading_ids: selection.append((str(col.id), col.title)) - fields[tools.ustr(que.id) + "_selection_" + tools.ustr(row.id)] = {'type':'selection', 'selection' : selection, 'string': "Answer"} + fields[tools.ustr(que.id) + "_selection_" + tools.ustr(row.id)] = {'type': 'selection', 'selection': selection, 'string': "Answer"} if que_rec.comment_column: - fields[tools.ustr(que.id) + "_commentcolumn_"+tools.ustr(row.id) + "_field"] = {'type':'char', 'size' : 255, 'string':tools.ustr(que_rec.column_name), 'views':{}} - etree.SubElement(xml_group, 'field', {'readonly' :str(readonly), 'name': tools.ustr(que.id) + "_commentcolumn_"+tools.ustr(row.id)+ "_field"}) + fields[tools.ustr(que.id) + "_commentcolumn_" + tools.ustr(row.id) + "_field"] = {'type': 'char', 'size': 255, 'string': tools.ustr(que_rec.column_name), 'views': {}} + etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'name': tools.ustr(que.id) + "_commentcolumn_" + tools.ustr(row.id) + "_field"}) - def _view_field_rating_scale(self, xml_group, fields, readonly, que, que_rec): + def _view_field_rating_scale(self, cr, uid, xml_group, fields, readonly, que, que_rec): self._view_field_matrix_of_choices_only_one_ans(xml_group, fields, readonly, que, que_rec) - def _view_survey_complete(self, result): + def _view_field_after_matrix_of_choices(self, cr, uid, xml_group, fields, readonly, que, que_rec): + if que_rec.type in ['multiple_choice_only_one_ans', 'multiple_choice_multiple_ans'] and que_rec.comment_field_type in ['char', 'text'] and que_rec.make_comment_field: + etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'name': tools.ustr(que.id) + "_otherfield", 'colspan': "4"}) + fields[tools.ustr(que.id) + "_otherfield"] = {'type': 'boolean', 'string': que_rec.comment_label, 'views': {}} + etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'name': tools.ustr(que.id) + "_other", 'nolabel': "1", 'colspan': "4"}) + fields[tools.ustr(que.id) + "_other"] = {'type': que_rec.comment_field_type, 'string': '', 'views': {}} + else: + etree.SubElement(xml_group, 'label', {'string': to_xml(tools.ustr(que_rec.comment_label)), 'colspan': "4"}) + etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'name': tools.ustr(que.id) + "_other", 'nolabel': "1", 'colspan': "4"}) + fields[tools.ustr(que.id) + "_other"] = {'type': que_rec.comment_field_type, 'string': '', 'views': {}} + + def _view_survey_complete(self, result, context): xml_form = etree.Element('form', {'string': _('Complete Survey Answer')}) - #xml_footer = etree.SubElement(xml_form, 'footer', {'col': '6', 'colspan': '4' ,'class': 'oe_survey_title_height'}) + #xml_footer = etree.SubElement(xml_form, 'footer', {'col': '6', 'colspan': '4', 'class': 'oe_survey_title_height'}) etree.SubElement(xml_form, 'separator', {'string': 'Survey Completed', 'colspan': "4"}) etree.SubElement(xml_form, 'label', {'string': 'Thanks for your Answer'}) etree.SubElement(xml_form, 'newline') @@ -171,56 +181,68 @@ class survey_question_wiz(osv.osv_memory): result['arch'] = etree.tostring(root) result['fields'] = {} result['context'] = context - - def _survey_complete(self, survey_id, partner_id, sur_rec): + + def _survey_complete(self, cr, uid, survey_id, partner_id, sur_name_read, survey_browse, context): survey_obj = self.pool.get('survey') sur_response_obj = self.pool.get('survey.response') # record complete - survey_obj.write(cr, uid, survey_id, {'tot_comp_survey' : sur_rec.tot_comp_survey + 1}) - sur_response_obj.write(cr, uid, [sur_name_read.response], {'state' : 'done'}) + survey_obj.write(cr, uid, survey_id, {'tot_comp_survey': survey_browse.tot_comp_survey + 1}) + sur_response_obj.write(cr, uid, [sur_name_read.response], {'state': 'done'}) # send mail to the responsible - survey_data = survey_obj.browse(cr, uid, survey_id, context.context) - responsible_id = survey_data.responsible_id and survey_data.responsible_id.email or False - if sur_rec.send_response and responsible_id: + survey_browse = survey_obj.browse(cr, uid, survey_id, context) + responsible_id = survey_browse.responsible_id and survey_browse.responsible_id.id or False + if survey_browse.send_response and responsible_id: val = { 'type': 'notification', 'author_id': partner_id or None, - 'partner_ids': [responsible_id], - 'notified_partner_ids': [responsible_id], + 'partner_ids': responsible_id and [responsible_id] or None, 'model': 'survey', 'res_id': survey_id, 'record_name': _("Survey N° %s") % survey_id, - 'subject': survey_data.title, + 'subject': survey_browse.title or None, 'body': _("A survey answer is completed."), } - self.pool.get('mail.thread').create(cr, uid, val, context=context) - + print val + self.pool.get('mail.message').create(cr, uid, val, context=context) + + def _check_token(self, cr, uid, survey_id, context): + # get if the token of the partner or anonymous user is valid + survey_browse = self.pool.get('survey').browse(cr, uid, survey_id, context=context) + + if survey_browse.responsible_id.id == uid: + response_id = False + partner_id = survey_browse.responsible_id.partner_id.id or False + else: + sur_response_obj = self.pool.get('survey.response') + + pid = self.pool.get('res.users').browse(cr, uid, uid, context=context).partner_id.id + response_id = sur_response_obj.search(cr, uid, [ + ('survey_id', '=', survey_browse.id), ('state', '=', 'new'), + '|', ('partner_id', '=', pid), ("token", "=", context.get("survey_token", None)), + '|', ('date_deadline', '=', None), ('date_deadline', '<', datetime.now())], context=context, limit=1) + if response_id: + sur_response_browse = sur_response_obj.browse(cr, uid, response_id[0], context=context) + partner_id = sur_response_browse.partner_id.id or False + + return {'partner_id': partner_id or False, 'response_id': response_id and response_id[0] or False} + def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False): """ - Fields View Get method :- generate the new view and display the survey pages of selected survey. + Fields View Get method: - generate the new view and display the survey pages of selected survey. """ if context is None: context = {} - result = super(survey_question_wiz, self).fields_view_get(cr, uid, view_id, view_type, context, toolbar,submenu) + result = super(survey_question_wiz, self).fields_view_get(cr, uid, view_id, view_type, context, toolbar, submenu) surv_name_wiz = self.pool.get('survey.name.wiz') survey_obj = self.pool.get('survey') page_obj = self.pool.get('survey.page') que_obj = self.pool.get('survey.question') - ans_obj = self.pool.get('survey.answer') sur_response_obj = self.pool.get('survey.response') - que_col_head = self.pool.get('survey.question.column.heading') - user_obj = self.pool.get('res.users') - user_browse = user_obj.browse(cr, uid, uid, context=context) - #todo - partner_id = 0 - partner_email = 'fqsdf@fdqsf' - partner_obj = self.pool.get('res.partner') - mail_message = self.pool.get('mail.message') - + if view_type in ['form']: wiz_id = 0 sur_name_rec = None @@ -236,9 +258,9 @@ class survey_question_wiz(osv.osv_memory): } wiz_id = surv_name_wiz.create(cr, uid, res_data) sur_name_rec = surv_name_wiz.browse(cr, uid, wiz_id, context=context) - context.update({'sur_name_id' :wiz_id}) + context.update({'sur_name_id': wiz_id}) - if context.has_key('active_id'): + if context.get('active_id'): context.pop('active_id') survey_id = context.get('survey_id', False) @@ -255,52 +277,43 @@ class survey_question_wiz(osv.osv_memory): return super(survey_question_wiz, self).\ fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar, submenu=submenu) - sur_rec = survey_obj.browse(cr, uid, survey_id, context=context) - p_id = map(lambda x:x.id, sur_rec.page_ids) + survey_browse = survey_obj.browse(cr, uid, survey_id, context=context) + p_id = map(lambda x: x.id, survey_browse.page_ids) total_pages = len(p_id) pre_button = False readonly = 0 if context.get('response_id', False) \ - and int(context['response_id'][0]) > 0: + and int(context['response_id'][0]) > 0: readonly = 1 - if not sur_name_rec.page_no + 1 : - surv_name_wiz.write(cr, uid, [context['sur_name_id'],], {'store_ans':{}}) + if not sur_name_rec.page_no + 1: + surv_name_wiz.write(cr, uid, [context['sur_name_id'], ], {'store_ans': {}}) sur_name_read = surv_name_wiz.browse(cr, uid, context['sur_name_id'], context=context) page_number = int(sur_name_rec.page_no) if sur_name_read.transfer or not sur_name_rec.page_no + 1: - surv_name_wiz.write(cr, uid, [context['sur_name_id']], {'transfer':False}) + surv_name_wiz.write(cr, uid, [context['sur_name_id']], {'transfer': False}) flag = False fields = {} # get if the token of the partner or anonymous user is valid - validate_response = sur_rec.responsible_id.id == uid or sur_response_obj.search(cr, uid, [('survey_id','=',survey_id), ('state','=','new'), - '|', ('partner_id','=',partner_id), ("token","=", context.get("survey_token", None)), - '|', ('date_deadline','=',None), ('date_deadline','<',datetime.now())], context=context, limit=1) - active = context.get('active', False) + check_token = self._check_token(cr, uid, survey_id, context) # have acces to this survey - if validate_response: + if check_token['partner_id'] or check_token['response_id']: + active = context.get('active', False) + if sur_name_read.page == "next" or sur_name_rec.page_no == -1: if total_pages > sur_name_rec.page_no + 1: - if not active and not sur_name_rec.page_no + 1: - if sur_rec.state != "open" : - raise osv.except_osv(_('Warning!'),_("You cannot answer because the survey is not open.")) - cr.execute('select count(id) from survey_history where partner_id=%s\ - and survey_id=%s', (uid,survey_id)) - res = cr.fetchone()[0] - partner_limit = survey_obj.browse(cr, uid, survey_id) - partner_limit = partner_limit.response_partner - if partner_limit and res >= partner_limit: - raise osv.except_osv(_('Warning!'),_("You cannot answer this survey more than %s times.") % (partner_limit)) + if not active and not sur_name_rec.page_no + 1 and survey_browse.state != "open": + raise osv.except_osv(_('Warning!'), _("You cannot answer because the survey is not open.")) - if sur_rec.max_response_limit and sur_rec.max_response_limit <= sur_rec.tot_start_survey and not sur_name_rec.page_no + 1: - survey_obj.write(cr, uid, survey_id, {'state':'close', 'date_close':strftime("%Y-%m-%d %H:%M:%S")}) + if survey_browse.max_response_limit and survey_browse.max_response_limit <= survey_browse.tot_start_survey and not sur_name_rec.page_no + 1: + survey_obj.write(cr, uid, survey_id, {'state': 'close', 'date_close': strftime("%Y-%m-%d %H: %M: %S")}) p_id = p_id[sur_name_rec.page_no + 1] - surv_name_wiz.write(cr, uid, [context['sur_name_id'],], {'page_no' : sur_name_rec.page_no + 1}) + surv_name_wiz.write(cr, uid, [context['sur_name_id'], ], {'page_no': sur_name_rec.page_no + 1}) flag = True page_number += 1 if sur_name_rec.page_no > - 1: @@ -310,8 +323,8 @@ class survey_question_wiz(osv.osv_memory): else: if sur_name_rec.page_no != 0: p_id = p_id[sur_name_rec.page_no - 1] - surv_name_wiz.write(cr, uid, [context['sur_name_id'],],\ - {'page_no' : sur_name_rec.page_no - 1}) + surv_name_wiz.write(cr, uid, [context['sur_name_id'], ], \ + {'page_no': sur_name_rec.page_no - 1}) flag = True page_number -= 1 @@ -321,88 +334,86 @@ class survey_question_wiz(osv.osv_memory): # survey in progress if flag: pag_rec = page_obj.browse(cr, uid, p_id, context=context) - xml_form = etree.Element('form', {'string': tools.ustr( pag_rec and pag_rec.title or sur_rec.title )}) + xml_form = etree.Element('form', {'string': tools.ustr(pag_rec and pag_rec.title or survey_browse.title)}) if active and context.get('edit'): - context.update({'page_id' : tools.ustr(p_id),'page_number' : sur_name_rec.page_no , 'transfer' : sur_name_read.transfer}) + context.update({'page_id': tools.ustr(p_id), 'page_number': sur_name_rec.page_no, 'transfer': sur_name_read.transfer}) xml_group3 = etree.SubElement(xml_form, 'group', {'col': '4', 'colspan': '4'}) - etree.SubElement(xml_group3, 'button', {'string' :'Add Page','icon': "gtk-new", 'type' :'object','name':"action_new_page", 'context' : tools.ustr(context)}) - etree.SubElement(xml_group3, 'button', {'string' :'Edit Page','icon': "gtk-edit", 'type' :'object','name':"action_edit_page", 'context' : tools.ustr(context)}) - etree.SubElement(xml_group3, 'button', {'string' :'Delete Page','icon': "gtk-delete", 'type' :'object','name':"action_delete_page", 'context' : tools.ustr(context)}) - etree.SubElement(xml_group3, 'button', {'string' :'Add Question','icon': "gtk-new", 'type' :'object','name':"action_new_question", 'context' : tools.ustr(context)}) + etree.SubElement(xml_group3, 'button', {'string': 'Add Page', 'icon': "gtk-new", 'type': 'object', 'name': "action_new_page", 'context': tools.ustr(context)}) + etree.SubElement(xml_group3, 'button', {'string': 'Edit Page', 'icon': "gtk-edit", 'type': 'object', 'name': "action_edit_page", 'context': tools.ustr(context)}) + etree.SubElement(xml_group3, 'button', {'string': 'Delete Page', 'icon': "gtk-delete", 'type': 'object', 'name': "action_delete_page", 'context': tools.ustr(context)}) + etree.SubElement(xml_group3, 'button', {'string': 'Add Question', 'icon': "gtk-new", 'type': 'object', 'name': "action_new_question", 'context': tools.ustr(context)}) # FP Note xml_group = xml_form - if context.get('response_id') and int(context.get('response_id',0)[0]) > 0: + if context.get('response_id') and int(context.get('response_id', 0)[0]) > 0: # TODO: l10n, cleanup this code to make it readable. Or template? xml_group = etree.SubElement(xml_form, 'group', {'col': '40', 'colspan': '4'}) record = sur_response_obj.browse(cr, uid, context['response_id'][context['response_no']]) - etree.SubElement(xml_group, 'label', {'string': to_xml(tools.ustr('Answer Of :- ' + record.partner_id.name + ', Date :- ' + record.date_create.split('.')[0] )), 'align':"0.0"}) - etree.SubElement(xml_group, 'label', {'string': to_xml(tools.ustr(" Answer :- " + str(context.get('response_no',0) + 1) +"/" + str(len(context.get('response_id',0))) )), 'align':"0.0"}) - if context.get('response_no',0) > 0: - etree.SubElement(xml_group, 'button', {'colspan':"1",'icon':"gtk-go-back",'name':"action_forward_previous",'string': tools.ustr("Previous Answer"),'type':"object"}) - if context.get('response_no',0) + 1 < len(context.get('response_id',0)): - etree.SubElement(xml_group, 'button', {'colspan':"1",'icon': "gtk-go-forward", 'name':"action_forward_next",'string': tools.ustr("Next Answer") ,'type':"object",'context' : tools.ustr(context)}) + etree.SubElement(xml_group, 'label', {'string': to_xml(tools.ustr('Answer Of: - ' + record.partner_id.name + ', Date: - ' + record.date_create.split('.')[0])), 'align': "0.0"}) + etree.SubElement(xml_group, 'label', {'string': to_xml(tools.ustr(" Answer: - " + str(context.get('response_no', 0) + 1) + "/" + str(len(context.get('response_id', 0))))), 'align': "0.0"}) + if context.get('response_no', 0) > 0: + etree.SubElement(xml_group, 'button', {'colspan': "1", 'icon': "gtk-go-back", 'name': "action_forward_previous", 'string': tools.ustr("Previous Answer"), 'type': "object"}) + if context.get('response_no', 0) + 1 < len(context.get('response_id', 0)): + etree.SubElement(xml_group, 'button', {'colspan': "1", 'icon': "gtk-go-forward", 'name': "action_forward_next", 'string': tools.ustr("Next Answer"), 'type': "object", 'context': tools.ustr(context)}) if wiz_id: - fields["wizardid_" + str(wiz_id)] = {'type':'char', 'size' : 255, 'string':"", 'views':{}} - etree.SubElement(xml_form, 'field', {'invisible':'1','name': "wizardid_" + str(wiz_id),'default':str(lambda *a: 0),'modifiers':'{"invisible":true}'}) + fields["wizardid_" + str(wiz_id)] = {'type': 'char', 'size': 255, 'string': "", 'views': {}} + etree.SubElement(xml_form, 'field', {'invisible': '1', 'name': "wizardid_" + str(wiz_id), 'default': str(lambda *a: 0), 'modifiers': '{"invisible": true}'}) if pag_rec and pag_rec.note: - xml_group_note = etree.SubElement(xml_form, 'group', {'col': '1','colspan': '4'}) + xml_group_note = etree.SubElement(xml_form, 'group', {'col': '1', 'colspan': '4'}) for que_test in pag_rec.note.split('\n'): - etree.SubElement(xml_group_note, 'label', {'string': to_xml(tools.ustr(que_test)), 'align':"0.0"}) - + etree.SubElement(xml_group_note, 'label', {'string': to_xml(tools.ustr(que_test)), 'align': "0.0"}) + qu_no = 0 for que in (pag_rec and pag_rec.question_ids or []): qu_no += 1 que_rec = que_obj.browse(cr, uid, que.id, context=context) - descriptive_text = "" separator_string = tools.ustr(qu_no) + "." + tools.ustr(que_rec.question) star = (not active and que_rec.is_require_answer) and '*' or '' if active and context.get('edit'): - etree.SubElement(xml_form, 'separator', {'string': star+to_xml(separator_string)}) + etree.SubElement(xml_form, 'separator', {'string': star + to_xml(separator_string)}) xml_group1 = etree.SubElement(xml_form, 'group', {'col': '2', 'colspan': '2'}) - context.update({'question_id' : tools.ustr(que.id),'page_number': sur_name_rec.page_no , 'transfer' : sur_name_read.transfer, 'page_id' : p_id}) - etree.SubElement(xml_group1, 'button', {'string':'','icon': "gtk-edit", 'type' :'object', 'name':"action_edit_question", 'context' : tools.ustr(context)}) - etree.SubElement(xml_group1, 'button', {'string':'','icon': "gtk-delete", 'type' :'object','name':"action_delete_question", 'context' : tools.ustr(context)}) + context.update({'question_id': tools.ustr(que.id), 'page_number': sur_name_rec.page_no, 'transfer': sur_name_read.transfer, 'page_id': p_id}) + etree.SubElement(xml_group1, 'button', {'string': '', 'icon': "gtk-edit", 'type': 'object', 'name': "action_edit_question", 'context': tools.ustr(context)}) + etree.SubElement(xml_group1, 'button', {'string': '', 'icon': "gtk-delete", 'type': 'object', 'name': "action_delete_question", 'context': tools.ustr(context)}) else: etree.SubElement(xml_form, 'newline') - etree.SubElement(xml_form, 'separator', {'string': star+to_xml(separator_string)}) + etree.SubElement(xml_form, 'separator', {'string': star + to_xml(separator_string)}) xml_group = etree.SubElement(xml_form, 'group', {'col': '1', 'colspan': '4'}) # rendering different views - getattr(self, "_view_field_%s" % que_rec.type)(xml_group, fields, readonly, que, que_rec) + getattr(self, "_view_field_%s" % que_rec.type)(cr, uid, xml_group, fields, readonly, que, que_rec) if que_rec.type in ['multiple_choice_only_one_ans', 'multiple_choice_multiple_ans', 'matrix_of_choices_only_one_ans', 'matrix_of_choices_only_multi_ans', 'rating_scale'] and que_rec.is_comment_require: - self._view_field_after_matrix_of_choices(xml_group, fields, readonly, que, que_rec) + self._view_field_after_matrix_of_choices(cr, uid, xml_group, fields, readonly, que, que_rec) - - xml_footer = etree.SubElement(xml_form, 'footer', {'col': '8', 'colspan': '1', 'width':"100%"}) + xml_footer = etree.SubElement(xml_form, 'footer', {'col': '8', 'colspan': '1', 'width': "100%"}) if pre_button: etree.SubElement(xml_footer, 'label', {'string': ""}) - etree.SubElement(xml_footer, 'button', {'name':"action_previous",'string':"Previous",'type':"object"}) + etree.SubElement(xml_footer, 'button', {'name': "action_previous", 'string': "Previous", 'type': "object"}) but_string = "Next" if int(page_number) + 1 == total_pages: but_string = "Done" - if active and int(page_number) + 1 == total_pages and context.get('response_id') and context.get('response_no',0) + 1 == len(context.get('response_id',0)): + if active and int(page_number) + 1 == total_pages and context.get('response_id') and context.get('response_no', 0) + 1 == len(context.get('response_id', 0)): etree.SubElement(xml_footer, 'label', {'string': ""}) - etree.SubElement(xml_footer, 'button', {'special' : 'cancel','string': tools.ustr("Done") ,'context' : tools.ustr(context), 'class':"oe_highlight"}) + etree.SubElement(xml_footer, 'button', {'special': 'cancel', 'string': tools.ustr("Done"), 'context': tools.ustr(context), 'class': "oe_highlight"}) elif active and int(page_number) + 1 == total_pages and context.get('response_id'): etree.SubElement(xml_footer, 'label', {'string': ""}) - etree.SubElement(xml_footer, 'button', {'name':"action_forward_next",'string': tools.ustr("Next Answer") ,'type':"object",'context' : tools.ustr(context), 'class':"oe_highlight"}) + etree.SubElement(xml_footer, 'button', {'name': "action_forward_next", 'string': tools.ustr("Next Answer"), 'type': "object", 'context': tools.ustr(context), 'class': "oe_highlight"}) elif active and int(page_number) + 1 == total_pages: etree.SubElement(xml_footer, 'label', {'string': ""}) - etree.SubElement(xml_footer, 'button', {'special': "cancel", 'string' : 'Done', 'context' : tools.ustr(context), 'class':"oe_highlight"}) + etree.SubElement(xml_footer, 'button', {'special': "cancel", 'string': 'Done', 'context': tools.ustr(context), 'class': "oe_highlight"}) else: etree.SubElement(xml_footer, 'label', {'string': ""}) - etree.SubElement(xml_footer, 'button', {'name':"action_next",'string': tools.ustr(but_string) ,'type':"object",'context' : tools.ustr(context), 'class':"oe_highlight"}) + etree.SubElement(xml_footer, 'button', {'name': "action_next", 'string': tools.ustr(but_string), 'type': "object", 'context': tools.ustr(context), 'class': "oe_highlight"}) if context.get('ir_actions_act_window_target', None): etree.SubElement(xml_footer, 'label', {'string': "or"}) - etree.SubElement(xml_footer, 'button', {'special': "cancel",'string':"Exit",'class':"oe_link"}) - etree.SubElement(xml_footer, 'label', {'string': tools.ustr(page_number+ 1) + "/" + tools.ustr(total_pages), 'class':"oe_survey_title_page oe_right"}) + etree.SubElement(xml_footer, 'button', {'special': "cancel", 'string': "Exit", 'class': "oe_link"}) + etree.SubElement(xml_footer, 'label', {'string': tools.ustr(page_number + 1) + "/" + tools.ustr(total_pages), 'class': "oe_survey_title_page oe_right"}) root = xml_form.getroottree() result['arch'] = etree.tostring(root) @@ -411,14 +422,13 @@ class survey_question_wiz(osv.osv_memory): # survey complete else: - self._survey_complete(survey_id, partner_id, sur_rec) - self._view_survey_complete(result): + self._survey_complete(cr, uid, survey_id, check_token['partner_id'], sur_name_read, survey_browse, context) + self._view_survey_complete(result, context) - # don't have acces to this survey else: xml_form = etree.Element('form', {'string': _('No access to this survey')}) - etree.SubElement(xml_form, 'separator', {'string': sur_rec.title, 'colspan': "4"}) + etree.SubElement(xml_form, 'separator', {'string': survey_browse.title, 'colspan': "4"}) etree.SubElement(xml_form, 'label', {'string': "You don't have access to this survey."}) etree.SubElement(xml_form, 'newline') etree.SubElement(xml_form, 'label', {'string': "The access you have not been given or the deadline has passed."}) @@ -437,26 +447,13 @@ class survey_question_wiz(osv.osv_memory): return (False, Exception('Report name and Resources ids are required !!!')) try: uid = 1 - service = netsvc.LocalService(report_name); + service = netsvc.LocalService(report_name) (result, format) = service.create(cr, uid, res_ids, {}, context) ret_file_name = addons.get_module_resource('survey', 'report') + file_name + '.pdf' - with open(ret_file_name, 'wb+') as fp: + with open(ret_file_name, 'wb + ') as fp: fp.write(result) - - # hr.applicant: if survey answered directly in system: attach report to applicant - if context.get('active_model') == 'hr.applicant': - self.pool.get('hr.applicant').write(cr,uid,[context.get('active_ids')[0]],{'response':context.get('response_id')}) - result = base64.b64encode(result) - file_name = file_name + '.pdf' - ir_attachment = self.pool.get('ir.attachment').create(cr, uid, - {'name': file_name, - 'datas': result, - 'datas_fname': file_name, - 'res_model': context.get('active_model'), - 'res_id': context.get('active_ids')[0]}, - context=context) - except Exception,e: + except Exception, e: return (False, str(e)) return (True, ret_file_name) @@ -469,13 +466,12 @@ class survey_question_wiz(osv.osv_memory): context = {} for field in fields_list: if field.split('_')[0] == 'progress': - tot_page_id = self.pool.get('survey').browse(cr, uid, context.get('survey_id',False)) + tot_page_id = self.pool.get('survey').browse(cr, uid, context.get('survey_id', False)) tot_per = (float(100) * (int(field.split('_')[2]) + 1) / len(tot_page_id.page_ids)) value[field] = tot_per response_obj = self.pool.get('survey.response') surv_name_wiz = self.pool.get('survey.name.wiz') - if context.has_key('response_id') and context.get('response_id') and int(context['response_id'][0]) > 0: - data = super(survey_question_wiz, self).default_get(cr, uid, fields_list, context) + if context.get('response_id') and int(context['response_id'][0]) > 0: response_ans = response_obj.browse(cr, uid, context['response_id'][context['response_no']]) fields_list.sort() @@ -489,7 +485,7 @@ class survey_question_wiz(osv.osv_memory): if que.response_table_ids and len(field.split('_')) == 4 and field.split('_')[1] == "table": for ans in que.response_table_ids: - if str(field.split('_')[2]) == str(ans.column_id.id) and str(field.split('_')[3]) == str(ans.name): + if str(field.split('_')[2]) == str(ans.column_id.id) and str(field.split('_')[3]) == str(ans.name): value[field] = ans.value if que.comment and (field.split('_')[1] == "comment" or field.split('_')[1] == "other"): @@ -500,7 +496,7 @@ class survey_question_wiz(osv.osv_memory): elif que.response_answer_ids and len(field.split('_')) == 3 and field.split('_')[1] == "selection": for ans in que.response_answer_ids: - if str(field.split('_')[2]) == str( ans.answer_id.id): + if str(field.split('_')[2]) == str(ans.answer_id.id): value[field] = str(ans.column_id.id) elif que.response_answer_ids and len(field.split('_')) == 2 and field.split('_')[1] == "selection": @@ -508,7 +504,7 @@ class survey_question_wiz(osv.osv_memory): elif que.response_answer_ids and len(field.split('_')) == 3 and field.split('_')[2] != "multi" and field.split('_')[2] != "numeric": for ans in que.response_answer_ids: - if str(field.split('_')[1]) == str( ans.answer_id.id) and str(field.split('_')[2]) == str(ans.column_id.id): + if str(field.split('_')[1]) == str(ans.answer_id.id) and str(field.split('_')[2]) == str(ans.column_id.id): if ans.value_choice: value[field] = ans.value_choice else: @@ -516,19 +512,17 @@ class survey_question_wiz(osv.osv_memory): else: for ans in que.response_answer_ids: - if str(field.split('_')[1]) == str( ans.answer_id.id): + if str(field.split('_')[1]) == str(ans.answer_id.id): value[field] = ans.answer else: - - if not context.has_key('sur_name_id'): + if not context.get('sur_name_id'): return value - if context.has_key('active') and context.get('active',False): + if context.get('active', False): return value - sur_name_read = surv_name_wiz.read(cr, uid, context.get('sur_name_id',False)) - ans_list = [] + sur_name_read = surv_name_wiz.read(cr, uid, context.get('sur_name_id', False)) - for key,val in safe_eval(sur_name_read.get('store_ans',"{}")).items(): + for key, val in safe_eval(sur_name_read.get('store_ans', "{}")).items(): for field in fields_list: if field in list(val): value[field] = val[field] @@ -538,16 +532,20 @@ class survey_question_wiz(osv.osv_memory): """ Create the Answer of survey and store in survey.response object, and if set validation of question then check the value of question if value is wrong then raise the exception. """ - if context is None: context = {} + context = context or {} - survey_question_wiz_id = super(survey_question_wiz,self).create(cr, uid, {'name': vals.get('name')}, context=context) - if context.get('active',False): + check_token = self._check_token(cr, uid, context['survey_id'], context) + if not check_token['partner_id'] and not check_token['response_id']: + return False + + survey_question_wiz_id = super(survey_question_wiz, self).create(cr, uid, {'name': vals.get('name')}, context=context) + if context.get('active', False): return survey_question_wiz_id - for key,val in vals.items(): + for key, val in vals.items(): if key.split('_')[0] == "progress": vals.pop(key) - if not context.has_key('sur_name_id') and key.split('_')[0] == "wizardid": + if not context.get('sur_name_id') and key.split('_')[0] == "wizardid": context.update({'sur_name_id': int(key.split('_')[1])}) vals.pop(key) @@ -560,36 +558,31 @@ class survey_question_wiz(osv.osv_memory): resp_obj = self.pool.get('survey.response.line') res_ans_obj = self.pool.get('survey.response.answer') que_obj = self.pool.get('survey.question') - sur_name_read = surv_name_wiz.read(cr, uid, context.get('sur_name_id',False), []) - partner_id = self.pool.get('res.users').browse(cr, uid, uid, context).partner_id.id - response_id = 0 + sur_name_read = surv_name_wiz.read(cr, uid, context.get('sur_name_id', False), []) + response_id = 0 if not sur_name_read['response']: - response_id = surv_all_resp_obj.create(cr, uid, {'response_type':'link', 'partner_id':partner_id, 'date_create':datetime.now(), 'survey_id' : context['survey_id']}) - surv_name_wiz.write(cr, uid, [context.get('sur_name_id', False)], {'response' : tools.ustr(response_id)}) + response_id = surv_all_resp_obj.create(cr, uid, {'response_type': 'link', 'partner_id': check_token['partner_id'], 'date_create': datetime.now(), 'survey_id': context['survey_id']}) + surv_name_wiz.write(cr, uid, [context.get('sur_name_id', False)], {'response': tools.ustr(response_id)}) else: response_id = int(sur_name_read['response']) if response_id not in surv_all_resp_obj.search(cr, uid, []): - response_id = surv_all_resp_obj.create(cr, uid, {'response_type':'link', 'partner_id':partner_id, 'date_create':datetime.now(), 'survey_id' : context.get('survey_id',False)}) - surv_name_wiz.write(cr, uid, [context.get('sur_name_id',False)], {'response' : tools.ustr(response_id)}) + response_id = surv_all_resp_obj.create(cr, uid, {'response_type': 'link', 'partner_id': check_token['partner_id'], 'date_create': datetime.now(), 'survey_id': context.get('survey_id', False)}) + surv_name_wiz.write(cr, uid, [context.get('sur_name_id', False)], {'response': tools.ustr(response_id)}) #click first time on next button then increemnet on total start suvey if not safe_eval(sur_name_read['store_ans']): - his_id = self.pool.get('survey.history').create(cr, uid, {'partner_id': partner_id, \ - 'date': strftime('%Y-%m-%d %H:%M:%S'), 'survey_id': sur_name_read['survey_id'][0]}) survey_id = sur_name_read['survey_id'][0] - sur_rec = survey_obj.read(cr, uid, survey_id) - survey_obj.write(cr, uid, survey_id, {'tot_start_survey' : sur_rec['tot_start_survey'] + 1}) - if context.has_key('cur_id'): - if context.get('request',False): - self.pool.get(context.get('object',False)).write(cr, uid, [int(context.get('cur_id',False))], {'response' : response_id}) - self.pool.get(context.get('object',False)).survey_req_done(cr, uid, [int(context.get('cur_id'))], context) - else: - self.pool.get(context.get('object',False)).write(cr, uid, [int(context.get('cur_id',False))], {'response' : response_id}) + survey_browse = survey_obj.read(cr, uid, survey_id) + survey_obj.write(cr, uid, survey_id, {'tot_start_survey': survey_browse['tot_start_survey'] + 1}) + if context.get('cur_id'): + self.pool.get(context.get('object', False)).write(cr, uid, [int(context.get('cur_id', False))], {'response': response_id}) + if context.get('request', False): + self.pool.get(context.get('object', False)).survey_req_done(cr, uid, [int(context.get('cur_id'))], context) if sur_name_read['store_ans'] and type(safe_eval(sur_name_read['store_ans'])) == dict: sur_name_read['store_ans'] = safe_eval(sur_name_read['store_ans']) - for key,val in sur_name_read['store_ans'].items(): + for key, val in sur_name_read['store_ans'].items(): for field in vals: if field.split('_')[0] == val['question_id']: click_state = False @@ -605,7 +598,7 @@ class survey_question_wiz(osv.osv_memory): if que_id not in que_li: que_li.append(que_id) que_rec = que_obj.read(cr, uid, [int(que_id)], [])[0] - res_data = { + res_data = { 'question_id': que_id, 'date_create': datetime.now(), 'state': 'done', @@ -613,8 +606,8 @@ class survey_question_wiz(osv.osv_memory): } resp_id = resp_obj.create(cr, uid, res_data) resp_id_list.append(resp_id) - sur_name_read['store_ans'].update({resp_id:{'question_id':que_id}}) - surv_name_wiz.write(cr, uid, [context.get('sur_name_id',False)], {'store_ans':sur_name_read['store_ans']}) + sur_name_read['store_ans'].update({resp_id: {'question_id': que_id}}) + surv_name_wiz.write(cr, uid, [context.get('sur_name_id', False)], {'store_ans': sur_name_read['store_ans']}) select_count = 0 numeric_sum = 0 selected_value = [] @@ -625,25 +618,25 @@ class survey_question_wiz(osv.osv_memory): for key1, val1 in vals.items(): if val1 and key1.split('_')[1] == "table" and key1.split('_')[0] == que_id: - surv_tbl_column_obj.create(cr, uid, {'response_table_id' : resp_id,'column_id':key1.split('_')[2], 'name':key1.split('_')[3], 'value' : val1}) - sur_name_read['store_ans'][resp_id].update({key1:val1}) + surv_tbl_column_obj.create(cr, uid, {'response_table_id': resp_id, 'column_id': key1.split('_')[2], 'name': key1.split('_')[3], 'value': val1}) + sur_name_read['store_ans'][resp_id].update({key1: val1}) select_count += 1 elif val1 and key1.split('_')[1] == "otherfield" and key1.split('_')[0] == que_id: comment_field = True - sur_name_read['store_ans'][resp_id].update({key1:val1}) + sur_name_read['store_ans'][resp_id].update({key1: val1}) select_count += 1 - surv_name_wiz.write(cr, uid, [context.get('sur_name_id',False)], {'store_ans':sur_name_read['store_ans']}) + surv_name_wiz.write(cr, uid, [context.get('sur_name_id', False)], {'store_ans': sur_name_read['store_ans']}) continue elif val1 and key1.split('_')[1] == "selection" and key1.split('_')[0] == que_id: if len(key1.split('_')) > 2: - ans_create_id = res_ans_obj.create(cr, uid, {'response_id':resp_id, 'answer_id':key1.split('_')[-1], 'column_id' : val1}) + ans_create_id = res_ans_obj.create(cr, uid, {'response_id': resp_id, 'answer_id': key1.split('_')[-1], 'column_id': val1}) selected_value.append(val1) response_list.append(str(ans_create_id) + "_" + str(key1.split('_')[-1])) else: - ans_create_id = res_ans_obj.create(cr, uid, {'response_id':resp_id, 'answer_id':val1}) - sur_name_read['store_ans'][resp_id].update({key1:val1}) + ans_create_id = res_ans_obj.create(cr, uid, {'response_id': resp_id, 'answer_id': val1}) + sur_name_read['store_ans'][resp_id].update({key1: val1}) select_count += 1 elif key1.split('_')[1] == "other" and key1.split('_')[0] == que_id: @@ -652,87 +645,87 @@ class survey_question_wiz(osv.osv_memory): else: error = False if que_rec['is_comment_require'] and que_rec['comment_valid_type'] == 'must_be_specific_length': - if (not val1 and que_rec['comment_minimum_no']) or len(val1) < que_rec['comment_minimum_no'] or len(val1) > que_rec['comment_maximum_no']: + if (not val1 and que_rec['comment_minimum_no']) or len(val1) < que_rec['comment_minimum_no'] or len(val1) > que_rec['comment_maximum_no']: error = True - elif que_rec['is_comment_require'] and que_rec['comment_valid_type'] in ['must_be_whole_number', 'must_be_decimal_number', 'must_be_date']: + elif que_rec['is_comment_require'] and que_rec['comment_valid_type'] in ['must_be_whole_number', 'must_be_decimal_number', 'must_be_date']: error = False try: if que_rec['comment_valid_type'] == 'must_be_whole_number': value = int(val1) - if value < que_rec['comment_minimum_no'] or value > que_rec['comment_maximum_no']: + if value < que_rec['comment_minimum_no'] or value > que_rec['comment_maximum_no']: error = True elif que_rec['comment_valid_type'] == 'must_be_decimal_number': value = float(val1) - if value < que_rec['comment_minimum_float'] or value > que_rec['comment_maximum_float']: + if value < que_rec['comment_minimum_float'] or value > que_rec['comment_maximum_float']: error = True elif que_rec['comment_valid_type'] == 'must_be_date': value = datetime.datetime.strptime(val1, "%Y-%m-%d") - if value < datetime.datetime.strptime(que_rec['comment_minimum_date'], "%Y-%m-%d") or value > datetime.datetime.strptime(que_rec['comment_maximum_date'], "%Y-%m-%d"): + if value < datetime.datetime.strptime(que_rec['comment_minimum_date'], "%Y-%m-%d") or value > datetime.datetime.strptime(que_rec['comment_maximum_date'], "%Y-%m-%d"): error = True except: error = True - elif que_rec['is_comment_require'] and que_rec['comment_valid_type'] == 'must_be_email_address': + elif que_rec['is_comment_require'] and que_rec['comment_valid_type'] == 'must_be_email_address': import re - if re.match("^[a-zA-Z0-9._%-+]+@[a-zA-Z0-9._%-]+.[a-zA-Z]{2,6}$", val1) == None: + if re.match("^[a-zA-Z0-9._%- + ] + @[a-zA-Z0-9._%-] + .[a-zA-Z]{2, 6}$", val1) == None: error = True if error: for res in resp_id_list: sur_name_read['store_ans'].pop(res) raise osv.except_osv(_('Warning!'), "'" + que_rec['question'] + "' \n" + tools.ustr(que_rec['comment_valid_err_msg'])) - resp_obj.write(cr, uid, resp_id, {'comment':val1}) - sur_name_read['store_ans'][resp_id].update({key1:val1}) + resp_obj.write(cr, uid, resp_id, {'comment': val1}) + sur_name_read['store_ans'][resp_id].update({key1: val1}) elif val1 and key1.split('_')[1] == "comment" and key1.split('_')[0] == que_id: - resp_obj.write(cr, uid, resp_id, {'comment':val1}) - sur_name_read['store_ans'][resp_id].update({key1:val1}) + resp_obj.write(cr, uid, resp_id, {'comment': val1}) + sur_name_read['store_ans'][resp_id].update({key1: val1}) select_count += 1 - elif val1 and key1.split('_')[0] == que_id and (key1.split('_')[1] == "single" or (len(key1.split('_')) > 2 and key1.split('_')[2] == 'multi')): + elif val1 and key1.split('_')[0] == que_id and (key1.split('_')[1] == "single" or (len(key1.split('_')) > 2 and key1.split('_')[2] == 'multi')): error = False if que_rec['is_validation_require'] and que_rec['validation_type'] == 'must_be_specific_length': - if (not val1 and que_rec['validation_minimum_no']) or len(val1) < que_rec['validation_minimum_no'] or len(val1) > que_rec['validation_maximum_no']: + if (not val1 and que_rec['validation_minimum_no']) or len(val1) < que_rec['validation_minimum_no'] or len(val1) > que_rec['validation_maximum_no']: error = True elif que_rec['is_validation_require'] and que_rec['validation_type'] in ['must_be_whole_number', 'must_be_decimal_number', 'must_be_date']: error = False try: if que_rec['validation_type'] == 'must_be_whole_number': value = int(val1) - if value < que_rec['validation_minimum_no'] or value > que_rec['validation_maximum_no']: + if value < que_rec['validation_minimum_no'] or value > que_rec['validation_maximum_no']: error = True elif que_rec['validation_type'] == 'must_be_decimal_number': value = float(val1) - if value < que_rec['validation_minimum_float'] or value > que_rec['validation_maximum_float']: + if value < que_rec['validation_minimum_float'] or value > que_rec['validation_maximum_float']: error = True elif que_rec['validation_type'] == 'must_be_date': value = datetime.datetime.strptime(val1, "%Y-%m-%d") - if value < datetime.datetime.strptime(que_rec['validation_minimum_date'], "%Y-%m-%d") or value > datetime.datetime.strptime(que_rec['validation_maximum_date'], "%Y-%m-%d"): + if value < datetime.datetime.strptime(que_rec['validation_minimum_date'], "%Y-%m-%d") or value > datetime.datetime.strptime(que_rec['validation_maximum_date'], "%Y-%m-%d"): error = True except: error = True elif que_rec['is_validation_require'] and que_rec['validation_type'] == 'must_be_email_address': import re - if re.match("^[a-zA-Z0-9._%-+]+@[a-zA-Z0-9._%-]+.[a-zA-Z]{2,6}$", val1) == None: + if re.match("^[a-zA-Z0-9._%- + ] + @[a-zA-Z0-9._%-] + .[a-zA-Z]{2, 6}$", val1) == None: error = True if error: for res in resp_id_list: sur_name_read['store_ans'].pop(res) raise osv.except_osv(_('Warning!'), "'" + que_rec['question'] + "' \n" + tools.ustr(que_rec['validation_valid_err_msg'])) - if key1.split('_')[1] == "single" : - resp_obj.write(cr, uid, resp_id, {'single_text':val1}) + if key1.split('_')[1] == "single": + resp_obj.write(cr, uid, resp_id, {'single_text': val1}) else: - ans_create_id = res_ans_obj.create(cr, uid, {'response_id':resp_id, 'answer_id':key1.split('_')[1], 'answer' : val1}) + ans_create_id = res_ans_obj.create(cr, uid, {'response_id': resp_id, 'answer_id': key1.split('_')[1], 'answer': val1}) - sur_name_read['store_ans'][resp_id].update({key1:val1}) + sur_name_read['store_ans'][resp_id].update({key1: val1}) select_count += 1 elif val1 and que_id == key1.split('_')[0] and len(key1.split('_')) > 2 and key1.split('_')[2] == 'numeric': - if not val1=="0": + if not val1 == "0": try: numeric_sum += int(val1) - ans_create_id = res_ans_obj.create(cr, uid, {'response_id':resp_id, 'answer_id':key1.split('_')[1], 'answer' : val1}) - sur_name_read['store_ans'][resp_id].update({key1:val1}) + ans_create_id = res_ans_obj.create(cr, uid, {'response_id': resp_id, 'answer_id': key1.split('_')[1], 'answer': val1}) + sur_name_read['store_ans'][resp_id].update({key1: val1}) select_count += 1 except: for res in resp_id_list: @@ -741,32 +734,32 @@ class survey_question_wiz(osv.osv_memory): elif val1 and que_id == key1.split('_')[0] and len(key1.split('_')) == 3: if type(val1) == type('') or type(val1) == type(u''): - ans_create_id = res_ans_obj.create(cr, uid, {'response_id':resp_id, 'answer_id':key1.split('_')[1], 'column_id' : key1.split('_')[2], 'value_choice' : val1}) - sur_name_read['store_ans'][resp_id].update({key1:val1}) + ans_create_id = res_ans_obj.create(cr, uid, {'response_id': resp_id, 'answer_id': key1.split('_')[1], 'column_id': key1.split('_')[2], 'value_choice': val1}) + sur_name_read['store_ans'][resp_id].update({key1: val1}) else: - ans_create_id = res_ans_obj.create(cr, uid, {'response_id':resp_id, 'answer_id':key1.split('_')[1], 'column_id' : key1.split('_')[2]}) - sur_name_read['store_ans'][resp_id].update({key1:True}) + ans_create_id = res_ans_obj.create(cr, uid, {'response_id': resp_id, 'answer_id': key1.split('_')[1], 'column_id': key1.split('_')[2]}) + sur_name_read['store_ans'][resp_id].update({key1: True}) matrix_list.append(key1.split('_')[0] + '_' + key1.split('_')[1]) select_count += 1 elif val1 and que_id == key1.split('_')[0] and len(key1.split('_')) == 2: - ans_create_id = res_ans_obj.create(cr, uid, {'response_id':resp_id, 'answer_id':key1.split('_')[-1], 'answer' : val1}) - sur_name_read['store_ans'][resp_id].update({key1:val1}) + ans_create_id = res_ans_obj.create(cr, uid, {'response_id': resp_id, 'answer_id': key1.split('_')[-1], 'answer': val1}) + sur_name_read['store_ans'][resp_id].update({key1: val1}) select_count += 1 - surv_name_wiz.write(cr, uid, [context.get('sur_name_id',False)], {'store_ans':sur_name_read['store_ans']}) + surv_name_wiz.write(cr, uid, [context.get('sur_name_id', False)], {'store_ans': sur_name_read['store_ans']}) - for key,val in vals.items(): + for key, val in vals.items(): if val and key.split('_')[1] == "commentcolumn" and key.split('_')[0] == que_id: for res_id in response_list: if key.split('_')[2] in res_id.split('_')[1]: - a = res_ans_obj.write(cr, uid, [res_id.split('_')[0]], {'comment_field':val}) - sur_name_read['store_ans'][resp_id].update({key:val}) + a = res_ans_obj.write(cr, uid, [res_id.split('_')[0]], {'comment_field': val}) + sur_name_read['store_ans'][resp_id].update({key: val}) if comment_field and comment_value: for res in resp_id_list: sur_name_read['store_ans'].pop(res) - raise osv.except_osv(_('Warning!'), "'" + que_rec['question'] + "' " + tools.ustr(que_rec['make_comment_field_err_msg'])) + raise osv.except_osv(_('Warning!'), "'" + que_rec['question'] + "' " + tools.ustr(que_rec['make_comment_field_err_msg'])) if que_rec['type'] == "rating_scale" and que_rec['rating_allow_one_column_require'] and len(selected_value) > len(list(set(selected_value))): for res in resp_id_list: @@ -774,14 +767,14 @@ class survey_question_wiz(osv.osv_memory): raise osv.except_osv(_('Warning!'), "'" + que_rec['question'] + "'\n" + _("You cannot select the same answer more than one time.")) if not select_count: - resp_obj.write(cr, uid, resp_id, {'state':'skip'}) + resp_obj.write(cr, uid, resp_id, {'state': 'skip'}) if que_rec['numeric_required_sum'] and numeric_sum > que_rec['numeric_required_sum']: for res in resp_id_list: sur_name_read['store_ans'].pop(res) raise osv.except_osv(_('Warning!'), "'" + que_rec['question'] + "' " + tools.ustr(que_rec['numeric_required_sum_err_msg'])) - if que_rec['type'] in ['multiple_textboxes_diff_type', 'multiple_choice_multiple_ans','matrix_of_choices_only_one_ans','matrix_of_choices_only_multi_ans','rating_scale','multiple_textboxes','numerical_textboxes','date','date_and_time'] and que_rec['is_require_answer']: + if que_rec['type'] in ['multiple_textboxes_diff_type', 'multiple_choice_multiple_ans', 'matrix_of_choices_only_one_ans', 'matrix_of_choices_only_multi_ans', 'rating_scale', 'multiple_textboxes', 'numerical_textboxes', 'date', 'date_and_time'] and que_rec['is_require_answer']: if matrix_list: if (que_rec['required_type'] == 'all' and len(list(set(matrix_list))) < len(que_rec['answer_choice_ids'])) or \ (que_rec['required_type'] == 'at least' and len(list(set(matrix_list))) < que_rec['req_ans']) or \ @@ -801,7 +794,7 @@ class survey_question_wiz(osv.osv_memory): sur_name_read['store_ans'].pop(res) raise osv.except_osv(_('Warning!'), "'" + que_rec['question'] + "' " + tools.ustr(que_rec['req_error_msg'])) - if que_rec['type'] in ['multiple_choice_only_one_ans','single_textbox','comment'] and que_rec['is_require_answer'] and select_count <= 0: + if que_rec['type'] in ['multiple_choice_only_one_ans', 'single_textbox', 'comment'] and que_rec['is_require_answer'] and select_count <= 0: for res in resp_id_list: sur_name_read['store_ans'].pop(res) raise osv.except_osv(_('Warning!'), "'" + que_rec['question'] + "' " + tools.ustr(que_rec['req_error_msg'])) @@ -809,12 +802,12 @@ class survey_question_wiz(osv.osv_memory): else: resp_id_list = [] for update in click_update: - que_rec = que_obj.read(cr, uid , [int(sur_name_read['store_ans'][update]['question_id'])], [])[0] - res_ans_obj.unlink(cr, uid,res_ans_obj.search(cr, uid, [('response_id', '=', update)])) - surv_tbl_column_obj.unlink(cr, uid,surv_tbl_column_obj.search(cr, uid, [('response_table_id', '=', update)])) + que_rec = que_obj.read(cr, uid, [int(sur_name_read['store_ans'][update]['question_id'])], [])[0] + res_ans_obj.unlink(cr, uid, res_ans_obj.search(cr, uid, [('response_id', '=', update)])) + surv_tbl_column_obj.unlink(cr, uid, surv_tbl_column_obj.search(cr, uid, [('response_table_id', '=', update)])) resp_id_list.append(update) - sur_name_read['store_ans'].update({update:{'question_id':sur_name_read['store_ans'][update]['question_id']}}) - surv_name_wiz.write(cr, uid, [context.get('sur_name_id',False)], {'store_ans':sur_name_read['store_ans']}) + sur_name_read['store_ans'].update({update: {'question_id': sur_name_read['store_ans'][update]['question_id']}}) + surv_name_wiz.write(cr, uid, [context.get('sur_name_id', False)], {'store_ans': sur_name_read['store_ans']}) select_count = 0 numeric_sum = 0 selected_value = [] @@ -827,26 +820,26 @@ class survey_question_wiz(osv.osv_memory): ans_id_len = key.split('_') if ans_id_len[0] == sur_name_read['store_ans'][update]['question_id']: if val and key.split('_')[1] == "table": - surv_tbl_column_obj.create(cr, uid, {'response_table_id' : update,'column_id':key.split('_')[2], 'name':key.split('_')[3], 'value' : val}) - sur_name_read['store_ans'][update].update({key:val}) + surv_tbl_column_obj.create(cr, uid, {'response_table_id': update, 'column_id': key.split('_')[2], 'name': key.split('_')[3], 'value': val}) + sur_name_read['store_ans'][update].update({key: val}) resp_obj.write(cr, uid, update, {'state': 'done'}) - elif val and key.split('_')[1] == "otherfield" : + elif val and key.split('_')[1] == "otherfield": comment_field = True - sur_name_read['store_ans'][update].update({key:val}) + sur_name_read['store_ans'][update].update({key: val}) select_count += 1 - surv_name_wiz.write(cr, uid, [context.get('sur_name_id',False)], {'store_ans':sur_name_read['store_ans']}) + surv_name_wiz.write(cr, uid, [context.get('sur_name_id', False)], {'store_ans': sur_name_read['store_ans']}) continue elif val and key.split('_')[1] == "selection": if len(key.split('_')) > 2: - ans_create_id = res_ans_obj.create(cr, uid, {'response_id':update, 'answer_id':key.split('_')[-1], 'column_id' : val}) + ans_create_id = res_ans_obj.create(cr, uid, {'response_id': update, 'answer_id': key.split('_')[-1], 'column_id': val}) selected_value.append(val) response_list.append(str(ans_create_id) + "_" + str(key.split('_')[-1])) else: - ans_create_id = res_ans_obj.create(cr, uid, {'response_id':update, 'answer_id': val}) + ans_create_id = res_ans_obj.create(cr, uid, {'response_id': update, 'answer_id': val}) resp_obj.write(cr, uid, update, {'state': 'done'}) - sur_name_read['store_ans'][update].update({key:val}) + sur_name_read['store_ans'][update].update({key: val}) select_count += 1 elif key.split('_')[1] == "other": @@ -854,82 +847,82 @@ class survey_question_wiz(osv.osv_memory): comment_value = True else: error = False - if que_rec['is_comment_require'] and que_rec['comment_valid_type'] == 'must_be_specific_length': - if (not val and que_rec['comment_minimum_no']) or len(val) < que_rec['comment_minimum_no'] or len(val) > que_rec['comment_maximum_no']: + if que_rec['is_comment_require'] and que_rec['comment_valid_type'] == 'must_be_specific_length': + if (not val and que_rec['comment_minimum_no']) or len(val) < que_rec['comment_minimum_no'] or len(val) > que_rec['comment_maximum_no']: error = True - elif que_rec['is_comment_require'] and que_rec['comment_valid_type'] in ['must_be_whole_number', 'must_be_decimal_number', 'must_be_date']: + elif que_rec['is_comment_require'] and que_rec['comment_valid_type'] in ['must_be_whole_number', 'must_be_decimal_number', 'must_be_date']: try: if que_rec['comment_valid_type'] == 'must_be_whole_number': value = int(val) - if value < que_rec['comment_minimum_no'] or value > que_rec['comment_maximum_no']: + if value < que_rec['comment_minimum_no'] or value > que_rec['comment_maximum_no']: error = True elif que_rec['comment_valid_type'] == 'must_be_decimal_number': value = float(val) - if value < que_rec['comment_minimum_float'] or value > que_rec['comment_maximum_float']: + if value < que_rec['comment_minimum_float'] or value > que_rec['comment_maximum_float']: error = True elif que_rec['comment_valid_type'] == 'must_be_date': value = datetime.datetime.strptime(val, "%Y-%m-%d") - if value < datetime.datetime.strptime(que_rec['comment_minimum_date'], "%Y-%m-%d") or value > datetime.datetime.strptime(que_rec['comment_maximum_date'], "%Y-%m-%d"): + if value < datetime.datetime.strptime(que_rec['comment_minimum_date'], "%Y-%m-%d") or value > datetime.datetime.strptime(que_rec['comment_maximum_date'], "%Y-%m-%d"): error = True except: error = True - elif que_rec['is_comment_require'] and que_rec['comment_valid_type'] == 'must_be_email_address': + elif que_rec['is_comment_require'] and que_rec['comment_valid_type'] == 'must_be_email_address': import re - if re.match("^[a-zA-Z0-9._%-+]+@[a-zA-Z0-9._%-]+.[a-zA-Z]{2,6}$", val) == None: + if re.match("^[a-zA-Z0-9._%- + ] + @[a-zA-Z0-9._%-] + .[a-zA-Z]{2, 6}$", val) == None: error = True if error: raise osv.except_osv(_('Warning!'), "'" + que_rec['question'] + "' \n" + tools.ustr(que_rec['comment_valid_err_msg'])) - resp_obj.write(cr, uid, update, {'comment':val,'state': 'done'}) - sur_name_read['store_ans'][update].update({key:val}) + resp_obj.write(cr, uid, update, {'comment': val, 'state': 'done'}) + sur_name_read['store_ans'][update].update({key: val}) elif val and key.split('_')[1] == "comment": - resp_obj.write(cr, uid, update, {'comment':val,'state': 'done'}) - sur_name_read['store_ans'][update].update({key:val}) + resp_obj.write(cr, uid, update, {'comment': val, 'state': 'done'}) + sur_name_read['store_ans'][update].update({key: val}) select_count += 1 - elif val and (key.split('_')[1] == "single" or (len(key.split('_')) > 2 and key.split('_')[2] == 'multi')): + elif val and (key.split('_')[1] == "single" or (len(key.split('_')) > 2 and key.split('_')[2] == 'multi')): error = False if que_rec['is_validation_require'] and que_rec['validation_type'] == 'must_be_specific_length': - if (not val and que_rec['validation_minimum_no']) or len(val) < que_rec['validation_minimum_no'] or len(val) > que_rec['validation_maximum_no']: + if (not val and que_rec['validation_minimum_no']) or len(val) < que_rec['validation_minimum_no'] or len(val) > que_rec['validation_maximum_no']: error = True elif que_rec['is_validation_require'] and que_rec['validation_type'] in ['must_be_whole_number', 'must_be_decimal_number', 'must_be_date']: error = False try: if que_rec['validation_type'] == 'must_be_whole_number': value = int(val) - if value < que_rec['validation_minimum_no'] or value > que_rec['validation_maximum_no']: + if value < que_rec['validation_minimum_no'] or value > que_rec['validation_maximum_no']: error = True elif que_rec['validation_type'] == 'must_be_decimal_number': value = float(val) - if value < que_rec['validation_minimum_float'] or value > que_rec['validation_maximum_float']: + if value < que_rec['validation_minimum_float'] or value > que_rec['validation_maximum_float']: error = True elif que_rec['validation_type'] == 'must_be_date': value = datetime.datetime.strptime(val, "%Y-%m-%d") - if value < datetime.datetime.strptime(que_rec['validation_minimum_date'], "%Y-%m-%d") or value > datetime.datetime.strptime(que_rec['validation_maximum_date'], "%Y-%m-%d"): + if value < datetime.datetime.strptime(que_rec['validation_minimum_date'], "%Y-%m-%d") or value > datetime.datetime.strptime(que_rec['validation_maximum_date'], "%Y-%m-%d"): error = True - except Exception ,e: + except Exception: error = True - elif que_rec['is_validation_require'] and que_rec['validation_type'] == 'must_be_email_address': + elif que_rec['is_validation_require'] and que_rec['validation_type'] == 'must_be_email_address': import re - if re.match("^[a-zA-Z0-9._%-+]+@[a-zA-Z0-9._%-]+.[a-zA-Z]{2,6}$", val) == None: + if re.match("^[a-zA-Z0-9._%- + ] + @[a-zA-Z0-9._%-] + .[a-zA-Z]{2, 6}$", val) == None: error = True if error: raise osv.except_osv(_('Warning!'), "'" + que_rec['question'] + "' \n" + tools.ustr(que_rec['validation_valid_err_msg'])) - if key.split('_')[1] == "single" : - resp_obj.write(cr, uid, update, {'single_text':val,'state': 'done'}) + if key.split('_')[1] == "single": + resp_obj.write(cr, uid, update, {'single_text': val, 'state': 'done'}) else: resp_obj.write(cr, uid, update, {'state': 'done'}) - ans_create_id = res_ans_obj.create(cr, uid, {'response_id':update, 'answer_id':ans_id_len[1], 'answer' : val}) - sur_name_read['store_ans'][update].update({key:val}) + ans_create_id = res_ans_obj.create(cr, uid, {'response_id': update, 'answer_id': ans_id_len[1], 'answer': val}) + sur_name_read['store_ans'][update].update({key: val}) select_count += 1 elif val and len(key.split('_')) > 2 and key.split('_')[2] == 'numeric': - if not val=="0": + if not val == "0": try: numeric_sum += int(val) resp_obj.write(cr, uid, update, {'state': 'done'}) - ans_create_id = res_ans_obj.create(cr, uid, {'response_id': update, 'answer_id':ans_id_len[1], 'answer' : val}) - sur_name_read['store_ans'][update].update({key:val}) + ans_create_id = res_ans_obj.create(cr, uid, {'response_id': update, 'answer_id': ans_id_len[1], 'answer': val}) + sur_name_read['store_ans'][update].update({key: val}) select_count += 1 except: raise osv.except_osv(_('Warning!'), "'" + que_rec['question'] + "'\n" + _("Please enter an integer value.")) @@ -937,30 +930,30 @@ class survey_question_wiz(osv.osv_memory): elif val and len(key.split('_')) == 3: resp_obj.write(cr, uid, update, {'state': 'done'}) if type(val) == type('') or type(val) == type(u''): - ans_create_id = res_ans_obj.create(cr, uid, {'response_id': update, 'answer_id':ans_id_len[1], 'column_id' : ans_id_len[2], 'value_choice' : val}) - sur_name_read['store_ans'][update].update({key:val}) + ans_create_id = res_ans_obj.create(cr, uid, {'response_id': update, 'answer_id': ans_id_len[1], 'column_id': ans_id_len[2], 'value_choice': val}) + sur_name_read['store_ans'][update].update({key: val}) else: - ans_create_id = res_ans_obj.create(cr, uid, {'response_id': update, 'answer_id':ans_id_len[1], 'column_id' : ans_id_len[2]}) - sur_name_read['store_ans'][update].update({key:True}) + ans_create_id = res_ans_obj.create(cr, uid, {'response_id': update, 'answer_id': ans_id_len[1], 'column_id': ans_id_len[2]}) + sur_name_read['store_ans'][update].update({key: True}) matrix_list.append(key.split('_')[0] + '_' + key.split('_')[1]) select_count += 1 elif val and len(key.split('_')) == 2: resp_obj.write(cr, uid, update, {'state': 'done'}) - ans_create_id = res_ans_obj.create(cr, uid, {'response_id': update, 'answer_id':ans_id_len[-1], 'answer' : val}) - sur_name_read['store_ans'][update].update({key:val}) + ans_create_id = res_ans_obj.create(cr, uid, {'response_id': update, 'answer_id': ans_id_len[-1], 'answer': val}) + sur_name_read['store_ans'][update].update({key: val}) select_count += 1 - surv_name_wiz.write(cr, uid, [context.get('sur_name_id',False)], {'store_ans': sur_name_read['store_ans']}) + surv_name_wiz.write(cr, uid, [context.get('sur_name_id', False)], {'store_ans': sur_name_read['store_ans']}) - for key,val in vals.items(): + for key, val in vals.items(): if val and key.split('_')[1] == "commentcolumn" and key.split('_')[0] == sur_name_read['store_ans'][update]['question_id']: for res_id in response_list: if key.split('_')[2] in res_id.split('_')[1]: - a = res_ans_obj.write(cr, uid, [res_id.split('_')[0]], {'comment_field':val}) - sur_name_read['store_ans'][update].update({key:val}) + res_ans_obj.write(cr, uid, [res_id.split('_')[0]], {'comment_field': val}) + sur_name_read['store_ans'][update].update({key: val}) if comment_field and comment_value: - raise osv.except_osv(_('Warning!'), "'" + que_rec['question'] + "' " + tools.ustr(que_rec['make_comment_field_err_msg'])) + raise osv.except_osv(_('Warning!'), "'" + que_rec['question'] + "' " + tools.ustr(que_rec['make_comment_field_err_msg'])) if que_rec['type'] == "rating_scale" and que_rec['rating_allow_one_column_require'] and len(selected_value) > len(list(set(selected_value))): raise osv.except_osv(_('Warning!'), "'" + que_rec['question'] + "\n" + _("You cannot select same answer more than one time.'")) @@ -971,7 +964,7 @@ class survey_question_wiz(osv.osv_memory): if not select_count: resp_obj.write(cr, uid, update, {'state': 'skip'}) - if que_rec['type'] in ['multiple_textboxes_diff_type','multiple_choice_multiple_ans','matrix_of_choices_only_one_ans','matrix_of_choices_only_multi_ans','rating_scale','multiple_textboxes','numerical_textboxes','date','date_and_time'] and que_rec['is_require_answer']: + if que_rec['type'] in ['multiple_textboxes_diff_type', 'multiple_choice_multiple_ans', 'matrix_of_choices_only_one_ans', 'matrix_of_choices_only_multi_ans', 'rating_scale', 'multiple_textboxes', 'numerical_textboxes', 'date', 'date_and_time'] and que_rec['is_require_answer']: if matrix_list: if (que_rec['required_type'] == 'all' and len(list(set(matrix_list))) < len(que_rec['answer_choice_ids'])) or \ (que_rec['required_type'] == 'at least' and len(list(set(matrix_list))) < que_rec['req_ans']) or \ @@ -987,7 +980,7 @@ class survey_question_wiz(osv.osv_memory): (que_rec['required_type'] == 'a range' and (select_count < que_rec['minimum_req_ans'] or select_count > que_rec['maximum_req_ans'])): raise osv.except_osv(_('Warning!'), "'" + que_rec['question'] + "' " + tools.ustr(que_rec['req_error_msg'])) - if que_rec['type'] in ['multiple_choice_only_one_ans','single_textbox','comment'] and que_rec['is_require_answer'] and select_count <= 0: + if que_rec['type'] in ['multiple_choice_only_one_ans', 'single_textbox', 'comment'] and que_rec['is_require_answer'] and select_count <= 0: raise osv.except_osv(_('Warning!'), "'" + que_rec['question'] + "' " + tools.ustr(que_rec['req_error_msg'])) return survey_question_wiz_id @@ -998,11 +991,11 @@ class survey_question_wiz(osv.osv_memory): """ if context is None: context = {} - for key,val in context.items(): + for key, val in context.items(): if type(key) == type(True): context.pop(key) - view_id = self.pool.get('ir.ui.view').search(cr,uid,[('model','=','survey.question'),\ - ('name','=','survey_question_wizard_test')]) + view_id = self.pool.get('ir.ui.view').search(cr, uid, [('model', '=', 'survey.question'), \ + ('name', '=', 'survey_question_wizard_test')]) return { 'view_type': 'form', "view_mode": 'form', @@ -1019,11 +1012,11 @@ class survey_question_wiz(osv.osv_memory): """ if context is None: context = {} - for key,val in context.items(): + for key, val in context.items(): if type(key) == type(True): context.pop(key) - view_id = self.pool.get('ir.ui.view').search(cr,uid,[('model','=','survey.page'),\ - ('name','=','survey_page_wizard_test')]) + view_id = self.pool.get('ir.ui.view').search(cr, uid, [('model', '=', 'survey.page'), \ + ('name', '=', 'survey_page_wizard_test')]) return { 'view_type': 'form', "view_mode": 'form', @@ -1040,18 +1033,18 @@ class survey_question_wiz(osv.osv_memory): """ if context is None: context = {} - for key,val in context.items(): + for key, val in context.items(): if type(key) == type(True): context.pop(key) - view_id = self.pool.get('ir.ui.view').search(cr,uid,[('model','=','survey.page'),\ - ('name','=','survey_page_wizard_test')]) + view_id = self.pool.get('ir.ui.view').search(cr, uid, [('model', '=', 'survey.page'), \ + ('name', '=', 'survey_page_wizard_test')]) return { 'view_type': 'form', "view_mode": 'form', 'res_model': 'survey.page', 'type': 'ir.actions.act_window', 'target': 'new', - 'res_id': int(context.get('page_id',0)), + 'res_id': int(context.get('page_id', 0)), 'view_id': view_id, 'context': context } @@ -1062,27 +1055,27 @@ class survey_question_wiz(osv.osv_memory): """ if context is None: context = {} - for key,val in context.items(): + for key, val in context.items(): if type(key) == type(True): context.pop(key) - self.pool.get('survey.page').unlink(cr, uid, [context.get('page_id',False)]) - for survey in self.pool.get('survey').browse(cr, uid, [context.get('survey_id',False)], context=context): + self.pool.get('survey.page').unlink(cr, uid, [context.get('page_id', False)]) + for survey in self.pool.get('survey').browse(cr, uid, [context.get('survey_id', False)], context=context): if not survey.page_ids: - return {'type':'ir.actions.act_window_close'} + return {'type': 'ir.actions.act_window_close'} - search_id = self.pool.get('ir.ui.view').search(cr,uid,[('model','=','survey.question.wiz'),\ - ('name','=','Survey Search')]) + search_id = self.pool.get('ir.ui.view').search(cr, uid, [('model', '=', 'survey.question.wiz'), \ + ('name', '=', 'Survey Search')]) surv_name_wiz = self.pool.get('survey.name.wiz') - surv_name_wiz.write(cr, uid, [context.get('sur_name_id',False)], \ - {'transfer':True, 'page_no' : context.get('page_number',False) }) + surv_name_wiz.write(cr, uid, [context.get('sur_name_id', False)], \ + {'transfer': True, 'page_no': context.get('page_number', False)}) return { 'view_type': 'form', "view_mode": 'form', 'res_model': 'survey.question.wiz', 'type': 'ir.actions.act_window', 'target': 'new', - 'search_view_id':search_id[0], + 'search_view_id': search_id[0], 'context': context } @@ -1092,18 +1085,18 @@ class survey_question_wiz(osv.osv_memory): """ if context is None: context = {} - for key,val in context.items(): + for key, val in context.items(): if type(key) == type(True): context.pop(key) - view_id = self.pool.get('ir.ui.view').search(cr,uid,[('model','=','survey.question'),\ - ('name','=','survey_question_wizard_test')]) + view_id = self.pool.get('ir.ui.view').search(cr, uid, [('model', '=', 'survey.question'), \ + ('name', '=', 'survey_question_wizard_test')]) return { 'view_type': 'form', "view_mode": 'form', 'res_model': 'survey.question', 'type': 'ir.actions.act_window', 'target': 'new', - 'res_id' : int(context.get('question_id',0)), + 'res_id': int(context.get('question_id', 0)), 'view_id': view_id, 'context': context } @@ -1114,17 +1107,17 @@ class survey_question_wiz(osv.osv_memory): """ if context is None: context = {} - for key,val in context.items(): + for key, val in context.items(): if type(key) == type(True): context.pop(key) que_obj = self.pool.get('survey.question') - que_obj.unlink(cr, uid, [context.get('question_id',False)]) - search_id = self.pool.get('ir.ui.view').search(cr,uid,[('model','=','survey.question.wiz'),\ - ('name','=','Survey Search')]) + que_obj.unlink(cr, uid, [context.get('question_id', False)]) + search_id = self.pool.get('ir.ui.view').search(cr, uid, [('model', '=', 'survey.question.wiz'), \ + ('name', '=', 'Survey Search')]) surv_name_wiz = self.pool.get('survey.name.wiz') - surv_name_wiz.write(cr, uid, [context.get('sur_name_id',False)],\ - {'transfer':True, 'page_no' : context.get('page_number',0) }) + surv_name_wiz.write(cr, uid, [context.get('sur_name_id', False)], \ + {'transfer': True, 'page_no': context.get('page_number', 0)}) return { 'view_type': 'form', "view_mode": 'form', @@ -1143,12 +1136,12 @@ class survey_question_wiz(osv.osv_memory): context = {} search_obj = self.pool.get('ir.ui.view') surv_name_wiz = self.pool.get('survey.name.wiz') - search_id = search_obj.search(cr,uid,[('model','=','survey.question.wiz'),\ - ('name','=','Survey Search')]) - wiz_id = surv_name_wiz.create(cr,uid, {'survey_id': context.get('survey_id',False),'page_no' :-1,'page':'next','transfer' :1,'response':0}) - context.update({'sur_name_id' :wiz_id, 'response_no': context.get('response_no',0) - 1}) + search_id = search_obj.search(cr, uid, [('model', '=', 'survey.question.wiz'), \ + ('name', '=', 'Survey Search')]) + wiz_id = surv_name_wiz.create(cr, uid, {'survey_id': context.get('survey_id', False), 'page_no': -1, 'page': 'next', 'transfer': 1, 'response': 0}) + context.update({'sur_name_id': wiz_id, 'response_no': context.get('response_no', 0) - 1}) - if context.get('response_no',0) + 1 > len(context.get('response_id',0)): + if context.get('response_no', 0) + 1 > len(context.get('response_id', 0)): return {} return { 'view_type': 'form', @@ -1168,12 +1161,12 @@ class survey_question_wiz(osv.osv_memory): context = {} search_obj = self.pool.get('ir.ui.view') surv_name_wiz = self.pool.get('survey.name.wiz') - search_id = search_obj.search(cr,uid,[('model','=','survey.question.wiz'),\ - ('name','=','Survey Search')]) - wiz_id = surv_name_wiz.create(cr,uid, {'survey_id' : context.get('survey_id',False),'page_no' :-1,'page':'next','transfer' :1,'response':0}) - context.update({'sur_name_id' :wiz_id, 'response_no' : context.get('response_no',0) + 1}) + search_id = search_obj.search(cr, uid, [('model', '=', 'survey.question.wiz'), \ + ('name', '=', 'Survey Search')]) + wiz_id = surv_name_wiz.create(cr, uid, {'survey_id': context.get('survey_id', False), 'page_no': -1, 'page': 'next', 'transfer': 1, 'response': 0}) + context.update({'sur_name_id': wiz_id, 'response_no': context.get('response_no', 0) + 1}) - if context.get('response_no',0) + 1 > len(context.get('response_id',0)): + if context.get('response_no', 0) + 1 > len(context.get('response_id', 0)): return {} return { 'view_type': 'form', @@ -1193,8 +1186,8 @@ class survey_question_wiz(osv.osv_memory): context = {} surv_name_wiz = self.pool.get('survey.name.wiz') search_obj = self.pool.get('ir.ui.view') - search_id = search_obj.search(cr,uid,[('model','=','survey.question.wiz'),('name','=','Survey Search')]) - surv_name_wiz.write(cr, uid, [context.get('sur_name_id',False)], {'transfer':True, 'page':'next'}) + search_id = search_obj.search(cr, uid, [('model', '=', 'survey.question.wiz'), ('name', '=', 'Survey Search')]) + surv_name_wiz.write(cr, uid, [context.get('sur_name_id', False)], {'transfer': True, 'page': 'next'}) return { 'view_type': 'form', "view_mode": 'form', @@ -1213,9 +1206,9 @@ class survey_question_wiz(osv.osv_memory): context = {} surv_name_wiz = self.pool.get('survey.name.wiz') search_obj = self.pool.get('ir.ui.view') - search_id = search_obj.search(cr,uid,[('model','=','survey.question.wiz'),\ - ('name','=','Survey Search')]) - surv_name_wiz.write(cr, uid, [context.get('sur_name_id',False)], {'transfer':True, 'page':'previous'}) + search_id = search_obj.search(cr, uid, [('model', '=', 'survey.question.wiz'), \ + ('name', '=', 'Survey Search')]) + surv_name_wiz.write(cr, uid, [context.get('sur_name_id', False)], {'transfer': True, 'page': 'previous'}) return { 'view_type': 'form', "view_mode": 'form', @@ -1228,4 +1221,4 @@ class survey_question_wiz(osv.osv_memory): survey_question_wiz() -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: +# vim: expandtab: smartindent: tabstop=4: softtabstop=4: shiftwidth=4: diff --git a/addons/survey/wizard/survey_selection.py b/addons/survey/wizard/survey_selection.py index 496f871394c..3eadb3802a9 100644 --- a/addons/survey/wizard/survey_selection.py +++ b/addons/survey/wizard/survey_selection.py @@ -66,23 +66,17 @@ class survey_name_wiz(osv.osv_memory): """ survey_obj = self.pool.get('survey') search_obj = self.pool.get('ir.ui.view') - if context is None: context = {} + context = context or {} this = self.browse(cr, uid, ids, context=context)[0] survey_id = this.survey_id.id context.update({'survey_id': survey_id, 'sur_name_id': this.id}) - cr.execute('select count(id) from survey_history where user_id=%s\ - and survey_id=%s' % (uid,survey_id)) - - res = cr.fetchone()[0] - sur_rec = survey_obj.browse(cr,uid,survey_id,context=context) - if sur_rec.response_user and res >= sur_rec.response_user: - raise osv.except_osv(_('Warning!'),_("You cannot give response for this survey more than %s times.") % (sur_rec.response_user)) + sur_rec = survey_obj.browse(cr, uid, survey_id, context=context) if sur_rec.max_response_limit and sur_rec.max_response_limit <= sur_rec.tot_start_survey: - raise osv.except_osv(_('Warning!'),_("You cannot give more responses. Please contact the author of this survey for further assistance.")) + raise osv.except_osv(_('Warning!'), _("You cannot give more responses. Please contact the author of this survey for further assistance.")) - search_id = search_obj.search(cr,uid,[('model','=','survey.question.wiz'),('name','=','Survey Search')]) + search_id = search_obj.search(cr, uid, [('model', '=', 'survey.question.wiz'), ('name', '=', 'Survey Search')]) return { 'view_type': 'form', "view_mode": 'form', diff --git a/addons/survey/wizard/survey_selection.xml b/addons/survey/wizard/survey_selection.xml index de1231b53fb..41feba775c6 100644 --- a/addons/survey/wizard/survey_selection.xml +++ b/addons/survey/wizard/survey_selection.xml @@ -5,7 +5,7 @@ Display Survey List --> - + From 6d0a71f546e5458165bf764108a95e7ca6216f0d Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Fri, 15 Feb 2013 14:09:24 +0100 Subject: [PATCH 0029/1010] [IMP] survey: check_token, view for survey response bzr revid: chm@openerp.com-20130215130924-uiy66a1q9n5yqoud --- addons/survey/security/ir.model.access.csv | 3 - addons/survey/survey.py | 69 +++------- addons/survey/survey_view.xml | 152 ++++++++------------- addons/survey/wizard/survey_answer.py | 58 ++++---- 4 files changed, 105 insertions(+), 177 deletions(-) diff --git a/addons/survey/security/ir.model.access.csv b/addons/survey/security/ir.model.access.csv index b613e223afa..a410959376e 100644 --- a/addons/survey/security/ir.model.access.csv +++ b/addons/survey/security/ir.model.access.csv @@ -1,6 +1,5 @@ id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink access_survey_type_manager,survey.type.manager,model_survey_type,base.group_tool_manager,1,1,1,1 -access_survey_request_manager,survey.request manager,model_survey_request,base.group_tool_manager,1,1,1,1 access_survey_tbl_column_heading_manager,survey.tbl.column.heading manager,model_survey_tbl_column_heading,base.group_tool_manager,1,1,1,1 access_survey_res_partner_user,survey.res.partner.user,base.model_res_partner,base.group_tool_user,1,1,1,1 access_survey_user,survey.user,model_survey,base.group_tool_user,1,1,1,1 @@ -9,7 +8,6 @@ access_survey_question_user,survey.question user,model_survey_question,base.grou access_survey_answer_user,survey.answer user,model_survey_answer,base.group_tool_user,1,1,1,1 access_survey_response_user,survey.response user,model_survey_response,base.group_tool_user,1,1,1,1 access_survey_response_answer_user,survey.response.answer user,model_survey_response_answer,base.group_tool_user,1,1,1,1 -access_survey_history_user,survey.history.user,model_survey_history,base.group_tool_user,1,1,1,1 access_survey_response_line_user,survey.response.line user,model_survey_response_line,base.group_tool_user,1,1,1,1 access_survey_res_partner_user,survey.res.partner.user,base.model_res_partner,base.group_tool_user,1,1,1,1 access_survey_survey_user,survey.survey.user,model_survey,base.group_survey_user,1,1,1,1 @@ -18,7 +16,6 @@ access_survey_question_survey_user,survey.question.survey.user,model_survey_ques access_survey_answer_survey_user,survey.answer.survey.user,model_survey_answer,base.group_survey_user,1,1,1,1 access_survey_response_survey_user,survey.response.survey.user,model_survey_response,base.group_survey_user,1,1,1,1 access_survey_response_answer_survey_user,survey.response.answer.survey.user,model_survey_response_answer,base.group_survey_user,1,1,1,1 -access_survey_history_survey_user,survey.history.survey.user,model_survey_history,base.group_survey_user,1,1,1,1 access_survey_response_line_survey_user,survey.response.line.survey.user,model_survey_response_line,base.group_survey_user,1,1,1,1 access_survey_question_column_heading_survey_user,survey.question.column.heading.survey.user,model_survey_question_column_heading,base.group_survey_user,1,0,0,0 access_survey_question_column_heading_user,survey.question.column.heading user,model_survey_question_column_heading,base.group_tool_user,1,1,1,1 diff --git a/addons/survey/survey.py b/addons/survey/survey.py index 79f30df1a37..e578326cc71 100644 --- a/addons/survey/survey.py +++ b/addons/survey/survey.py @@ -20,15 +20,12 @@ ############################################################################## import copy -from datetime import datetime -from dateutil.relativedelta import relativedelta from time import strftime -import os -from openerp import netsvc, tools from openerp.osv import fields, osv from openerp.tools.translate import _ + class survey_type(osv.osv): _name = 'survey.type' _description = 'Survey Type' @@ -38,6 +35,7 @@ class survey_type(osv.osv): } survey_type() + class survey(osv.osv): _name = 'survey' _description = 'Survey' @@ -231,6 +229,7 @@ class survey(osv.osv): survey() + class survey_page(osv.osv): _name = 'survey.page' _description = 'Survey Pages' @@ -281,6 +280,7 @@ class survey_page(osv.osv): survey_page() + class survey_question(osv.osv): _name = 'survey.question' _description = 'Survey Question' @@ -592,6 +592,7 @@ class survey_question_column_heading(osv.osv): } survey_question_column_heading() + class survey_answer(osv.osv): _name = 'survey.answer' _description = 'Survey Answer' @@ -649,19 +650,20 @@ class survey_answer(osv.osv): survey_answer() + class survey_response(osv.osv): _name = "survey.response" _rec_name = 'date_create' _columns = { 'date_deadline': fields.date("Deadline date", help="Date by which the person can respond to the survey"), - 'survey_id' : fields.many2one('survey', 'Survey', required=1, ondelete='cascade'), + 'survey_id' : fields.many2one('survey', 'Survey', required=1, readonly=1, ondelete='cascade'), 'date_create' : fields.datetime('Create Date', required=1), - 'response_type' : fields.selection([('manually', 'Manually'), ('link', 'Link')], 'Answer Type', required=1, readonly=1), + 'response_type' : fields.selection([('manually', 'Manually'), ('link', 'Link')], 'Answer Type', required=1), 'question_ids' : fields.one2many('survey.response.line', 'response_id', 'Answer'), - 'state' : fields.selection([('new', 'Not Started'),('done', 'Finished'),('skip', 'Not Finished')], 'Status', readonly=True), - 'token': fields.char("Indentification token"), - 'partner_id' : fields.many2one('res.partner', 'Partner'), - 'email': fields.char("Email", size=64), + 'state' : fields.selection([('new', 'Wait answer'), ('done', 'Finished'), ('skip', 'Not Finished')], 'Status', readonly=True), + 'token': fields.char("Indentification token", readonly=1), + 'partner_id' : fields.many2one('res.partner', 'Partner', readonly=1), + 'email': fields.char("Email", size=64, readonly=1), } _defaults = { 'state' : lambda * a: "new", @@ -683,6 +685,7 @@ class survey_response(osv.osv): survey_response() + class survey_response_line(osv.osv): _name = 'survey.response.line' _description = 'Survey Response Line' @@ -707,6 +710,7 @@ class survey_response_line(osv.osv): survey_response_line() + class survey_tbl_column_heading(osv.osv): _name = 'survey.tbl.column.heading' _order = 'name' @@ -719,6 +723,7 @@ class survey_tbl_column_heading(osv.osv): survey_tbl_column_heading() + class survey_response_answer(osv.osv): _name = 'survey.response.answer' _description = 'Survey Answer' @@ -735,6 +740,7 @@ class survey_response_answer(osv.osv): survey_response_answer() + class res_partner(osv.osv): _inherit = "res.partner" _name = "res.partner" @@ -743,47 +749,4 @@ class res_partner(osv.osv): } res_partner() -class survey_request(osv.osv): - _name = "survey.request" - _order = 'date_deadline' - _rec_name = 'date_deadline' - - _columns = { - 'date_deadline': fields.date("Deadline date"), - 'token': fields.char("Indentification token"), - 'partner_id': fields.many2one("res.partner", "Partner"), - 'email': fields.char("Email", size=64), - 'survey_id': fields.many2one("survey", "Survey", required=1, ondelete='cascade'), - 'response_id': fields.many2one('survey.response', 'Answer'), - 'state': fields.selection([('draft','Draft'),('cancel', 'Cancelled'),('waiting_answer', 'Waiting Answer'),('done', 'Done')], 'Status', readonly=1) - } - _defaults = { - 'state': lambda * a: 'draft', -# 'date_deadline': lambda * a : (datetime.now() + relativedelta(months=+1)).strftime("%Y-%m-%d %H:%M:%S") - } - def survey_req_waiting_answer(self, cr, uid, ids, arg): - self.write(cr, uid, ids, { 'state' : 'waiting_answer'}) - return True - - def survey_req_draft(self, cr, uid, ids, arg): - self.write(cr, uid, ids, { 'state' : 'draft'}) - return True - - def survey_req_done(self, cr, uid, ids, arg): - self.write(cr, uid, ids, { 'state' : 'done'}) - return True - - def survey_req_cancel(self, cr, uid, ids, arg): - self.write(cr, uid, ids, { 'state' : 'cancel'}) - return True - - def on_change_partner(self, cr, uid, ids, partner_id, context=None): - if partner_id: - partner_obj = self.pool.get('res.partner') - partner = partner_obj.browse(cr, uid, partner_id, context=context) - return {'value': {'email': partner.email}} - return {} - -survey_request() - # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/survey/survey_view.xml b/addons/survey/survey_view.xml index 68b5cd575cb..23f3adbb33e 100644 --- a/addons/survey/survey_view.xml +++ b/addons/survey/survey_view.xml @@ -999,17 +999,46 @@ Survey Response --> - - survey_response_form + + survey_response_search survey.response -
+ - + - - - + + + + + + + + + + + survey_response_tree + survey.response + + +
+ +
+ + + + + + + + + + + + + + +
@@ -1018,16 +1047,36 @@ survey_response_tree survey.response - + + +
+ + Survey Type + survey.response + form + tree,form + + + +

+ Nobody have reply to your surveys. +

+
+
+ + + @@ -1080,86 +1129,6 @@
- - - - survey_request_form - survey.request - -
-
-
- - - - - - - - - -
-
-
- - - survey_request_tree - survey.request - - - - - - - - - - - - - - survey_request_search - survey.request - - - - - - - - - - - - - - - - - - - - - Survey Requests - survey.request - form - tree,form - ['|', ('partner_id.user_id.id','=',uid), ('survey_id.responsible_id.id','=',uid)] - - - - - - @@ -1222,12 +1191,5 @@ res_model="survey.answer" src_model="survey.question"/> - - diff --git a/addons/survey/wizard/survey_answer.py b/addons/survey/wizard/survey_answer.py index a6a5652ebca..8832f10398d 100644 --- a/addons/survey/wizard/survey_answer.py +++ b/addons/survey/wizard/survey_answer.py @@ -209,24 +209,31 @@ class survey_question_wiz(osv.osv_memory): def _check_token(self, cr, uid, survey_id, context): # get if the token of the partner or anonymous user is valid + res = {'partner_id': False, 'response_id': False, 'state': None} + + if not survey_id: + return res + survey_browse = self.pool.get('survey').browse(cr, uid, survey_id, context=context) + if False and survey_browse.responsible_id.id == uid: + res['partner_id'] = survey_browse.responsible_id.partner_id.id or False + return res - if survey_browse.responsible_id.id == uid: - response_id = False - partner_id = survey_browse.responsible_id.partner_id.id or False + sur_response_obj = self.pool.get('survey.response') + dom = [('survey_id', '=', survey_id), ('state', 'in', ['new', 'skip']), "|", ('date_deadline', '=', None), ('date_deadline', '<', datetime.now())] + + if context.get("survey_token", None): + response_id = sur_response_obj.search(cr, uid, dom + [("token", "=", context.get("survey_token", None))], context=context, limit=1, order="date_deadline DESC") else: - sur_response_obj = self.pool.get('survey.response') - pid = self.pool.get('res.users').browse(cr, uid, uid, context=context).partner_id.id - response_id = sur_response_obj.search(cr, uid, [ - ('survey_id', '=', survey_browse.id), ('state', '=', 'new'), - '|', ('partner_id', '=', pid), ("token", "=", context.get("survey_token", None)), - '|', ('date_deadline', '=', None), ('date_deadline', '<', datetime.now())], context=context, limit=1) - if response_id: - sur_response_browse = sur_response_obj.browse(cr, uid, response_id[0], context=context) - partner_id = sur_response_browse.partner_id.id or False + response_id = sur_response_obj.search(cr, uid, dom + [('partner_id', '=', pid)], context=context, limit=1, order="date_deadline DESC") - return {'partner_id': partner_id or False, 'response_id': response_id and response_id[0] or False} + if response_id: + sur_response_browse = sur_response_obj.browse(cr, uid, response_id[0], context=context) + res['partner_id'] = sur_response_browse.partner_id.id or False + res['state'] = sur_response_browse.state + + return res def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False): """ @@ -469,10 +476,10 @@ class survey_question_wiz(osv.osv_memory): tot_page_id = self.pool.get('survey').browse(cr, uid, context.get('survey_id', False)) tot_per = (float(100) * (int(field.split('_')[2]) + 1) / len(tot_page_id.page_ids)) value[field] = tot_per - response_obj = self.pool.get('survey.response') + sur_response_obj = self.pool.get('survey.response') surv_name_wiz = self.pool.get('survey.name.wiz') if context.get('response_id') and int(context['response_id'][0]) > 0: - response_ans = response_obj.browse(cr, uid, context['response_id'][context['response_no']]) + response_ans = sur_response_obj.browse(cr, uid, context['response_id'][context['response_no']]) fields_list.sort() for que in response_ans.question_ids: @@ -552,26 +559,25 @@ class survey_question_wiz(osv.osv_memory): click_state = True click_update = [] surv_name_wiz = self.pool.get('survey.name.wiz') - surv_all_resp_obj = self.pool.get('survey.response') + sur_response_obj = self.pool.get('survey.response') surv_tbl_column_obj = self.pool.get('survey.tbl.column.heading') survey_obj = self.pool.get('survey') resp_obj = self.pool.get('survey.response.line') res_ans_obj = self.pool.get('survey.response.answer') que_obj = self.pool.get('survey.question') - sur_name_read = surv_name_wiz.read(cr, uid, context.get('sur_name_id', False), []) - response_id = 0 + sur_name_read = surv_name_wiz.read(cr, uid, context.get('sur_name_id', False), context=context) if not sur_name_read['response']: - response_id = surv_all_resp_obj.create(cr, uid, {'response_type': 'link', 'partner_id': check_token['partner_id'], 'date_create': datetime.now(), 'survey_id': context['survey_id']}) - surv_name_wiz.write(cr, uid, [context.get('sur_name_id', False)], {'response': tools.ustr(response_id)}) - else: response_id = int(sur_name_read['response']) + elif check_token['response_id']: + response_id = check_token['response_id'] + else: + response_id = sur_response_obj.create(cr, uid, {'response_type': 'link', 'partner_id': check_token['partner_id'], 'date_create': datetime.now(), 'survey_id': context.get('survey_id')}) - if response_id not in surv_all_resp_obj.search(cr, uid, []): - response_id = surv_all_resp_obj.create(cr, uid, {'response_type': 'link', 'partner_id': check_token['partner_id'], 'date_create': datetime.now(), 'survey_id': context.get('survey_id', False)}) - surv_name_wiz.write(cr, uid, [context.get('sur_name_id', False)], {'response': tools.ustr(response_id)}) + surv_name_wiz.write(cr, uid, [context.get('sur_name_id', False)], {'response': tools.ustr(response_id)}) + sur_response_obj.write(cr, uid, response_id, {'state': 'skip'}) - #click first time on next button then increemnet on total start suvey + #click first time on next button then increment on total start suvey if not safe_eval(sur_name_read['store_ans']): survey_id = sur_name_read['survey_id'][0] survey_browse = survey_obj.read(cr, uid, survey_id) @@ -753,7 +759,7 @@ class survey_question_wiz(osv.osv_memory): if val and key.split('_')[1] == "commentcolumn" and key.split('_')[0] == que_id: for res_id in response_list: if key.split('_')[2] in res_id.split('_')[1]: - a = res_ans_obj.write(cr, uid, [res_id.split('_')[0]], {'comment_field': val}) + res_ans_obj.write(cr, uid, [res_id.split('_')[0]], {'comment_field': val}) sur_name_read['store_ans'][resp_id].update({key: val}) if comment_field and comment_value: From d30f143ac2592dd73ba64616a15c764a4d10fb21 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Fri, 15 Feb 2013 14:40:58 +0100 Subject: [PATCH 0030/1010] [IMP] survey: clean in progress bzr revid: chm@openerp.com-20130215134058-ipzanp6atqndzbnu --- addons/survey/survey.py | 3 +- addons/survey/survey_view.xml | 12 ++-- addons/survey/wizard/survey_answer.py | 78 ++---------------------- addons/survey/wizard/survey_selection.py | 51 ---------------- 4 files changed, 13 insertions(+), 131 deletions(-) diff --git a/addons/survey/survey.py b/addons/survey/survey.py index e578326cc71..2de955031c9 100644 --- a/addons/survey/survey.py +++ b/addons/survey/survey.py @@ -64,7 +64,6 @@ class survey(osv.osv): 'send_response': fields.boolean('Email Notification on Answer'), 'type': fields.many2one('survey.type', 'Type'), 'color': fields.integer('Color Index'), - 'invited_partner_ids': fields.many2many('res.partner', 'survey_invited_partner_rel', 'sid', 'partner_id', 'Invited User'), } _defaults = { 'state': lambda * a: "open", @@ -660,7 +659,7 @@ class survey_response(osv.osv): 'date_create' : fields.datetime('Create Date', required=1), 'response_type' : fields.selection([('manually', 'Manually'), ('link', 'Link')], 'Answer Type', required=1), 'question_ids' : fields.one2many('survey.response.line', 'response_id', 'Answer'), - 'state' : fields.selection([('new', 'Wait answer'), ('done', 'Finished'), ('skip', 'Not Finished')], 'Status', readonly=True), + 'state' : fields.selection([('new', 'Not Started'), ('skip', 'Not Finished'), ('done', 'Finished')], 'Status', readonly=True), 'token': fields.char("Indentification token", readonly=1), 'partner_id' : fields.many2one('res.partner', 'Partner', readonly=1), 'email': fields.char("Email", size=64, readonly=1), diff --git a/addons/survey/survey_view.xml b/addons/survey/survey_view.xml index 23f3adbb33e..104411ac755 100644 --- a/addons/survey/survey_view.xml +++ b/addons/survey/survey_view.xml @@ -214,9 +214,6 @@
- - - @@ -1007,17 +1004,20 @@ + + + - + - - survey_response_tree + + survey_response_form survey.response
diff --git a/addons/survey/wizard/survey_answer.py b/addons/survey/wizard/survey_answer.py index 8832f10398d..0a6fe1834c4 100644 --- a/addons/survey/wizard/survey_answer.py +++ b/addons/survey/wizard/survey_answer.py @@ -204,7 +204,6 @@ class survey_question_wiz(osv.osv_memory): 'subject': survey_browse.title or None, 'body': _("A survey answer is completed."), } - print val self.pool.get('mail.message').create(cr, uid, val, context=context) def _check_token(self, cr, uid, survey_id, context): @@ -341,7 +340,9 @@ class survey_question_wiz(osv.osv_memory): # survey in progress if flag: pag_rec = page_obj.browse(cr, uid, p_id, context=context) - xml_form = etree.Element('form', {'string': tools.ustr(pag_rec and pag_rec.title or survey_browse.title)}) + xml_form = etree.Element('form', {'version': "7.0", 'string': tools.ustr(pag_rec and pag_rec.title or survey_browse.title)}) + xml_form = etree.SubElement(xml_form, 'sheet') + if active and context.get('edit'): context.update({'page_id': tools.ustr(p_id), 'page_number': sur_name_rec.page_no, 'transfer': sur_name_read.transfer}) xml_group3 = etree.SubElement(xml_form, 'group', {'col': '4', 'colspan': '4'}) @@ -353,17 +354,6 @@ class survey_question_wiz(osv.osv_memory): # FP Note xml_group = xml_form - if context.get('response_id') and int(context.get('response_id', 0)[0]) > 0: - # TODO: l10n, cleanup this code to make it readable. Or template? - xml_group = etree.SubElement(xml_form, 'group', {'col': '40', 'colspan': '4'}) - record = sur_response_obj.browse(cr, uid, context['response_id'][context['response_no']]) - etree.SubElement(xml_group, 'label', {'string': to_xml(tools.ustr('Answer Of: - ' + record.partner_id.name + ', Date: - ' + record.date_create.split('.')[0])), 'align': "0.0"}) - etree.SubElement(xml_group, 'label', {'string': to_xml(tools.ustr(" Answer: - " + str(context.get('response_no', 0) + 1) + "/" + str(len(context.get('response_id', 0))))), 'align': "0.0"}) - if context.get('response_no', 0) > 0: - etree.SubElement(xml_group, 'button', {'colspan': "1", 'icon': "gtk-go-back", 'name': "action_forward_previous", 'string': tools.ustr("Previous Answer"), 'type': "object"}) - if context.get('response_no', 0) + 1 < len(context.get('response_id', 0)): - etree.SubElement(xml_group, 'button', {'colspan': "1", 'icon': "gtk-go-forward", 'name': "action_forward_next", 'string': tools.ustr("Next Answer"), 'type': "object", 'context': tools.ustr(context)}) - if wiz_id: fields["wizardid_" + str(wiz_id)] = {'type': 'char', 'size': 255, 'string': "", 'views': {}} etree.SubElement(xml_form, 'field', {'invisible': '1', 'name': "wizardid_" + str(wiz_id), 'default': str(lambda *a: 0), 'modifiers': '{"invisible": true}'}) @@ -405,13 +395,7 @@ class survey_question_wiz(osv.osv_memory): but_string = "Next" if int(page_number) + 1 == total_pages: but_string = "Done" - if active and int(page_number) + 1 == total_pages and context.get('response_id') and context.get('response_no', 0) + 1 == len(context.get('response_id', 0)): - etree.SubElement(xml_footer, 'label', {'string': ""}) - etree.SubElement(xml_footer, 'button', {'special': 'cancel', 'string': tools.ustr("Done"), 'context': tools.ustr(context), 'class': "oe_highlight"}) - elif active and int(page_number) + 1 == total_pages and context.get('response_id'): - etree.SubElement(xml_footer, 'label', {'string': ""}) - etree.SubElement(xml_footer, 'button', {'name': "action_forward_next", 'string': tools.ustr("Next Answer"), 'type': "object", 'context': tools.ustr(context), 'class': "oe_highlight"}) - elif active and int(page_number) + 1 == total_pages: + if active and int(page_number) + 1 == total_pages: etree.SubElement(xml_footer, 'label', {'string': ""}) etree.SubElement(xml_footer, 'button', {'special': "cancel", 'string': 'Done', 'context': tools.ustr(context), 'class': "oe_highlight"}) else: @@ -1134,56 +1118,6 @@ class survey_question_wiz(osv.osv_memory): 'context': context } - def action_forward_previous(self, cr, uid, ids, context=None): - """ - Goes to previous Survey Answer. - """ - if context is None: - context = {} - search_obj = self.pool.get('ir.ui.view') - surv_name_wiz = self.pool.get('survey.name.wiz') - search_id = search_obj.search(cr, uid, [('model', '=', 'survey.question.wiz'), \ - ('name', '=', 'Survey Search')]) - wiz_id = surv_name_wiz.create(cr, uid, {'survey_id': context.get('survey_id', False), 'page_no': -1, 'page': 'next', 'transfer': 1, 'response': 0}) - context.update({'sur_name_id': wiz_id, 'response_no': context.get('response_no', 0) - 1}) - - if context.get('response_no', 0) + 1 > len(context.get('response_id', 0)): - return {} - return { - 'view_type': 'form', - "view_mode": 'form', - 'res_model': 'survey.question.wiz', - 'type': 'ir.actions.act_window', - 'target': 'new', - 'search_view_id': search_id[0], - 'context': context - } - - def action_forward_next(self, cr, uid, ids, context=None): - """ - Goes to Next Survey Answer. - """ - if context is None: - context = {} - search_obj = self.pool.get('ir.ui.view') - surv_name_wiz = self.pool.get('survey.name.wiz') - search_id = search_obj.search(cr, uid, [('model', '=', 'survey.question.wiz'), \ - ('name', '=', 'Survey Search')]) - wiz_id = surv_name_wiz.create(cr, uid, {'survey_id': context.get('survey_id', False), 'page_no': -1, 'page': 'next', 'transfer': 1, 'response': 0}) - context.update({'sur_name_id': wiz_id, 'response_no': context.get('response_no', 0) + 1}) - - if context.get('response_no', 0) + 1 > len(context.get('response_id', 0)): - return {} - return { - 'view_type': 'form', - "view_mode": 'form', - 'res_model': 'survey.question.wiz', - 'type': 'ir.actions.act_window', - 'target': 'new', - 'search_view_id': search_id[0], - 'context': context - } - def action_next(self, cr, uid, ids, context=None): """ Goes to Next page. @@ -1199,7 +1133,7 @@ class survey_question_wiz(osv.osv_memory): "view_mode": 'form', 'res_model': 'survey.question.wiz', 'type': 'ir.actions.act_window', - 'target': 'inline', + 'target': context.get('ir_actions_act_window_target', 'inline'), 'search_view_id': search_id[0], 'context': context } @@ -1220,7 +1154,7 @@ class survey_question_wiz(osv.osv_memory): "view_mode": 'form', 'res_model': 'survey.question.wiz', 'type': 'ir.actions.act_window', - 'target': 'inline', + 'target': context.get('ir_actions_act_window_target', 'inline'), 'search_view_id': search_id[0], 'context': context } diff --git a/addons/survey/wizard/survey_selection.py b/addons/survey/wizard/survey_selection.py index 3eadb3802a9..cb991ee8db6 100644 --- a/addons/survey/wizard/survey_selection.py +++ b/addons/survey/wizard/survey_selection.py @@ -45,55 +45,4 @@ class survey_name_wiz(osv.osv_memory): 'store_ans': '{}' #Setting the default pattern as '{}' as the field is of type text. The field always gets the value in dict format } - def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False): - res = super(survey_name_wiz, self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar, submenu=False) - partner_id = self.pool.get('res.partner').search(cr, uid, [("user_id","=",uid)], context=context)[0] - survey_obj = self.pool.get('survey') - line_ids = survey_obj.search(cr, uid, [('invited_partner_ids.partner_id','in',partner_id)], context=context) - domain = str([('id', 'in', line_ids)]) - doc = etree.XML(res['arch']) - nodes = doc.xpath("//field[@name='survey_id']") - for node in nodes: - node.set('domain', domain) - res['arch'] = etree.tostring(doc) - return res - - def action_next(self, cr, uid, ids, context=None): - """ - Start the survey, Increment in started survey field but if set the max_response_limit of - survey then check the current user how many times start this survey. if current user max_response_limit - is reach then this user can not start this survey(Raise Exception). - """ - survey_obj = self.pool.get('survey') - search_obj = self.pool.get('ir.ui.view') - context = context or {} - - this = self.browse(cr, uid, ids, context=context)[0] - survey_id = this.survey_id.id - context.update({'survey_id': survey_id, 'sur_name_id': this.id}) - sur_rec = survey_obj.browse(cr, uid, survey_id, context=context) - - if sur_rec.max_response_limit and sur_rec.max_response_limit <= sur_rec.tot_start_survey: - raise osv.except_osv(_('Warning!'), _("You cannot give more responses. Please contact the author of this survey for further assistance.")) - - search_id = search_obj.search(cr, uid, [('model', '=', 'survey.question.wiz'), ('name', '=', 'Survey Search')]) - return { - 'view_type': 'form', - "view_mode": 'form', - 'res_model': 'survey.question.wiz', - 'type': 'ir.actions.act_window', - 'target': 'new', - 'search_view_id': search_id[0], - 'context': context - } - - def on_change_survey(self, cr, uid, ids, survey_id, context=None): - """ - on change event of survey_id field, if note is available in selected survey then display this note in note fields. - """ - if not survey_id: - return {} - notes = self.pool.get('survey').read(cr, uid, survey_id, ['note'])['note'] - return {'value': {'note': notes}} - # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: From 131d94a438fc863e0d5e6d513b6ddeaf9a9d11d6 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Fri, 15 Feb 2013 15:54:28 +0100 Subject: [PATCH 0031/1010] [IMP] survey: change spaces bzr revid: chm@openerp.com-20130215145428-5g8wx69q2pma7s0m --- addons/survey/survey.py | 391 +++++++++++++++++++--------------------- 1 file changed, 182 insertions(+), 209 deletions(-) diff --git a/addons/survey/survey.py b/addons/survey/survey.py index 2de955031c9..498a4081b45 100644 --- a/addons/survey/survey.py +++ b/addons/survey/survey.py @@ -2,28 +2,28 @@ ############################################################################## # # OpenERP, Open Source Management Solution -# Copyright (C) 2004-TODAY OpenERP S.A. +# Copyright (C) 2004-TODAY OpenERP S.A. # -# This program is free software: you can redistribute it and/or modify +# 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. +# MERCHANTABILITY or FITNESS F OR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License f or m or e details. # # You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . +# along with this program. If not, see . # ############################################################################## -import copy -from time import strftime +imp or t copy +from time imp or t strftime -from openerp.osv import fields, osv -from openerp.tools.translate import _ +from openerp.osv imp or t fields, osv +from openerp.tools.translate imp or t _ class survey_type(osv.osv): @@ -55,54 +55,54 @@ class survey(osv.osv): help="Set to one if survey is answerable only once"), 'response_partner': fields.integer('Maximum Answer per partner', help="Set to one if you require only one Answer per partner"), - 'state': fields.selection([('open', 'Open'), ('cancel', 'Cancelled'),('close', 'Closed') ], 'Status', readonly=True), - 'responsible_id': fields.many2one('res.users', 'Responsible', help="User responsible for survey"), + 'state': fields.selection([('open', 'Open'), ('cancel', 'Cancelled'), ('close', 'Closed')], 'Status', readonly=True), + 'responsible_id': fields.many2one('res.users', 'Responsible', help="User responsible f or survey"), 'tot_start_survey': fields.integer("Total Started Survey", readonly=1), 'tot_comp_survey': fields.integer("Total Completed Survey", readonly=1), 'note': fields.text('Description', size=128), 'partner_id': fields.many2many('res.partner', 'survey_partner_rel', 'sid', 'partner_id', 'Partners'), 'send_response': fields.boolean('Email Notification on Answer'), 'type': fields.many2one('survey.type', 'Type'), - 'color': fields.integer('Color Index'), + 'col or ': fields.integer('Col or Index'), } _defaults = { 'state': lambda * a: "open", 'tot_start_survey': lambda * a: 0, 'tot_comp_survey': lambda * a: 0, 'send_response': lambda * a: 1, - 'response_partner': lambda * a:1, + 'response_partner': lambda * a: 1, 'date_open': fields.datetime.now, } def survey_open(self, cr, uid, ids, arg): - self.write(cr, uid, ids, {'state': 'open', 'date_open': strftime("%Y-%m-%d %H:%M:%S")}) + self.write(cr, uid, ids, {'state': 'open', 'date_open': strftime("%Y-%m-%d %H: %M: %S")}) return True def survey_close(self, cr, uid, ids, arg): - self.write(cr, uid, ids, {'state': 'close', 'date_close': strftime("%Y-%m-%d %H:%M:%S") }) + self.write(cr, uid, ids, {'state': 'close', 'date_close': strftime("%Y-%m-%d %H: %M: %S")}) return True def survey_cancel(self, cr, uid, ids, arg): - self.write(cr, uid, ids, {'state': 'cancel' }) + self.write(cr, uid, ids, {'state': 'cancel'}) return True def copy(self, cr, uid, ids, default=None, context=None): vals = {} current_rec = self.read(cr, uid, ids, context=context) title = _("%s (copy)") % (current_rec.get('title')) - vals.update({'title':title}) - vals.update({'tot_start_survey':0,'tot_comp_survey':0}) + vals.update({'title': title}) + vals.update({'tot_start_survey': 0, 'tot_comp_survey': 0}) return super(survey, self).copy(cr, uid, ids, vals, context=context) def action_print_survey(self, cr, uid, ids, context=None): """ - If response is available then print this response otherwise print survey form(print template of the survey). + If response is available then print this response otherwise print survey f or m(print template of the survey). @param self: The object pointer - @param cr: the current row, from the database cursor, - @param uid: the current user’s ID for security checks, + @param cr: the current row, from the database curs or , + @param uid: the current user’s ID f or security checks, @param ids: List of Survey IDs - @param context: A standard dictionary for contextual values - @return : Dictionary value for print survey form. + @param context: A st and ard dictionary f or contextual values + @return: Dictionary value f or print survey f or m. """ if context is None: context = {} @@ -111,65 +111,66 @@ class survey(osv.osv): response_id = context.get('response_id', 0) datas['ids'] = [context.get('survey_id', 0)] else: - response_id = self.pool.get('survey.response').search(cr, uid, [('survey_id','=', ids)], context=context) + response_id = self.pool.get('survey.response').search(cr, uid, [('survey_id', '=', ids)], context=context) datas['ids'] = ids - page_setting = {'orientation': 'vertical', 'without_pagebreak': 0, 'paper_size': 'letter', 'page_number': 1, 'survey_title': 1} - report = {} + page_setting = {' or ientation': 'vertical', 'without_pagebreak': 0, 'paper_size': 'letter', 'page_number': 1, 'survey_title': 1} + rep or t = {} if response_id and response_id[0]: context.update({'survey_id': datas['ids']}) - datas['form'] = page_setting + datas['f or m'] = page_setting datas['model'] = 'survey.print.answer' - report = { - 'type': 'ir.actions.report.xml', - 'report_name': 'survey.browse.response', + rep or t = { + 'type': 'ir.actions.rep or t.xml', + 'rep or t_name': 'survey.browse.response', 'datas': datas, - 'context' : context, - 'nodestroy':True, + 'context': context, + 'nodestroy': True, } else: - datas['form'] = page_setting + datas['f or m'] = page_setting datas['model'] = 'survey.print' - report = { - 'type': 'ir.actions.report.xml', - 'report_name': 'survey.form', + rep or t = { + 'type': 'ir.actions.rep or t.xml', + 'rep or t_name': 'survey.f or m', 'datas': datas, - 'context' : context, - 'nodestroy':True, + 'context': context, + 'nodestroy': True, } - return report + return rep or t def fill_survey(self, cr, uid, ids, context=None): - sur_obj = self.read(cr, uid, ids,['title', 'page_ids'], context=context) - for sur in sur_obj: + sur_obj = self.read(cr, uid, ids, ['title', 'page_ids'], context=context) + f or sur in sur_obj: name = sur['title'] pages = sur['page_ids'] if not pages: raise osv.except_osv(_('Warning!'), _('This survey has no question defined. Please define the questions and answers first.')) - context.update({'active':False,'survey_id': ids[0]}) + context.update({'active': False, 'survey_id': ids[0]}) return { - 'view_type': 'form', - 'view_mode': 'form', + 'view_type': 'f or m', + 'view_mode': 'f or m', 'res_model': 'survey.question.wiz', 'type': 'ir.actions.act_window', 'target': 'inline', 'name': name, 'context': context } + def test_survey(self, cr, uid, ids, context=None): - sur_obj = self.read(cr, uid, ids,['title','page_ids'], context=context) - for sur in sur_obj: + sur_obj = self.read(cr, uid, ids, ['title', 'page_ids'], context=context) + f or sur in sur_obj: name = sur['title'] pages = sur['page_ids'] if not pages: raise osv.except_osv(_('Warning!'), _('This survey has no pages defined. Please define pages first.')) - context.update({'active':False,'survey_id': ids[0]}) + context.update({'active': False, 'survey_id': ids[0]}) context.update({'ir_actions_act_window_target': 'new'}) return { - 'view_type': 'form', - 'view_mode': 'form', + 'view_type': 'f or m', + 'view_mode': 'f or m', 'res_model': 'survey.question.wiz', 'type': 'ir.actions.act_window', 'target': 'inline', @@ -178,8 +179,8 @@ class survey(osv.osv): } def edit_survey(self, cr, uid, ids, context=None): - sur_obj = self.read(cr, uid, ids,['title','page_ids'], context=context) - for sur in sur_obj: + sur_obj = self.read(cr, uid, ids, ['title', 'page_ids'], context=context) + f or sur in sur_obj: name = sur['title'] pages = sur['page_ids'] if not pages: @@ -188,8 +189,8 @@ class survey(osv.osv): context.update({'ir_actions_act_window_target': 'new'}) return { - 'view_type': 'form', - 'view_mode': 'form', + 'view_type': 'f or m', + 'view_mode': 'f or m', 'res_model': 'survey.question.wiz', 'type': 'ir.actions.act_window', 'target': 'new', @@ -201,11 +202,11 @@ class survey(osv.osv): ''' This function opens a window to compose an email, with the survey template message loaded by default ''' - assert len(ids) == 1, 'This option should only be used for a single id at a time.' + assert len(ids) == 1, 'This option should only be used f or a single id at a time.' ir_model_data = self.pool.get('ir.model.data') try: template_id = ir_model_data.get_object_reference(cr, uid, 'survey', 'email_template_survey')[1] - except ValueError: + except ValueErr or : template_id = False ctx = dict(context) @@ -219,8 +220,8 @@ class survey(osv.osv): }) return { 'type': 'ir.actions.act_window', - 'view_type': 'form', - 'view_mode': 'form', + 'view_type': 'f or m', + 'view_mode': 'f or m', 'res_model': 'survey.mail.compose.message', 'target': 'new', 'context': ctx, @@ -233,7 +234,7 @@ class survey_page(osv.osv): _name = 'survey.page' _description = 'Survey Pages' _rec_name = 'title' - _order = 'sequence' + _ or der = 'sequence' _columns = { 'title': fields.char('Page Title', size=128, required=1), 'survey_id': fields.many2one('survey', 'Survey', ondelete='cascade'), @@ -249,24 +250,21 @@ class survey_page(osv.osv): if context is None: context = {} data = super(survey_page, self).default_get(cr, uid, fields, context) - if context.has_key('survey_id'): + if context.get('survey_id'): data['survey_id'] = context.get('survey_id', False) return data def survey_save(self, cr, uid, ids, context=None): if context is None: context = {} - search_obj = self.pool.get('ir.ui.view') - search_id = search_obj.search(cr,uid,[('model','=','survey.question.wiz'),('name','=','Survey Search')]) surv_name_wiz = self.pool.get('survey.name.wiz') - surv_name_wiz.write(cr, uid, [context.get('sur_name_id',False)], {'transfer':True, 'page_no' : context.get('page_number',0) }) + surv_name_wiz.write(cr, uid, [context.get('sur_name_id', False)], {'transfer': True, 'page_no': context.get('page_number', 0)}) return { - 'view_type': 'form', - 'view_mode': 'form', + 'view_type': 'f or m', + 'view_mode': 'f or m', 'res_model': 'survey.question.wiz', 'type': 'ir.actions.act_window', 'target': 'new', - #'search_view_id': search_id[0], 'context': context } @@ -274,7 +272,7 @@ class survey_page(osv.osv): vals = {} current_rec = self.read(cr, uid, ids, context=context) title = _("%s (copy)") % (current_rec.get('title')) - vals.update({'title':title}) + vals.update({'title': title}) return super(survey_page, self).copy(cr, uid, ids, vals, context=context) survey_page() @@ -284,7 +282,7 @@ class survey_question(osv.osv): _name = 'survey.question' _description = 'Survey Question' _rec_name = 'question' - _order = 'sequence' + _ or der = 'sequence' def _calc_response(self, cr, uid, ids, field_name, arg, context=None): if len(ids) == 0: @@ -292,45 +290,45 @@ class survey_question(osv.osv): val = {} cr.execute("select question_id, count(id) as Total_response from \ survey_response_line where state='done' and question_id IN %s\ - group by question_id" ,(tuple(ids),)) + group by question_id", (tuple(ids), )) ids1 = copy.deepcopy(ids) - for rec in cr.fetchall(): + f or rec in cr.fetchall(): ids1.remove(rec[0]) val[rec[0]] = int(rec[1]) - for id in ids1: + f or id in ids1: val[id] = 0 return val _columns = { 'page_id': fields.many2one('survey.page', 'Survey Page', ondelete='cascade', required=1), - 'question': fields.char('Question', size=128, required=1), + 'question': fields.char('Question', size=128, required=1), 'answer_choice_ids': fields.one2many('survey.answer', 'question_id', 'Answer'), 'is_require_answer': fields.boolean('Require Answer to Question'), - 'required_type': fields.selection([('all','All'), ('at least','At Least'), ('at most','At Most'), ('exactly','Exactly'), ('a range','A Range')], 'Respondent must answer'), + 'required_type': fields.selection([('all', 'All'), ('at least', 'At Least'), ('at most', 'At Most'), ('exactly', 'Exactly'), ('a range', 'A Range')], 'Respondent must answer'), 'req_ans': fields.integer('#Required Answer'), 'maximum_req_ans': fields.integer('Maximum Required Answer'), 'minimum_req_ans': fields.integer('Minimum Required Answer'), - 'req_error_msg': fields.text('Error Message'), + 'req_err or _msg': fields.text('Err or Message'), 'allow_comment': fields.boolean('Allow Comment Field'), 'sequence': fields.integer('Sequence'), 'tot_resp': fields.function(_calc_response, string="Total Answer"), 'survey': fields.related('page_id', 'survey_id', type='many2one', relation='survey', string='Survey'), 'descriptive_text': fields.text('Descriptive Text', size=255), - 'column_heading_ids': fields.one2many('survey.question.column.heading', 'question_id',' Column heading'), - 'type': fields.selection([('multiple_choice_only_one_ans','Multiple Choice (Only One Answer)'), - ('multiple_choice_multiple_ans','Multiple Choice (Multiple Answer)'), - ('matrix_of_choices_only_one_ans','Matrix of Choices (Only One Answers Per Row)'), - ('matrix_of_choices_only_multi_ans','Matrix of Choices (Multiple Answers Per Row)'), - ('rating_scale','Rating Scale'),('single_textbox','Single Textbox'), - ('multiple_textboxes','Multiple Textboxes'), - ('multiple_textboxes_diff_type','Multiple Textboxes With Different Type'), - ('comment','Comment/Essay Box'), - ('numerical_textboxes','Numerical Textboxes'),('date','Date'), - ('date_and_time','Date and Time'),('descriptive_text','Descriptive Text'), - ('table','Table'), - ], 'Question Type', required=1,), + 'column_heading_ids': fields.one2many('survey.question.column.heading', 'question_id', ' Column heading'), + 'type': fields.selection([('multiple_choice_only_one_ans', 'Multiple Choice (Only One Answer)'), + ('multiple_choice_multiple_ans', 'Multiple Choice (Multiple Answer)'), + ('matrix_of_choices_only_one_ans', 'Matrix of Choices (Only One Answers Per Row)'), + ('matrix_of_choices_only_multi_ans', 'Matrix of Choices (Multiple Answers Per Row)'), + ('rating_scale', 'Rating Scale'), ('single_textbox', 'Single Textbox'), + ('multiple_textboxes', 'Multiple Textboxes'), + ('multiple_textboxes_diff_type', 'Multiple Textboxes With Different Type'), + ('comment', 'Comment/Essay Box'), + ('numerical_textboxes', 'Numerical Textboxes'), ('date', 'Date'), + ('date_ and _time', 'Date and Time'), ('descriptive_text', 'Descriptive Text'), + ('table', 'Table'), + ], 'Question Type', required=1, ), 'is_comment_require': fields.boolean('Add Comment Field'), - 'comment_label': fields.char('Field Label', size = 255), + 'comment_label': fields.char('Field Label', size=255), 'comment_field_type': fields.selection([('char', 'Single Line Of Text'), ('text', 'Paragraph of Text')], 'Comment Field Type'), 'comment_valid_type': fields.selection([('do_not_validate', '''Don't Validate Comment Text.'''), ('must_be_specific_length', 'Must Be Specific Length'), @@ -345,15 +343,15 @@ class survey_question(osv.osv): 'comment_maximum_float': fields.float('Maximum decimal number'), 'comment_minimum_date': fields.date('Minimum date'), 'comment_maximum_date': fields.date('Maximum date'), - 'comment_valid_err_msg': fields.text('Error message'), + 'comment_valid_err_msg': fields.text('Err or message'), 'make_comment_field': fields.boolean('Make Comment Field an Answer Choice'), - 'make_comment_field_err_msg': fields.text('Error message'), + 'make_comment_field_err_msg': fields.text('Err or message'), 'is_validation_require': fields.boolean('Validate Text'), - 'validation_type': fields.selection([('do_not_validate', '''Don't Validate Comment Text.'''),\ - ('must_be_specific_length', 'Must Be Specific Length'),\ - ('must_be_whole_number', 'Must Be A Whole Number'),\ - ('must_be_decimal_number', 'Must Be A Decimal Number'),\ - ('must_be_date', 'Must Be A Date'),\ + 'validation_type': fields.selection([('do_not_validate', '''Don't Validate Comment Text.'''), \ + ('must_be_specific_length', 'Must Be Specific Length'), \ + ('must_be_whole_number', 'Must Be A Whole Number'), \ + ('must_be_decimal_number', 'Must Be A Decimal Number'), \ + ('must_be_date', 'Must Be A Date'), \ ('must_be_email_address', 'Must Be An Email Address')\ ], 'Text Validation'), 'validation_minimum_no': fields.integer('Minimum number'), @@ -362,31 +360,31 @@ class survey_question(osv.osv): 'validation_maximum_float': fields.float('Maximum decimal number'), 'validation_minimum_date': fields.date('Minimum date'), 'validation_maximum_date': fields.date('Maximum date'), - 'validation_valid_err_msg': fields.text('Error message'), + 'validation_valid_err_msg': fields.text('Err or message'), 'numeric_required_sum': fields.integer('Sum of all choices'), - 'numeric_required_sum_err_msg': fields.text('Error message'), - 'rating_allow_one_column_require': fields.boolean('Allow Only One Answer per Column (Forced Ranking)'), + 'numeric_required_sum_err_msg': fields.text('Err or message'), + 'rating_allow_one_column_require': fields.boolean('Allow Only One Answer per Column (F or ced Ranking)'), 'in_visible_rating_weight': fields.boolean('Is Rating Scale Invisible?'), 'in_visible_menu_choice': fields.boolean('Is Menu Choice Invisible?'), 'in_visible_answer_type': fields.boolean('Is Answer Type Invisible?'), 'comment_column': fields.boolean('Add comment column in matrix'), - 'column_name': fields.char('Column Name',size=256), + 'column_name': fields.char('Column Name', size=256), 'no_of_rows': fields.integer('No of Rows'), } _defaults = { 'sequence': lambda * a: 1, 'type': lambda * a: 'multiple_choice_multiple_ans', - 'req_error_msg': lambda * a: 'This question requires an answer.', + 'req_err or _msg': lambda * a: 'This question requires an answer.', 'required_type': lambda * a: 'at least', 'req_ans': lambda * a: 1, 'comment_field_type': lambda * a: 'char', 'comment_label': lambda * a: 'Other (please specify)', 'comment_valid_type': lambda * a: 'do_not_validate', - 'comment_valid_err_msg': lambda * a : 'The comment you entered is in an invalid format.', + 'comment_valid_err_msg': lambda * a: 'The comment you entered is in an invalid f or mat.', 'validation_type': lambda * a: 'do_not_validate', - 'validation_valid_err_msg': lambda * a : 'The comment you entered is in an invalid format.', - 'numeric_required_sum_err_msg': lambda * a :'The choices need to add up to [enter sum here].', - 'make_comment_field_err_msg': lambda * a : 'Please enter a comment.', + 'validation_valid_err_msg': lambda * a: 'The comment you entered is in an invalid f or mat.', + 'numeric_required_sum_err_msg': lambda * a: 'The choices need to add up to [enter sum here].', + 'make_comment_field_err_msg': lambda * a: 'Please enter a comment.', 'in_visible_answer_type': lambda * a: 1 } @@ -402,101 +400,76 @@ class survey_question(osv.osv): return {'value': val} if type in ['rating_scale']: - val.update({'in_visible_rating_weight':False, 'in_visible_menu_choice':True}) + val.update({'in_visible_rating_weight': False, 'in_visible_menu_choice': True}) return {'value': val} elif type in ['single_textbox']: - val.update({'in_visible_rating_weight':True, 'in_visible_menu_choice':True}) + val.update({'in_visible_rating_weight': True, 'in_visible_menu_choice': True}) return {'value': val} else: - val.update({'in_visible_rating_weight':True, 'in_visible_menu_choice':True,\ - 'in_visible_answer_type':True}) + val.update({'in_visible_rating_weight': True, 'in_visible_menu_choice': True, \ + 'in_visible_answer_type': True}) return {'value': val} def write(self, cr, uid, ids, vals, context=None): - questions = self.read(cr,uid, ids, ['answer_choice_ids', 'type', 'required_type',\ + questions = self.read(cr, uid, ids, ['answer_choice_ids', 'type', 'required_type', \ 'req_ans', 'minimum_req_ans', 'maximum_req_ans', 'column_heading_ids', 'page_id', 'question']) - for question in questions: + f or question in questions: col_len = len(question['column_heading_ids']) - if vals.has_key('column_heading_ids'): - for col in vals['column_heading_ids']: - if type(col[2]) == type({}): - col_len += 1 - else: - col_len -= 1 + f or col in vals.get('column_heading_ids', []): + if type(col[2]) == type({}): + col_len += 1 + else: + col_len -= 1 - if vals.has_key('type'): - que_type = vals['type'] - else: - que_type = question['type'] + que_type = vals.get('type', question['type']) if que_type in ['matrix_of_choices_only_one_ans', 'matrix_of_choices_only_multi_ans', 'rating_scale']: if not col_len: - raise osv.except_osv(_('Warning!'),_('You must enter one or more column headings for question "%s" of page %s.') % (question['question'], question['page_id'][1])) + raise osv.except_osv(_('Warning!'), _('You must enter one or m or e column headings f or question "%s" of page %s.') % (question['question'], question['page_id'][1])) ans_len = len(question['answer_choice_ids']) - if vals.has_key('answer_choice_ids'): - for ans in vals['answer_choice_ids']: - if type(ans[2]) == type({}): - ans_len += 1 - else: - ans_len -= 1 + f or ans in vals.get('answer_choice_ids', []): + if type(ans[2]) == type({}): + ans_len += 1 + else: + ans_len -= 1 - if que_type not in ['descriptive_text', 'single_textbox', 'comment','table']: + if que_type not in ['descriptive_text', 'single_textbox', 'comment', 'table']: if not ans_len: - raise osv.except_osv(_('Warning!'),_('You must enter one or more Answers for question "%s" of page %s.') % (question['question'], question['page_id'][1])) - req_type = "" + raise osv.except_osv(_('Warning!'), _('You must enter one or m or e Answers f or question "%s" of page %s.') % (question['question'], question['page_id'][1])) - if vals.has_key('required_type'): - req_type = vals['required_type'] - else: - req_type = question['required_type'] + req_type = vals.get('required_type', question['required_type']) - if que_type in ['multiple_choice_multiple_ans','matrix_of_choices_only_one_ans', \ - 'matrix_of_choices_only_multi_ans', 'rating_scale','multiple_textboxes', \ - 'numerical_textboxes','date','date_and_time']: + if que_type in ['multiple_choice_multiple_ans', 'matrix_of_choices_only_one_ans', \ + 'matrix_of_choices_only_multi_ans', 'rating_scale', 'multiple_textboxes', \ + 'numerical_textboxes', 'date', 'date_ and _time']: if req_type in ['at least', 'at most', 'exactly']: - if vals.has_key('req_ans'): - if not vals['req_ans'] or vals['req_ans'] > ans_len: - raise osv.except_osv(_('Warning!'),_("#Required Answer you entered \ + if 'req_ans' in vals: + if not vals['req_ans'] or vals['req_ans'] > ans_len: + raise osv.except_osv(_('Warning!'), _("#Required Answer you entered \ is greater than the number of answer. \ Please use a number that is smaller than %d.") % (ans_len + 1)) else: - if not question['req_ans'] or question['req_ans'] > ans_len: - raise osv.except_osv(_('Warning!'),_("#Required Answer you entered is \ + if not question['req_ans'] or question['req_ans'] > ans_len: + raise osv.except_osv(_('Warning!'), _("#Required Answer you entered is \ greater than the number of answer.\ Please use a number that is smaller than %d.") % (ans_len + 1)) if req_type == 'a range': minimum_ans = 0 maximum_ans = 0 - if vals.has_key('minimum_req_ans'): - minimum_ans = vals['minimum_req_ans'] - if not vals['minimum_req_ans'] or vals['minimum_req_ans'] > ans_len: - raise osv.except_osv(_('Warning!'),_("Minimum Required Answer\ - you entered is greater than the number of answer.\ - Please use a number that is smaller than %d.") % (ans_len + 1)) - else: - minimum_ans = question['minimum_req_ans'] - if not question['minimum_req_ans'] or question['minimum_req_ans'] > ans_len: - raise osv.except_osv(_('Warning!'),_("Minimum Required Answer you\ - entered is greater than the number of answer. \ - Please use a number that is smaller than %d.") % (ans_len + 1)) - if vals.has_key('maximum_req_ans'): - maximum_ans = vals['maximum_req_ans'] - if not vals['maximum_req_ans'] or vals['maximum_req_ans'] > ans_len: - raise osv.except_osv(_('Warning!'),_("Maximum Required Answer you \ - entered for your maximum is greater than the number of answer.\ - Please use a number that is smaller than %d.") % (ans_len + 1)) - else: - maximum_ans = question['maximum_req_ans'] - if not question['maximum_req_ans'] or question['maximum_req_ans'] > ans_len: - raise osv.except_osv(_('Warning!'),_("Maximum Required Answer you\ - entered for your maximum is greater than the number of answer.\ - Please use a number that is smaller than %d.") % (ans_len + 1)) + error = False + minimum_ans = 'minimum_req_ans' in vals and vals['minimum_req_ans'] or question['minimum_req_ans'] + maximum_ans = 'maximum_req_ans' in vals and vals['maximum_req_ans'] or question['maximum_req_ans'] + + if not minimum_ans or minimum_ans > ans_len or not maximum_ans or maximum_ans > ans_len: + raise osv.except_osv(_('Warning!'), _("Minimum Required Answer you\ + entered is greater than the number of answer. \ + Please use a number that is smaller than %d.") % (ans_len + 1)) if maximum_ans <= minimum_ans: - raise osv.except_osv(_('Warning!'),_("Maximum Required Answer is greater \ + raise osv.except_osv(_('Warning!'), _("Maximum Required Answer is greater \ than Minimum Required Answer")) return super(survey_question, self).write(cr, uid, ids, vals, context=context) @@ -505,28 +478,28 @@ class survey_question(osv.osv): minimum_ans = 0 maximum_ans = 0 page = self.pool.get('survey.page').browse(cr, uid, vals['page_id'], context=context).title - if vals.has_key('answer_choice_ids') and not len(vals['answer_choice_ids']): - if vals.has_key('type') and vals['type'] not in ['descriptive_text', 'single_textbox', 'comment','table']: - raise osv.except_osv(_('Warning!'),_('You must enter one or more answers for question "%s" of page %s .') % (vals['question'], page)) + if vals.has_key('answer_choice_ids') and not len(vals['answer_choice_ids']): + if vals.has_key('type') and vals['type'] not in ['descriptive_text', 'single_textbox', 'comment', 'table']: + raise osv.except_osv(_('Warning!'), _('You must enter one or m or e answers f or question "%s" of page %s .') % (vals['question'], page)) - if vals.has_key('column_heading_ids') and not len(vals['column_heading_ids']): + if vals.has_key('column_heading_ids') and not len(vals['column_heading_ids']): if vals.has_key('type') and vals['type'] in ['matrix_of_choices_only_one_ans', 'matrix_of_choices_only_multi_ans', 'rating_scale']: - raise osv.except_osv(_('Warning!'),_('You must enter one or more column headings for question "%s" of page %s.')% (vals['question'], page)) + raise osv.except_osv(_('Warning!'), _('You must enter one or m or e column headings f or question "%s" of page %s.')% (vals['question'], page)) - if vals['type'] in ['multiple_choice_multiple_ans','matrix_of_choices_only_one_ans', 'matrix_of_choices_only_multi_ans', 'rating_scale','multiple_textboxes','numerical_textboxes','date','date_and_time']: + if vals['type'] in ['multiple_choice_multiple_ans', 'matrix_of_choices_only_one_ans', 'matrix_of_choices_only_multi_ans', 'rating_scale', 'multiple_textboxes', 'numerical_textboxes', 'date', 'date_ and _time']: if vals.has_key('is_require_answer') and vals.has_key('required_type') and vals['required_type'] in ['at least', 'at most', 'exactly']: if vals.has_key('answer_choice_ids') and vals['req_ans'] > len(vals['answer_choice_ids']) or not vals['req_ans']: - raise osv.except_osv(_('Warning!'),_("#Required Answer you entered is greater than the number of answer. Please use a number that is smaller than %d.") % (len(vals['answer_choice_ids'])+1)) + raise osv.except_osv(_('Warning!'), _("#Required Answer you entered is greater than the number of answer. Please use a number that is smaller than %d.") % (len(vals['answer_choice_ids'])+1)) if vals.has_key('is_require_answer') and vals.has_key('required_type') and vals['required_type'] == 'a range': minimum_ans = vals['minimum_req_ans'] maximum_ans = vals['maximum_req_ans'] if vals.has_key('answer_choice_ids') or vals['minimum_req_ans'] > len(vals['answer_choice_ids']) or not vals['minimum_req_ans']: - raise osv.except_osv(_('Warning!'),_("Minimum Required Answer you entered is greater than the number of answer. Please use a number that is smaller than %d.") % (len(vals['answer_choice_ids'])+1)) + raise osv.except_osv(_('Warning!'), _("Minimum Required Answer you entered is greater than the number of answer. Please use a number that is smaller than %d.") % (len(vals['answer_choice_ids'])+1)) if vals.has_key('answer_choice_ids') or vals['maximum_req_ans'] > len(vals['answer_choice_ids']) or not vals['maximum_req_ans']: - raise osv.except_osv(_('Warning!'),_("Maximum Required Answer you entered for your maximum is greater than the number of answer. Please use a number that is smaller than %d.") % (len(vals['answer_choice_ids'])+1)) + raise osv.except_osv(_('Warning!'), _("Maximum Required Answer you entered f or your maximum is greater than the number of answer. Please use a number that is smaller than %d.") % (len(vals['answer_choice_ids'])+1)) if maximum_ans <= minimum_ans: - raise osv.except_osv(_('Warning!'),_("Maximum Required Answer is greater than Minimum Required Answer.")) + raise osv.except_osv(_('Warning!'), _("Maximum Required Answer is greater than Minimum Required Answer.")) res = super(survey_question, self).create(cr, uid, vals, context) return res @@ -535,12 +508,12 @@ class survey_question(osv.osv): if context is None: context = {} search_obj = self.pool.get('ir.ui.view') - search_id = search_obj.search(cr,uid,[('model','=','survey.question.wiz'),('name','=','Survey Search')]) + search_id = search_obj.search(cr, uid, [('model', '=', 'survey.question.wiz'), ('name', '=', 'Survey Search')]) surv_name_wiz = self.pool.get('survey.name.wiz') - surv_name_wiz.write(cr, uid, [context.get('sur_name_id',False)], {'transfer':True, 'page_no' : context.get('page_number',False) }) + surv_name_wiz.write(cr, uid, [context.get('sur_name_id', False)], {'transfer': True, 'page_no': context.get('page_number', False)}) return { - 'view_type': 'form', - 'view_mode': 'form', + 'view_type': 'f or m', + 'view_mode': 'f or m', 'res_model': 'survey.question.wiz', 'type': 'ir.actions.act_window', 'target': 'new', @@ -570,7 +543,7 @@ class survey_question_column_heading(osv.osv): if context.get('in_visible_rating_weight', False): return context['in_visible_rating_weight'] return False - def _get_in_visible_menu_choice(self,cr, uid, context=None): + def _get_in_visible_menu_choice(self, cr, uid, context=None): if context is None: context = {} if context.get('in_visible_menu_choice', False): @@ -596,15 +569,15 @@ class survey_answer(osv.osv): _name = 'survey.answer' _description = 'Survey Answer' _rec_name = 'answer' - _order = 'sequence' + _ or der = 'sequence' def _calc_response_avg(self, cr, uid, ids, field_name, arg, context=None): val = {} - for rec in self.browse(cr, uid, ids, context=context): - cr.execute("select count(question_id) ,(select count(answer_id) \ + f or rec in self.browse(cr, uid, ids, context=context): + cr.execute("select count(question_id), (select count(answer_id) \ from survey_response_answer sra, survey_response_line sa \ where sra.response_id = sa.id and sra.answer_id = %d \ - and sa.state='done') as tot_ans from survey_response_line \ + and sa.state='done') as tot_ans from survey_response_line \ where question_id = %d and state = 'done'"\ % (rec.id, rec.question_id.id)) res = cr.fetchone() @@ -629,16 +602,16 @@ class survey_answer(osv.osv): 'sequence': fields.integer('Sequence'), 'response': fields.function(_calc_response_avg, string="#Answer", multi='sums'), 'average': fields.function(_calc_response_avg, string="#Avg", multi='sums'), - 'type': fields.selection([('char','Character'),('date','Date'),('datetime','Date & Time'),\ - ('integer','Integer'),('float','Float'),('selection','Selection'),\ - ('email','Email')], "Type of Answer",required=1), + 'type': fields.selection([('char', 'Character'), ('date', 'Date'), ('datetime', 'Date & Time'), \ + ('integer', 'Integer'), ('float', 'Float'), ('selection', 'Selection'), \ + ('email', 'Email')], "Type of Answer", required=1), 'menu_choice': fields.text('Menu Choices'), 'in_visible_answer_type': fields.boolean('Is Answer Type Invisible??') } _defaults = { - # 'sequence' : lambda * a: 1, - 'type' : lambda * a: 'char', - 'in_visible_answer_type':_get_in_visible_answer_type, + # 'sequence': lambda * a: 1, + 'type': lambda * a: 'char', + 'in_visible_answer_type': _get_in_visible_answer_type, } def default_get(self, cr, uid, fields, context=None): @@ -655,32 +628,32 @@ class survey_response(osv.osv): _rec_name = 'date_create' _columns = { 'date_deadline': fields.date("Deadline date", help="Date by which the person can respond to the survey"), - 'survey_id' : fields.many2one('survey', 'Survey', required=1, readonly=1, ondelete='cascade'), - 'date_create' : fields.datetime('Create Date', required=1), - 'response_type' : fields.selection([('manually', 'Manually'), ('link', 'Link')], 'Answer Type', required=1), - 'question_ids' : fields.one2many('survey.response.line', 'response_id', 'Answer'), - 'state' : fields.selection([('new', 'Not Started'), ('skip', 'Not Finished'), ('done', 'Finished')], 'Status', readonly=True), + 'survey_id': fields.many2one('survey', 'Survey', required=1, readonly=1, ondelete='cascade'), + 'date_create': fields.datetime('Create Date', required=1), + 'response_type': fields.selection([('manually', 'Manually'), ('link', 'Link')], 'Answer Type', required=1), + 'question_ids': fields.one2many('survey.response.line', 'response_id', 'Answer'), + 'state': fields.selection([('new', 'Not Started'), ('skip', 'Not Finished'), ('done', 'Finished')], 'Status', readonly=True), 'token': fields.char("Indentification token", readonly=1), - 'partner_id' : fields.many2one('res.partner', 'Partner', readonly=1), + 'partner_id': fields.many2one('res.partner', 'Partner', readonly=1), 'email': fields.char("Email", size=64, readonly=1), } _defaults = { - 'state' : lambda * a: "new", - 'response_type' : lambda * a: "manually", + 'state': lambda * a: "new", + 'response_type': lambda * a: "manually", } def name_get(self, cr, uid, ids, context=None): if not len(ids): return [] - reads = self.read(cr, uid, ids, ['partner_id','date_create'], context=context) + reads = self.read(cr, uid, ids, ['partner_id', 'date_create'], context=context) res = [] - for record in reads: - name = (record['partner_id'] and record['partner_id'][1] or '' )+ ' (' + record['date_create'].split('.')[0] + ')' - res.append((record['id'], name)) + f or rec or d in reads: + name = (rec or d['partner_id'] and rec or d['partner_id'][1] or '') + ' (' + rec or d['date_create'].split('.')[0] + ')' + res.append((rec or d['id'], name)) return res def copy(self, cr, uid, id, default=None, context=None): - raise osv.except_osv(_('Warning!'),_('You cannot duplicate the resource!')) + raise osv.except_osv(_('Warning!'), _('You cannot duplicate the resource!')) survey_response() @@ -692,7 +665,7 @@ class survey_response_line(osv.osv): _columns = { 'response_id': fields.many2one('survey.response', 'Answer', ondelete='cascade'), 'date_create': fields.datetime('Create Date', required=1), - 'state': fields.selection([('draft', 'Draft'), ('done', 'Answered'),('skip', 'Skiped')],\ + 'state': fields.selection([('draft', 'Draft'), ('done', 'Answered'), ('skip', 'Skiped')], \ 'Status', readonly=True), 'question_id': fields.many2one('survey.question', 'Question'), 'page_id': fields.related('question_id', 'page_id', type='many2one', \ @@ -704,7 +677,7 @@ class survey_response_line(osv.osv): 'single_text': fields.char('Text', size=255), } _defaults = { - 'state' : lambda * a: "draft", + 'state': lambda * a: "draft", } survey_response_line() @@ -712,7 +685,7 @@ survey_response_line() class survey_tbl_column_heading(osv.osv): _name = 'survey.tbl.column.heading' - _order = 'name' + _ or der = 'name' _columns = { 'name': fields.integer('Row Number'), 'column_id': fields.many2one('survey.question.column.heading', 'Column'), @@ -730,7 +703,7 @@ class survey_response_answer(osv.osv): _columns = { 'response_id': fields.many2one('survey.response.line', 'Answer', ondelete='cascade'), 'answer_id': fields.many2one('survey.answer', 'Answer', required=1, ondelete='cascade'), - 'column_id': fields.many2one('survey.question.column.heading','Column'), + 'column_id': fields.many2one('survey.question.column.heading', 'Column'), 'answer': fields.char('Value', size =255), 'value_choice': fields.char('Value Choice', size =255), 'comment': fields.text('Notes'), @@ -748,4 +721,4 @@ class res_partner(osv.osv): } res_partner() -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: +# vim: exp and tab: smartindent: tabstop=4: softtabstop=4: shiftwidth=4: From 5f2a88ecae9130ed6e064a646981849cbbe6d9bc Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Mon, 18 Feb 2013 10:24:48 +0100 Subject: [PATCH 0032/1010] [IMP] survey: spaces error, in progress bzr revid: chm@openerp.com-20130218092448-1itidmoudhbx8g97 --- addons/survey/survey.py | 198 +++++++++++------------ addons/survey/wizard/survey_selection.py | 12 +- 2 files changed, 101 insertions(+), 109 deletions(-) diff --git a/addons/survey/survey.py b/addons/survey/survey.py index 498a4081b45..14b2da9c34e 100644 --- a/addons/survey/survey.py +++ b/addons/survey/survey.py @@ -11,19 +11,19 @@ # # 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 F OR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License f or m or e details. +# 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 . +# along with this program. If not, see . # ############################################################################## -imp or t copy -from time imp or t strftime +import copy +from time import strftime -from openerp.osv imp or t fields, osv -from openerp.tools.translate imp or t _ +from openerp.osv import fields, osv +from openerp.tools.translate import _ class survey_type(osv.osv): @@ -56,14 +56,14 @@ class survey(osv.osv): 'response_partner': fields.integer('Maximum Answer per partner', help="Set to one if you require only one Answer per partner"), 'state': fields.selection([('open', 'Open'), ('cancel', 'Cancelled'), ('close', 'Closed')], 'Status', readonly=True), - 'responsible_id': fields.many2one('res.users', 'Responsible', help="User responsible f or survey"), + 'responsible_id': fields.many2one('res.users', 'Responsible', help="User responsible forsurvey"), 'tot_start_survey': fields.integer("Total Started Survey", readonly=1), 'tot_comp_survey': fields.integer("Total Completed Survey", readonly=1), 'note': fields.text('Description', size=128), 'partner_id': fields.many2many('res.partner', 'survey_partner_rel', 'sid', 'partner_id', 'Partners'), 'send_response': fields.boolean('Email Notification on Answer'), 'type': fields.many2one('survey.type', 'Type'), - 'col or ': fields.integer('Col or Index'), + 'color': fields.integer('Color Index'), } _defaults = { 'state': lambda * a: "open", @@ -96,13 +96,13 @@ class survey(osv.osv): def action_print_survey(self, cr, uid, ids, context=None): """ - If response is available then print this response otherwise print survey f or m(print template of the survey). + If response is available then print this response otherwise print survey form(print template of the survey). @param self: The object pointer - @param cr: the current row, from the database curs or , - @param uid: the current user’s ID f or security checks, + @param cr: the current row, from the database cursor, + @param uid: the current user’s ID forsecurity checks, @param ids: List of Survey IDs - @param context: A st and ard dictionary f or contextual values - @return: Dictionary value f or print survey f or m. + @param context: A standard dictionary forcontextual values + @return: Dictionary value forprint survey form. """ if context is None: context = {} @@ -113,35 +113,35 @@ class survey(osv.osv): else: response_id = self.pool.get('survey.response').search(cr, uid, [('survey_id', '=', ids)], context=context) datas['ids'] = ids - page_setting = {' or ientation': 'vertical', 'without_pagebreak': 0, 'paper_size': 'letter', 'page_number': 1, 'survey_title': 1} - rep or t = {} + page_setting = {'orientation': 'vertical', 'without_pagebreak': 0, 'paper_size': 'letter', 'page_number': 1, 'survey_title': 1} + report = {} if response_id and response_id[0]: context.update({'survey_id': datas['ids']}) - datas['f or m'] = page_setting + datas['form'] = page_setting datas['model'] = 'survey.print.answer' - rep or t = { - 'type': 'ir.actions.rep or t.xml', - 'rep or t_name': 'survey.browse.response', + report = { + 'type': 'ir.actions.report.xml', + 'report_name': 'survey.browse.response', 'datas': datas, 'context': context, 'nodestroy': True, } else: - datas['f or m'] = page_setting + datas['form'] = page_setting datas['model'] = 'survey.print' - rep or t = { - 'type': 'ir.actions.rep or t.xml', - 'rep or t_name': 'survey.f or m', + report = { + 'type': 'ir.actions.report.xml', + 'report_name': 'survey.form', 'datas': datas, 'context': context, 'nodestroy': True, } - return rep or t + return report def fill_survey(self, cr, uid, ids, context=None): sur_obj = self.read(cr, uid, ids, ['title', 'page_ids'], context=context) - f or sur in sur_obj: + for sur in sur_obj: name = sur['title'] pages = sur['page_ids'] if not pages: @@ -149,8 +149,8 @@ class survey(osv.osv): context.update({'active': False, 'survey_id': ids[0]}) return { - 'view_type': 'f or m', - 'view_mode': 'f or m', + 'view_type': 'form', + 'view_mode': 'form', 'res_model': 'survey.question.wiz', 'type': 'ir.actions.act_window', 'target': 'inline', @@ -160,7 +160,7 @@ class survey(osv.osv): def test_survey(self, cr, uid, ids, context=None): sur_obj = self.read(cr, uid, ids, ['title', 'page_ids'], context=context) - f or sur in sur_obj: + for sur in sur_obj: name = sur['title'] pages = sur['page_ids'] if not pages: @@ -169,8 +169,8 @@ class survey(osv.osv): context.update({'ir_actions_act_window_target': 'new'}) return { - 'view_type': 'f or m', - 'view_mode': 'f or m', + 'view_type': 'form', + 'view_mode': 'form', 'res_model': 'survey.question.wiz', 'type': 'ir.actions.act_window', 'target': 'inline', @@ -180,7 +180,7 @@ class survey(osv.osv): def edit_survey(self, cr, uid, ids, context=None): sur_obj = self.read(cr, uid, ids, ['title', 'page_ids'], context=context) - f or sur in sur_obj: + for sur in sur_obj: name = sur['title'] pages = sur['page_ids'] if not pages: @@ -189,8 +189,8 @@ class survey(osv.osv): context.update({'ir_actions_act_window_target': 'new'}) return { - 'view_type': 'f or m', - 'view_mode': 'f or m', + 'view_type': 'form', + 'view_mode': 'form', 'res_model': 'survey.question.wiz', 'type': 'ir.actions.act_window', 'target': 'new', @@ -202,11 +202,11 @@ class survey(osv.osv): ''' This function opens a window to compose an email, with the survey template message loaded by default ''' - assert len(ids) == 1, 'This option should only be used f or a single id at a time.' + assert len(ids) == 1, 'This option should only be used for a single id at a time.' ir_model_data = self.pool.get('ir.model.data') try: template_id = ir_model_data.get_object_reference(cr, uid, 'survey', 'email_template_survey')[1] - except ValueErr or : + except ValueError: template_id = False ctx = dict(context) @@ -220,8 +220,8 @@ class survey(osv.osv): }) return { 'type': 'ir.actions.act_window', - 'view_type': 'f or m', - 'view_mode': 'f or m', + 'view_type': 'form', + 'view_mode': 'form', 'res_model': 'survey.mail.compose.message', 'target': 'new', 'context': ctx, @@ -234,7 +234,7 @@ class survey_page(osv.osv): _name = 'survey.page' _description = 'Survey Pages' _rec_name = 'title' - _ or der = 'sequence' + _order = 'sequence' _columns = { 'title': fields.char('Page Title', size=128, required=1), 'survey_id': fields.many2one('survey', 'Survey', ondelete='cascade'), @@ -260,8 +260,8 @@ class survey_page(osv.osv): surv_name_wiz = self.pool.get('survey.name.wiz') surv_name_wiz.write(cr, uid, [context.get('sur_name_id', False)], {'transfer': True, 'page_no': context.get('page_number', 0)}) return { - 'view_type': 'f or m', - 'view_mode': 'f or m', + 'view_type': 'form', + 'view_mode': 'form', 'res_model': 'survey.question.wiz', 'type': 'ir.actions.act_window', 'target': 'new', @@ -282,7 +282,7 @@ class survey_question(osv.osv): _name = 'survey.question' _description = 'Survey Question' _rec_name = 'question' - _ or der = 'sequence' + _order = 'sequence' def _calc_response(self, cr, uid, ids, field_name, arg, context=None): if len(ids) == 0: @@ -292,10 +292,10 @@ class survey_question(osv.osv): survey_response_line where state='done' and question_id IN %s\ group by question_id", (tuple(ids), )) ids1 = copy.deepcopy(ids) - f or rec in cr.fetchall(): + for rec in cr.fetchall(): ids1.remove(rec[0]) val[rec[0]] = int(rec[1]) - f or id in ids1: + for id in ids1: val[id] = 0 return val @@ -308,7 +308,7 @@ class survey_question(osv.osv): 'req_ans': fields.integer('#Required Answer'), 'maximum_req_ans': fields.integer('Maximum Required Answer'), 'minimum_req_ans': fields.integer('Minimum Required Answer'), - 'req_err or _msg': fields.text('Err or Message'), + 'req_error_msg': fields.text('Error Message'), 'allow_comment': fields.boolean('Allow Comment Field'), 'sequence': fields.integer('Sequence'), 'tot_resp': fields.function(_calc_response, string="Total Answer"), @@ -324,7 +324,7 @@ class survey_question(osv.osv): ('multiple_textboxes_diff_type', 'Multiple Textboxes With Different Type'), ('comment', 'Comment/Essay Box'), ('numerical_textboxes', 'Numerical Textboxes'), ('date', 'Date'), - ('date_ and _time', 'Date and Time'), ('descriptive_text', 'Descriptive Text'), + ('date_and_time', 'Date and Time'), ('descriptive_text', 'Descriptive Text'), ('table', 'Table'), ], 'Question Type', required=1, ), 'is_comment_require': fields.boolean('Add Comment Field'), @@ -343,9 +343,9 @@ class survey_question(osv.osv): 'comment_maximum_float': fields.float('Maximum decimal number'), 'comment_minimum_date': fields.date('Minimum date'), 'comment_maximum_date': fields.date('Maximum date'), - 'comment_valid_err_msg': fields.text('Err or message'), + 'comment_valid_err_msg': fields.text('Error message'), 'make_comment_field': fields.boolean('Make Comment Field an Answer Choice'), - 'make_comment_field_err_msg': fields.text('Err or message'), + 'make_comment_field_err_msg': fields.text('Error message'), 'is_validation_require': fields.boolean('Validate Text'), 'validation_type': fields.selection([('do_not_validate', '''Don't Validate Comment Text.'''), \ ('must_be_specific_length', 'Must Be Specific Length'), \ @@ -360,10 +360,10 @@ class survey_question(osv.osv): 'validation_maximum_float': fields.float('Maximum decimal number'), 'validation_minimum_date': fields.date('Minimum date'), 'validation_maximum_date': fields.date('Maximum date'), - 'validation_valid_err_msg': fields.text('Err or message'), + 'validation_valid_err_msg': fields.text('Error message'), 'numeric_required_sum': fields.integer('Sum of all choices'), - 'numeric_required_sum_err_msg': fields.text('Err or message'), - 'rating_allow_one_column_require': fields.boolean('Allow Only One Answer per Column (F or ced Ranking)'), + 'numeric_required_sum_err_msg': fields.text('Error message'), + 'rating_allow_one_column_require': fields.boolean('Allow Only One Answer per Column (Forced Ranking)'), 'in_visible_rating_weight': fields.boolean('Is Rating Scale Invisible?'), 'in_visible_menu_choice': fields.boolean('Is Menu Choice Invisible?'), 'in_visible_answer_type': fields.boolean('Is Answer Type Invisible?'), @@ -374,15 +374,15 @@ class survey_question(osv.osv): _defaults = { 'sequence': lambda * a: 1, 'type': lambda * a: 'multiple_choice_multiple_ans', - 'req_err or _msg': lambda * a: 'This question requires an answer.', + 'req_error_msg': lambda * a: 'This question requires an answer.', 'required_type': lambda * a: 'at least', 'req_ans': lambda * a: 1, 'comment_field_type': lambda * a: 'char', 'comment_label': lambda * a: 'Other (please specify)', 'comment_valid_type': lambda * a: 'do_not_validate', - 'comment_valid_err_msg': lambda * a: 'The comment you entered is in an invalid f or mat.', + 'comment_valid_err_msg': lambda * a: 'The comment you entered is in an invalid format.', 'validation_type': lambda * a: 'do_not_validate', - 'validation_valid_err_msg': lambda * a: 'The comment you entered is in an invalid f or mat.', + 'validation_valid_err_msg': lambda * a: 'The comment you entered is in an invalid format.', 'numeric_required_sum_err_msg': lambda * a: 'The choices need to add up to [enter sum here].', 'make_comment_field_err_msg': lambda * a: 'Please enter a comment.', 'in_visible_answer_type': lambda * a: 1 @@ -415,9 +415,9 @@ class survey_question(osv.osv): def write(self, cr, uid, ids, vals, context=None): questions = self.read(cr, uid, ids, ['answer_choice_ids', 'type', 'required_type', \ 'req_ans', 'minimum_req_ans', 'maximum_req_ans', 'column_heading_ids', 'page_id', 'question']) - f or question in questions: + for question in questions: col_len = len(question['column_heading_ids']) - f or col in vals.get('column_heading_ids', []): + for col in vals.get('column_heading_ids', []): if type(col[2]) == type({}): col_len += 1 else: @@ -427,10 +427,10 @@ class survey_question(osv.osv): if que_type in ['matrix_of_choices_only_one_ans', 'matrix_of_choices_only_multi_ans', 'rating_scale']: if not col_len: - raise osv.except_osv(_('Warning!'), _('You must enter one or m or e column headings f or question "%s" of page %s.') % (question['question'], question['page_id'][1])) + raise osv.except_osv(_('Warning!'), _('You must enter one or more column headings for question "%s" of page %s.') % (question['question'], question['page_id'][1])) ans_len = len(question['answer_choice_ids']) - f or ans in vals.get('answer_choice_ids', []): + for ans in vals.get('answer_choice_ids', []): if type(ans[2]) == type({}): ans_len += 1 else: @@ -438,13 +438,13 @@ class survey_question(osv.osv): if que_type not in ['descriptive_text', 'single_textbox', 'comment', 'table']: if not ans_len: - raise osv.except_osv(_('Warning!'), _('You must enter one or m or e Answers f or question "%s" of page %s.') % (question['question'], question['page_id'][1])) + raise osv.except_osv(_('Warning!'), _('You must enter one or more Answers for question "%s" of page %s.') % (question['question'], question['page_id'][1])) req_type = vals.get('required_type', question['required_type']) if que_type in ['multiple_choice_multiple_ans', 'matrix_of_choices_only_one_ans', \ 'matrix_of_choices_only_multi_ans', 'rating_scale', 'multiple_textboxes', \ - 'numerical_textboxes', 'date', 'date_ and _time']: + 'numerical_textboxes', 'date', 'date_and_time']: if req_type in ['at least', 'at most', 'exactly']: if 'req_ans' in vals: if not vals['req_ans'] or vals['req_ans'] > ans_len: @@ -460,7 +460,6 @@ class survey_question(osv.osv): if req_type == 'a range': minimum_ans = 0 maximum_ans = 0 - error = False minimum_ans = 'minimum_req_ans' in vals and vals['minimum_req_ans'] or question['minimum_req_ans'] maximum_ans = 'maximum_req_ans' in vals and vals['maximum_req_ans'] or question['maximum_req_ans'] @@ -475,49 +474,43 @@ class survey_question(osv.osv): return super(survey_question, self).write(cr, uid, ids, vals, context=context) def create(self, cr, uid, vals, context=None): - minimum_ans = 0 - maximum_ans = 0 page = self.pool.get('survey.page').browse(cr, uid, vals['page_id'], context=context).title - if vals.has_key('answer_choice_ids') and not len(vals['answer_choice_ids']): - if vals.has_key('type') and vals['type'] not in ['descriptive_text', 'single_textbox', 'comment', 'table']: - raise osv.except_osv(_('Warning!'), _('You must enter one or m or e answers f or question "%s" of page %s .') % (vals['question'], page)) + if 'answer_choice_ids' in vals and not len(vals.get('answer_choice_ids', [])) and \ + vals.get('type') not in ['descriptive_text', 'single_textbox', 'comment', 'table']: + raise osv.except_osv(_('Warning!'), _('You must enter one or more answers for question "%s" of page %s .') % (vals['question'], page)) - if vals.has_key('column_heading_ids') and not len(vals['column_heading_ids']): - if vals.has_key('type') and vals['type'] in ['matrix_of_choices_only_one_ans', 'matrix_of_choices_only_multi_ans', 'rating_scale']: - raise osv.except_osv(_('Warning!'), _('You must enter one or m or e column headings f or question "%s" of page %s.')% (vals['question'], page)) + if 'column_heading_ids' in vals and not len(vals.get('column_heading_ids', [])) and \ + vals.get('type') in ['matrix_of_choices_only_one_ans', 'matrix_of_choices_only_multi_ans', 'rating_scale']: + raise osv.except_osv(_('Warning!'), _('You must enter one or more column headings for question "%s" of page %s.') % (vals['question'], page)) - if vals['type'] in ['multiple_choice_multiple_ans', 'matrix_of_choices_only_one_ans', 'matrix_of_choices_only_multi_ans', 'rating_scale', 'multiple_textboxes', 'numerical_textboxes', 'date', 'date_ and _time']: - if vals.has_key('is_require_answer') and vals.has_key('required_type') and vals['required_type'] in ['at least', 'at most', 'exactly']: - if vals.has_key('answer_choice_ids') and vals['req_ans'] > len(vals['answer_choice_ids']) or not vals['req_ans']: - raise osv.except_osv(_('Warning!'), _("#Required Answer you entered is greater than the number of answer. Please use a number that is smaller than %d.") % (len(vals['answer_choice_ids'])+1)) - - if vals.has_key('is_require_answer') and vals.has_key('required_type') and vals['required_type'] == 'a range': - minimum_ans = vals['minimum_req_ans'] - maximum_ans = vals['maximum_req_ans'] - if vals.has_key('answer_choice_ids') or vals['minimum_req_ans'] > len(vals['answer_choice_ids']) or not vals['minimum_req_ans']: - raise osv.except_osv(_('Warning!'), _("Minimum Required Answer you entered is greater than the number of answer. Please use a number that is smaller than %d.") % (len(vals['answer_choice_ids'])+1)) - if vals.has_key('answer_choice_ids') or vals['maximum_req_ans'] > len(vals['answer_choice_ids']) or not vals['maximum_req_ans']: - raise osv.except_osv(_('Warning!'), _("Maximum Required Answer you entered f or your maximum is greater than the number of answer. Please use a number that is smaller than %d.") % (len(vals['answer_choice_ids'])+1)) - if maximum_ans <= minimum_ans: + if 'is_require_answer' in vals and vals.get('type') in ['multiple_choice_multiple_ans', 'matrix_of_choices_only_one_ans', \ + 'matrix_of_choices_only_multi_ans', 'rating_scale', 'multiple_textboxes', 'numerical_textboxes', 'date', 'date_and_time']: + if vals.get('required_type') in ['at least', 'at most', 'exactly']: + if 'answer_choice_ids' in vals and not vals.get('req_ans') or vals.get('req_ans') > len(vals['answer_choice_ids']): + raise osv.except_osv(_('Warning!'), _("#Required Answer you entered is greater than the number of answer. Please use a number that is smaller than %d.") % (len(vals['answer_choice_ids']) + 1)) + if vals.get('required_type') == 'a range': + if 'answer_choice_ids' in vals: + if not vals.get('minimum_req_ans') or vals['minimum_req_ans'] > len(vals['answer_choice_ids']): + raise osv.except_osv(_('Warning!'), _("Minimum Required Answer you entered is greater than the number of answer. Please use a number that is smaller than %d.") % (len(vals['answer_choice_ids']) + 1)) + if not vals.get('maximum_req_ans') or vals['maximum_req_ans'] > len(vals['answer_choice_ids']): + raise osv.except_osv(_('Warning!'), _("Maximum Required Answer you entered for your maximum is greater than the number of answer. Please use a number that is smaller than %d.") % (len(vals['answer_choice_ids']) + 1)) + if vals.get('maximum_req_ans', 0) <= vals.get('minimum_req_ans', 0): raise osv.except_osv(_('Warning!'), _("Maximum Required Answer is greater than Minimum Required Answer.")) - res = super(survey_question, self).create(cr, uid, vals, context) - return res + return super(survey_question, self).create(cr, uid, vals, context) def survey_save(self, cr, uid, ids, context=None): if context is None: context = {} - search_obj = self.pool.get('ir.ui.view') - search_id = search_obj.search(cr, uid, [('model', '=', 'survey.question.wiz'), ('name', '=', 'Survey Search')]) surv_name_wiz = self.pool.get('survey.name.wiz') surv_name_wiz.write(cr, uid, [context.get('sur_name_id', False)], {'transfer': True, 'page_no': context.get('page_number', False)}) return { - 'view_type': 'f or m', - 'view_mode': 'f or m', + 'view_type': 'form', + 'view_mode': 'form', 'res_model': 'survey.question.wiz', 'type': 'ir.actions.act_window', 'target': 'new', - #'search_view_id': search_id[0], + #'search_view_id': self.pool.get('ir.ui.view').search(cr, uid, [('model', '=', 'survey.question.wiz'), ('name', '=', 'Survey Search')])[0], 'context': context } @@ -525,8 +518,8 @@ class survey_question(osv.osv): if context is None: context = {} data = super(survey_question, self).default_get(cr, uid, fields, context) - if context.has_key('page_id'): - data['page_id']= context.get('page_id', False) + if context.get('page_id'): + data['page_id'] = context.get('page_id', False) return data survey_question() @@ -543,6 +536,7 @@ class survey_question_column_heading(osv.osv): if context.get('in_visible_rating_weight', False): return context['in_visible_rating_weight'] return False + def _get_in_visible_menu_choice(self, cr, uid, context=None): if context is None: context = {} @@ -558,7 +552,7 @@ class survey_question_column_heading(osv.osv): 'in_visible_rating_weight': fields.boolean('Is Rating Scale Invisible ??'), 'in_visible_menu_choice': fields.boolean('Is Menu Choice Invisible??') } - _defaults={ + _defaults = { 'in_visible_rating_weight': _get_in_visible_rating_weight, 'in_visible_menu_choice': _get_in_visible_menu_choice, } @@ -569,11 +563,11 @@ class survey_answer(osv.osv): _name = 'survey.answer' _description = 'Survey Answer' _rec_name = 'answer' - _ or der = 'sequence' + _order = 'sequence' def _calc_response_avg(self, cr, uid, ids, field_name, arg, context=None): val = {} - f or rec in self.browse(cr, uid, ids, context=context): + for rec in self.browse(cr, uid, ids, context=context): cr.execute("select count(question_id), (select count(answer_id) \ from survey_response_answer sra, survey_response_line sa \ where sra.response_id = sa.id and sra.answer_id = %d \ @@ -647,9 +641,9 @@ class survey_response(osv.osv): return [] reads = self.read(cr, uid, ids, ['partner_id', 'date_create'], context=context) res = [] - f or rec or d in reads: - name = (rec or d['partner_id'] and rec or d['partner_id'][1] or '') + ' (' + rec or d['date_create'].split('.')[0] + ')' - res.append((rec or d['id'], name)) + for record in reads: + name = (record['partner_id'] and record['partner_id'][1] or '') + ' (' + record['date_create'].split('.')[0] + ')' + res.append((record['id'], name)) return res def copy(self, cr, uid, id, default=None, context=None): @@ -685,11 +679,11 @@ survey_response_line() class survey_tbl_column_heading(osv.osv): _name = 'survey.tbl.column.heading' - _ or der = 'name' + _order = 'name' _columns = { 'name': fields.integer('Row Number'), 'column_id': fields.many2one('survey.question.column.heading', 'Column'), - 'value': fields.char('Value', size = 255), + 'value': fields.char('Value', size=255), 'response_table_id': fields.many2one('survey.response.line', 'Answer', ondelete='cascade'), } @@ -704,10 +698,10 @@ class survey_response_answer(osv.osv): 'response_id': fields.many2one('survey.response.line', 'Answer', ondelete='cascade'), 'answer_id': fields.many2one('survey.answer', 'Answer', required=1, ondelete='cascade'), 'column_id': fields.many2one('survey.question.column.heading', 'Column'), - 'answer': fields.char('Value', size =255), - 'value_choice': fields.char('Value Choice', size =255), + 'answer': fields.char('Value', size=255), + 'value_choice': fields.char('Value Choice', size=255), 'comment': fields.text('Notes'), - 'comment_field': fields.char('Comment', size = 255) + 'comment_field': fields.char('Comment', size=255) } survey_response_answer() diff --git a/addons/survey/wizard/survey_selection.py b/addons/survey/wizard/survey_selection.py index cb991ee8db6..09a8d1921f9 100644 --- a/addons/survey/wizard/survey_selection.py +++ b/addons/survey/wizard/survey_selection.py @@ -19,29 +19,27 @@ # ############################################################################## -from lxml import etree - from openerp.osv import fields, osv -from openerp.tools.translate import _ + class survey_name_wiz(osv.osv_memory): _name = 'survey.name.wiz' _columns = { - 'survey_id': fields.many2one('survey', 'Survey', required=True, ondelete='cascade', domain= [('state', '=', 'open')]), + 'survey_id': fields.many2one('survey', 'Survey', required=True, ondelete='cascade', domain=[('state', '=', 'open')]), 'page_no': fields.integer('Page Number'), 'note': fields.text("Description"), - 'page': fields.char('Page Position',size = 12), + 'page': fields.char('Page Position', size=12), 'transfer': fields.boolean('Page Transfer'), 'store_ans': fields.text('Store Answer'), - 'response': fields.char('Answer',size=16) + 'response': fields.char('Answer', size=16) } _defaults = { 'page_no': -1, 'page': 'next', 'transfer': 1, 'response': 0, - 'survey_id': lambda self,cr,uid,context:context.get('survey_id',False), + 'survey_id': lambda self, cr, uid, context: context.get('survey_id', False), 'store_ans': '{}' #Setting the default pattern as '{}' as the field is of type text. The field always gets the value in dict format } From 5032dad17d3bf4d74fd9ac07804881df6e70dafa Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Mon, 18 Feb 2013 18:55:59 +0100 Subject: [PATCH 0033/1010] [FIX] module: install_from_urls: restrict to administrators. Urls must come from apps server. lp bug: https://launchpad.net/bugs/1129299 fixed bzr revid: chs@openerp.com-20130218175559-ygo0goytspg119bl --- openerp/addons/base/module/module.py | 16 ++++++++++++++-- openerp/addons/base/static/src/js/apps.js | 4 ++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/openerp/addons/base/module/module.py b/openerp/addons/base/module/module.py index a0d1eedef2b..73c61812ee0 100644 --- a/openerp/addons/base/module/module.py +++ b/openerp/addons/base/module/module.py @@ -30,6 +30,7 @@ import shutil import tempfile import urllib import urllib2 +import urlparse import zipfile import zipimport @@ -39,6 +40,7 @@ except ImportError: from StringIO import StringIO # NOQA import openerp +import openerp.exceptions from openerp import modules, pooler, tools, addons from openerp.modules.db import create_categories from openerp.tools.parse_version import parse_version @@ -655,6 +657,11 @@ class module(osv.osv): return res def install_from_urls(self, cr, uid, urls, context=None): + if not self.pool['res.users'].has_group(cr, uid, 'base.group_system'): + raise openerp.exceptions.AccessDenied() + + apps_server = urlparse.urlparse(self.get_apps_server(cr, uid, context=context)) + OPENERP = 'openerp' tmp = tempfile.mkdtemp() _logger.debug('Install from url: %r', urls) @@ -663,6 +670,11 @@ class module(osv.osv): for module_name, url in urls.items(): if not url: continue # nothing to download, local version is already the last one + + up = urlparse.urlparse(url) + if up.scheme != apps_server.scheme or up.netloc != apps_server.netloc: + raise openerp.exceptions.AccessDenied() + try: _logger.info('Downloading module `%s` from OpenERP Apps', module_name) content = urllib2.urlopen(url).read() @@ -727,8 +739,8 @@ class module(osv.osv): finally: shutil.rmtree(tmp) - def install_by_names(self, cr, uid, names, context=None): - raise NotImplementedError('# TODO') + def get_apps_server(self, cr, uid, context=None): + return tools.config.get('apps_server', 'https://apps.openerp.com/apps') def _update_dependencies(self, cr, uid, mod_browse, depends=None): if depends is None: diff --git a/openerp/addons/base/static/src/js/apps.js b/openerp/addons/base/static/src/js/apps.js index a55c89a0483..7a77e827a94 100644 --- a/openerp/addons/base/static/src/js/apps.js +++ b/openerp/addons/base/static/src/js/apps.js @@ -62,8 +62,8 @@ openerp.base = function(instance) { if (instance.base.apps_client) { return check_client_available(instance.base.apps_client); } else { - var ICP = new instance.web.Model('ir.config_parameter'); - return ICP.call('get_param', ['apps.server', 'https://apps.openerp.com/apps']).then(function(u) { + var Mod = new instance.web.Model('ir.module.module'); + return Mod.call('get_apps_server').then(function(u) { var link = $(_.str.sprintf('', u))[0]; var host = _.str.sprintf('%s//%s', link.protocol, link.host); var dbname = link.pathname; From 2cd1601a70f2fa69c5e776053a592783168ba312 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Tue, 19 Feb 2013 11:03:55 +0100 Subject: [PATCH 0034/1010] [IMP] survey: in progress bzr revid: chm@openerp.com-20130219100355-o2l73vvgdd1tfqb6 --- addons/survey/survey.py | 2 +- addons/survey/wizard/survey_answer.py | 122 +++++++++++++++----------- 2 files changed, 74 insertions(+), 50 deletions(-) diff --git a/addons/survey/survey.py b/addons/survey/survey.py index 14b2da9c34e..1c6dfcad542 100644 --- a/addons/survey/survey.py +++ b/addons/survey/survey.py @@ -626,7 +626,7 @@ class survey_response(osv.osv): 'date_create': fields.datetime('Create Date', required=1), 'response_type': fields.selection([('manually', 'Manually'), ('link', 'Link')], 'Answer Type', required=1), 'question_ids': fields.one2many('survey.response.line', 'response_id', 'Answer'), - 'state': fields.selection([('new', 'Not Started'), ('skip', 'Not Finished'), ('done', 'Finished')], 'Status', readonly=True), + 'state': fields.selection([('new', 'Not Started'), ('skip', 'Not Finished'), ('done', 'Finished'), ('cancel', 'Canceled')], 'Status', readonly=True), 'token': fields.char("Indentification token", readonly=1), 'partner_id': fields.many2one('res.partner', 'Partner', readonly=1), 'email': fields.char("Email", size=64, readonly=1), diff --git a/addons/survey/wizard/survey_answer.py b/addons/survey/wizard/survey_answer.py index 0a6fe1834c4..6f5be521614 100644 --- a/addons/survey/wizard/survey_answer.py +++ b/addons/survey/wizard/survey_answer.py @@ -29,6 +29,8 @@ from datetime import datetime from openerp.tools.translate import _ from openerp.tools.safe_eval import safe_eval +DATETIME_FORMAT = "%Y-%m-%d" + class survey_question_wiz(osv.osv_memory): _name = 'survey.question.wiz' @@ -160,7 +162,8 @@ class survey_question_wiz(osv.osv_memory): def _view_field_rating_scale(self, cr, uid, xml_group, fields, readonly, que, que_rec): self._view_field_matrix_of_choices_only_one_ans(xml_group, fields, readonly, que, que_rec) - def _view_field_after_matrix_of_choices(self, cr, uid, xml_group, fields, readonly, que, que_rec): + def _view_field_postprocessing(self, cr, uid, xml_group, fields, readonly, que, que_rec): + # after matrix of choices if que_rec.type in ['multiple_choice_only_one_ans', 'multiple_choice_multiple_ans'] and que_rec.comment_field_type in ['char', 'text'] and que_rec.make_comment_field: etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'name': tools.ustr(que.id) + "_otherfield", 'colspan': "4"}) fields[tools.ustr(que.id) + "_otherfield"] = {'type': 'boolean', 'string': que_rec.comment_label, 'views': {}} @@ -172,6 +175,8 @@ class survey_question_wiz(osv.osv_memory): fields[tools.ustr(que.id) + "_other"] = {'type': que_rec.comment_field_type, 'string': '', 'views': {}} def _view_survey_complete(self, result, context): + """ rendering of the message displayed when the survey is completed + """ xml_form = etree.Element('form', {'string': _('Complete Survey Answer')}) #xml_footer = etree.SubElement(xml_form, 'footer', {'col': '6', 'colspan': '4', 'class': 'oe_survey_title_height'}) etree.SubElement(xml_form, 'separator', {'string': 'Survey Completed', 'colspan': "4"}) @@ -183,6 +188,8 @@ class survey_question_wiz(osv.osv_memory): result['context'] = context def _survey_complete(self, cr, uid, survey_id, partner_id, sur_name_read, survey_browse, context): + """ list of action to do when the survey is completed + """ survey_obj = self.pool.get('survey') sur_response_obj = self.pool.get('survey.response') @@ -206,9 +213,9 @@ class survey_question_wiz(osv.osv_memory): } self.pool.get('mail.message').create(cr, uid, val, context=context) - def _check_token(self, cr, uid, survey_id, context): + def _check_access(self, cr, uid, survey_id, context): # get if the token of the partner or anonymous user is valid - res = {'partner_id': False, 'response_id': False, 'state': None} + res = {'partner_id': False, 'response_id': False, 'state': None, 'error_message': None} if not survey_id: return res @@ -219,18 +226,31 @@ class survey_question_wiz(osv.osv_memory): return res sur_response_obj = self.pool.get('survey.response') - dom = [('survey_id', '=', survey_id), ('state', 'in', ['new', 'skip']), "|", ('date_deadline', '=', None), ('date_deadline', '<', datetime.now())] + dom = [('survey_id', '=', survey_id), ('state', 'in', ['new', 'skip']), "|", ('date_deadline', '=', None), ('date_deadline', '>', datetime.now())] - if context.get("survey_token", None): - response_id = sur_response_obj.search(cr, uid, dom + [("token", "=", context.get("survey_token", None))], context=context, limit=1, order="date_deadline DESC") + if context.get("survey_token"): + response_ids = sur_response_obj.search(cr, uid, dom + [("token", "=", context.get("survey_token", None))], context=context, limit=1, order="id DESC") else: pid = self.pool.get('res.users').browse(cr, uid, uid, context=context).partner_id.id - response_id = sur_response_obj.search(cr, uid, dom + [('partner_id', '=', pid)], context=context, limit=1, order="date_deadline DESC") + response_ids = sur_response_obj.search(cr, uid, dom + [('partner_id', '=', pid)], context=context, limit=1, order="date_deadline DESC") - if response_id: - sur_response_browse = sur_response_obj.browse(cr, uid, response_id[0], context=context) + if response_ids: + sur_response_browse = sur_response_obj.browse(cr, uid, response_ids[0], context=context) + res['response_id'] = response_ids[0] res['partner_id'] = sur_response_browse.partner_id.id or False res['state'] = sur_response_browse.state + else: + response_ids = sur_response_obj.search(cr, uid, [('survey_id', '=', survey_id), '|', ("token", "=", context.get("survey_token", None)), ('partner_id', '=', pid)], context=context, limit=1, order="date_deadline DESC") + if not response_ids: + res['error_message'] = _("You do not have access to this survey.") + else: + response = sur_response_obj.browse(cr, uid, response_ids[0], context=context) + if response.state == 'done': + res['error_message'] = _("Thank you, you have already answered this survey.") + elif response.date_deadline and response.date_deadline < datetime.now(): + res['error_message'] = _("The deadline for responding to this survey is exceeded since %s") % datetime.strptime(response.date_deadline, DATETIME_FORMAT) + else: + res['error_message'] = _("You do not have access to this survey.") return res @@ -241,15 +261,19 @@ class survey_question_wiz(osv.osv_memory): if context is None: context = {} + print "fields_view_get", context + result = super(survey_question_wiz, self).fields_view_get(cr, uid, view_id, view_type, context, toolbar, submenu) surv_name_wiz = self.pool.get('survey.name.wiz') survey_obj = self.pool.get('survey') page_obj = self.pool.get('survey.page') que_obj = self.pool.get('survey.question') - sur_response_obj = self.pool.get('survey.response') if view_type in ['form']: + + print view_type + wiz_id = 0 sur_name_rec = None if 'sur_name_id' in context: @@ -289,8 +313,7 @@ class survey_question_wiz(osv.osv_memory): pre_button = False readonly = 0 - if context.get('response_id', False) \ - and int(context['response_id'][0]) > 0: + if context.get('response_id', False) and int(context['response_id'][0]) > 0: readonly = 1 if not sur_name_rec.page_no + 1: @@ -298,17 +321,23 @@ class survey_question_wiz(osv.osv_memory): sur_name_read = surv_name_wiz.browse(cr, uid, context['sur_name_id'], context=context) page_number = int(sur_name_rec.page_no) + + print sur_name_read + if sur_name_read.transfer or not sur_name_rec.page_no + 1: surv_name_wiz.write(cr, uid, [context['sur_name_id']], {'transfer': False}) flag = False fields = {} # get if the token of the partner or anonymous user is valid - check_token = self._check_token(cr, uid, survey_id, context) + check_token = self._check_access(cr, uid, survey_id, context) + + print "check_token", check_token # have acces to this survey - if check_token['partner_id'] or check_token['response_id']: + if not check_token['error_message']: active = context.get('active', False) + print "access" if sur_name_read.page == "next" or sur_name_rec.page_no == -1: if total_pages > sur_name_rec.page_no + 1: @@ -316,7 +345,7 @@ class survey_question_wiz(osv.osv_memory): raise osv.except_osv(_('Warning!'), _("You cannot answer because the survey is not open.")) if survey_browse.max_response_limit and survey_browse.max_response_limit <= survey_browse.tot_start_survey and not sur_name_rec.page_no + 1: - survey_obj.write(cr, uid, survey_id, {'state': 'close', 'date_close': strftime("%Y-%m-%d %H: %M: %S")}) + survey_obj.write(cr, uid, survey_id, {'state': 'close', 'date_close': datetime.now()}) p_id = p_id[sur_name_rec.page_no + 1] surv_name_wiz.write(cr, uid, [context['sur_name_id'], ], {'page_no': sur_name_rec.page_no + 1}) @@ -385,7 +414,7 @@ class survey_question_wiz(osv.osv_memory): # rendering different views getattr(self, "_view_field_%s" % que_rec.type)(cr, uid, xml_group, fields, readonly, que, que_rec) if que_rec.type in ['multiple_choice_only_one_ans', 'multiple_choice_multiple_ans', 'matrix_of_choices_only_one_ans', 'matrix_of_choices_only_multi_ans', 'rating_scale'] and que_rec.is_comment_require: - self._view_field_after_matrix_of_choices(cr, uid, xml_group, fields, readonly, que, que_rec) + self._view_field_postprocessing(cr, uid, xml_group, fields, readonly, que, que_rec) xml_footer = etree.SubElement(xml_form, 'footer', {'col': '8', 'colspan': '1', 'width': "100%"}) @@ -420,9 +449,7 @@ class survey_question_wiz(osv.osv_memory): else: xml_form = etree.Element('form', {'string': _('No access to this survey')}) etree.SubElement(xml_form, 'separator', {'string': survey_browse.title, 'colspan': "4"}) - etree.SubElement(xml_form, 'label', {'string': "You don't have access to this survey."}) - etree.SubElement(xml_form, 'newline') - etree.SubElement(xml_form, 'label', {'string': "The access you have not been given or the deadline has passed."}) + etree.SubElement(xml_form, 'label', {'string': check_token['error_message']}) root = xml_form.getroottree() result['arch'] = etree.tostring(root) result['fields'] = {} @@ -455,17 +482,24 @@ class survey_question_wiz(osv.osv_memory): value = {} if context is None: context = {} + for field in fields_list: if field.split('_')[0] == 'progress': tot_page_id = self.pool.get('survey').browse(cr, uid, context.get('survey_id', False)) tot_per = (float(100) * (int(field.split('_')[2]) + 1) / len(tot_page_id.page_ids)) value[field] = tot_per + + check_token = self._check_access(cr, uid, context.get('survey_id'), context) + + response_ans = False sur_response_obj = self.pool.get('survey.response') - surv_name_wiz = self.pool.get('survey.name.wiz') + if check_token.get('response_id'): + response_ans = sur_response_obj.browse(cr, uid, check_token['response_id']) if context.get('response_id') and int(context['response_id'][0]) > 0: response_ans = sur_response_obj.browse(cr, uid, context['response_id'][context['response_no']]) - fields_list.sort() + if response_ans: + fields_list.sort() for que in response_ans.question_ids: for field in fields_list: if field.split('_')[0] != "progress" and field.split('_')[0] == str(que.question_id.id): @@ -511,6 +545,8 @@ class survey_question_wiz(osv.osv_memory): return value if context.get('active', False): return value + + surv_name_wiz = self.pool.get('survey.name.wiz') sur_name_read = surv_name_wiz.read(cr, uid, context.get('sur_name_id', False)) for key, val in safe_eval(sur_name_read.get('store_ans', "{}")).items(): @@ -525,8 +561,8 @@ class survey_question_wiz(osv.osv_memory): """ context = context or {} - check_token = self._check_token(cr, uid, context['survey_id'], context) - if not check_token['partner_id'] and not check_token['response_id']: + check_token = self._check_access(cr, uid, context['survey_id'], context) + if check_token['error_message']: return False survey_question_wiz_id = super(survey_question_wiz, self).create(cr, uid, {'name': vals.get('name')}, context=context) @@ -551,10 +587,10 @@ class survey_question_wiz(osv.osv_memory): que_obj = self.pool.get('survey.question') sur_name_read = surv_name_wiz.read(cr, uid, context.get('sur_name_id', False), context=context) - if not sur_name_read['response']: - response_id = int(sur_name_read['response']) - elif check_token['response_id']: + if check_token['response_id']: response_id = check_token['response_id'] + elif not sur_name_read['response']: + response_id = int(sur_name_read['response']) else: response_id = sur_response_obj.create(cr, uid, {'response_type': 'link', 'partner_id': check_token['partner_id'], 'date_create': datetime.now(), 'survey_id': context.get('survey_id')}) @@ -1118,16 +1154,15 @@ class survey_question_wiz(osv.osv_memory): 'context': context } - def action_next(self, cr, uid, ids, context=None): - """ - Goes to Next page. + def _action_next_previous(self, cr, uid, ids, next, context=None): + """ Goes to nex page or previous page. """ if context is None: context = {} - surv_name_wiz = self.pool.get('survey.name.wiz') search_obj = self.pool.get('ir.ui.view') search_id = search_obj.search(cr, uid, [('model', '=', 'survey.question.wiz'), ('name', '=', 'Survey Search')]) - surv_name_wiz.write(cr, uid, [context.get('sur_name_id', False)], {'transfer': True, 'page': 'next'}) + surv_name_wiz = self.pool.get('survey.name.wiz') + surv_name_wiz.write(cr, uid, [context.get('sur_name_id', False)], {'transfer': True, 'page': next and 'next' or 'previous'}) return { 'view_type': 'form', "view_mode": 'form', @@ -1138,26 +1173,15 @@ class survey_question_wiz(osv.osv_memory): 'context': context } + def action_next(self, cr, uid, ids, context=None): + """ Goes to Next page. + """ + return self._action_next_previous(cr, uid, ids, True, context=context) + def action_previous(self, cr, uid, ids, context=None): + """ Goes to previous page. """ - Goes to previous page. - """ - if context is None: - context = {} - surv_name_wiz = self.pool.get('survey.name.wiz') - search_obj = self.pool.get('ir.ui.view') - search_id = search_obj.search(cr, uid, [('model', '=', 'survey.question.wiz'), \ - ('name', '=', 'Survey Search')]) - surv_name_wiz.write(cr, uid, [context.get('sur_name_id', False)], {'transfer': True, 'page': 'previous'}) - return { - 'view_type': 'form', - "view_mode": 'form', - 'res_model': 'survey.question.wiz', - 'type': 'ir.actions.act_window', - 'target': context.get('ir_actions_act_window_target', 'inline'), - 'search_view_id': search_id[0], - 'context': context - } + return self._action_next_previous(cr, uid, ids, False, context=context) survey_question_wiz() From d317812332e7572cc96f0b98cd3ccd3d497c7f40 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Tue, 19 Feb 2013 11:09:35 +0100 Subject: [PATCH 0035/1010] [IMP] survey: in progress, default value ok bzr revid: chm@openerp.com-20130219100935-47fbk2ihgwb8dst5 --- addons/survey/wizard/survey_answer.py | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/addons/survey/wizard/survey_answer.py b/addons/survey/wizard/survey_answer.py index 6f5be521614..19c4ec2caf3 100644 --- a/addons/survey/wizard/survey_answer.py +++ b/addons/survey/wizard/survey_answer.py @@ -261,8 +261,6 @@ class survey_question_wiz(osv.osv_memory): if context is None: context = {} - print "fields_view_get", context - result = super(survey_question_wiz, self).fields_view_get(cr, uid, view_id, view_type, context, toolbar, submenu) surv_name_wiz = self.pool.get('survey.name.wiz') @@ -271,9 +269,6 @@ class survey_question_wiz(osv.osv_memory): que_obj = self.pool.get('survey.question') if view_type in ['form']: - - print view_type - wiz_id = 0 sur_name_rec = None if 'sur_name_id' in context: @@ -322,8 +317,6 @@ class survey_question_wiz(osv.osv_memory): sur_name_read = surv_name_wiz.browse(cr, uid, context['sur_name_id'], context=context) page_number = int(sur_name_rec.page_no) - print sur_name_read - if sur_name_read.transfer or not sur_name_rec.page_no + 1: surv_name_wiz.write(cr, uid, [context['sur_name_id']], {'transfer': False}) flag = False @@ -331,8 +324,6 @@ class survey_question_wiz(osv.osv_memory): # get if the token of the partner or anonymous user is valid check_token = self._check_access(cr, uid, survey_id, context) - - print "check_token", check_token # have acces to this survey if not check_token['error_message']: @@ -489,13 +480,14 @@ class survey_question_wiz(osv.osv_memory): tot_per = (float(100) * (int(field.split('_')[2]) + 1) / len(tot_page_id.page_ids)) value[field] = tot_per - check_token = self._check_access(cr, uid, context.get('survey_id'), context) + if not context.get('edit'): + check_token = self._check_access(cr, uid, context.get('survey_id'), context) response_ans = False sur_response_obj = self.pool.get('survey.response') - if check_token.get('response_id'): + if not context.get('edit') and check_token.get('response_id'): response_ans = sur_response_obj.browse(cr, uid, check_token['response_id']) - if context.get('response_id') and int(context['response_id'][0]) > 0: + elif context.get('response_id') and int(context['response_id'][0]) > 0: response_ans = sur_response_obj.browse(cr, uid, context['response_id'][context['response_no']]) if response_ans: From 145f161e2a87cad6c89196232830f4abb74d0008 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Tue, 19 Feb 2013 15:38:12 +0100 Subject: [PATCH 0036/1010] [IMP] survey: in progress bzr revid: chm@openerp.com-20130219143812-uv59mxjmyrtucfwl --- addons/survey/static/src/css/survey.css | 21 +++++++ addons/survey/survey.py | 77 ++++++++++++------------- addons/survey/survey_view.xml | 53 +++++++++++------ addons/survey/wizard/survey_answer.py | 25 +++++--- 4 files changed, 109 insertions(+), 67 deletions(-) diff --git a/addons/survey/static/src/css/survey.css b/addons/survey/static/src/css/survey.css index 34d686c6e77..6264a9037a7 100644 --- a/addons/survey/static/src/css/survey.css +++ b/addons/survey/static/src/css/survey.css @@ -9,3 +9,24 @@ width: 200px; } + +.openerp .oe_kanban_survey .oe_kanban_status, +.openerp .oe_kanban_survey .oe_kanban_status_green, +.openerp .oe_kanban_survey .oe_kanban_status_darkgreen, +.openerp .oe_kanban_survey .oe_kanban_status_red { + display: block; + height: 10px; + width: 10px; + background-color: #dddddd; + border-radius: 5px; + margin-top: 3px; +} +.openerp .oe_kanban_survey .oe_kanban_status_green { + background-color: green; +} +.openerp .oe_kanban_survey .oe_kanban_status_darkgreen { + background-color: darkgreen; +} +.openerp .oe_kanban_survey .oe_kanban_status_red { + background-color: red; +} \ No newline at end of file diff --git a/addons/survey/survey.py b/addons/survey/survey.py index 1c6dfcad542..c415b902f73 100644 --- a/addons/survey/survey.py +++ b/addons/survey/survey.py @@ -20,8 +20,7 @@ ############################################################################## import copy -from time import strftime - +from datetime import datetime from openerp.osv import fields, osv from openerp.tools.translate import _ @@ -46,16 +45,13 @@ class survey(osv.osv): return data _columns = { - 'id': fields.integer('ID'), 'title': fields.char('Survey Title', size=128, required=1), 'page_ids': fields.one2many('survey.page', 'survey_id', 'Page'), 'date_open': fields.datetime('Survey Open Date', readonly=1), 'date_close': fields.datetime('Survey Close Date', readonly=1), 'max_response_limit': fields.integer('Maximum Answer Limit', help="Set to one if survey is answerable only once"), - 'response_partner': fields.integer('Maximum Answer per partner', - help="Set to one if you require only one Answer per partner"), - 'state': fields.selection([('open', 'Open'), ('cancel', 'Cancelled'), ('close', 'Closed')], 'Status', readonly=True), + 'state': fields.selection([('draft', 'Draft'), ('open', 'Open freely'), ('restricted', 'Restricted invitation'), ('close', 'Close'), ('cancel', 'Cancelled')], 'Status'), 'responsible_id': fields.many2one('res.users', 'Responsible', help="User responsible forsurvey"), 'tot_start_survey': fields.integer("Total Started Survey", readonly=1), 'tot_comp_survey': fields.integer("Total Completed Survey", readonly=1), @@ -64,27 +60,30 @@ class survey(osv.osv): 'send_response': fields.boolean('Email Notification on Answer'), 'type': fields.many2one('survey.type', 'Type'), 'color': fields.integer('Color Index'), + 'response_ids': fields.one2many('survey.response', 'survey_id', 'Responses', readonly=1), } _defaults = { - 'state': lambda * a: "open", - 'tot_start_survey': lambda * a: 0, - 'tot_comp_survey': lambda * a: 0, - 'send_response': lambda * a: 1, - 'response_partner': lambda * a: 1, + 'state': "draft", + 'tot_start_survey': 0, + 'tot_comp_survey': 0, + 'send_response': 1, 'date_open': fields.datetime.now, } + def survey_draft(self, cr, uid, ids, arg): + return self.write(cr, uid, ids, {'state': 'draft', 'date_open': None}) + def survey_open(self, cr, uid, ids, arg): - self.write(cr, uid, ids, {'state': 'open', 'date_open': strftime("%Y-%m-%d %H: %M: %S")}) - return True + return self.write(cr, uid, ids, {'state': 'open', 'date_open': datetime.now()}) def survey_close(self, cr, uid, ids, arg): - self.write(cr, uid, ids, {'state': 'close', 'date_close': strftime("%Y-%m-%d %H: %M: %S")}) - return True + return self.write(cr, uid, ids, {'state': 'close', 'date_close': datetime.now()}) + + def survey_restricted(self, cr, uid, ids, arg): + return self.write(cr, uid, ids, {'state': 'restricted', 'date_close': datetime.now()}) def survey_cancel(self, cr, uid, ids, arg): - self.write(cr, uid, ids, {'state': 'cancel'}) - return True + return self.write(cr, uid, ids, {'state': 'cancel', 'date_close': datetime.now()}) def copy(self, cr, uid, ids, default=None, context=None): vals = {} @@ -243,7 +242,7 @@ class survey_page(osv.osv): 'note': fields.text('Description'), } _defaults = { - 'sequence': lambda * a: 1 + 'sequence': 1 } def default_get(self, cr, uid, fields, context=None): @@ -372,20 +371,20 @@ class survey_question(osv.osv): 'no_of_rows': fields.integer('No of Rows'), } _defaults = { - 'sequence': lambda * a: 1, - 'type': lambda * a: 'multiple_choice_multiple_ans', - 'req_error_msg': lambda * a: 'This question requires an answer.', - 'required_type': lambda * a: 'at least', - 'req_ans': lambda * a: 1, - 'comment_field_type': lambda * a: 'char', - 'comment_label': lambda * a: 'Other (please specify)', - 'comment_valid_type': lambda * a: 'do_not_validate', - 'comment_valid_err_msg': lambda * a: 'The comment you entered is in an invalid format.', - 'validation_type': lambda * a: 'do_not_validate', - 'validation_valid_err_msg': lambda * a: 'The comment you entered is in an invalid format.', - 'numeric_required_sum_err_msg': lambda * a: 'The choices need to add up to [enter sum here].', - 'make_comment_field_err_msg': lambda * a: 'Please enter a comment.', - 'in_visible_answer_type': lambda * a: 1 + 'sequence': 1, + 'type': 'multiple_choice_multiple_ans', + 'req_error_msg': 'This question requires an answer.', + 'required_type': 'at least', + 'req_ans': 1, + 'comment_field_type': 'char', + 'comment_label': 'Other (please specify)', + 'comment_valid_type': 'do_not_validate', + 'comment_valid_err_msg': 'The comment you entered is in an invalid format.', + 'validation_type': 'do_not_validate', + 'validation_valid_err_msg': 'The comment you entered is in an invalid format.', + 'numeric_required_sum_err_msg': 'The choices need to add up to [enter sum here].', + 'make_comment_field_err_msg': 'Please enter a comment.', + 'in_visible_answer_type': 1 } def on_change_type(self, cr, uid, ids, type, context=None): @@ -486,7 +485,7 @@ class survey_question(osv.osv): if 'is_require_answer' in vals and vals.get('type') in ['multiple_choice_multiple_ans', 'matrix_of_choices_only_one_ans', \ 'matrix_of_choices_only_multi_ans', 'rating_scale', 'multiple_textboxes', 'numerical_textboxes', 'date', 'date_and_time']: if vals.get('required_type') in ['at least', 'at most', 'exactly']: - if 'answer_choice_ids' in vals and not vals.get('req_ans') or vals.get('req_ans') > len(vals['answer_choice_ids']): + if 'answer_choice_ids' in vals and 'answer_choice_ids' in vals and vals.get('req_ans') > len(vals.get('answer_choice_ids', [])): raise osv.except_osv(_('Warning!'), _("#Required Answer you entered is greater than the number of answer. Please use a number that is smaller than %d.") % (len(vals['answer_choice_ids']) + 1)) if vals.get('required_type') == 'a range': if 'answer_choice_ids' in vals: @@ -571,7 +570,7 @@ class survey_answer(osv.osv): cr.execute("select count(question_id), (select count(answer_id) \ from survey_response_answer sra, survey_response_line sa \ where sra.response_id = sa.id and sra.answer_id = %d \ - and sa.state='done') as tot_ans from survey_response_line \ + and sa.state='done') as tot_ans from survey_response_line \ where question_id = %d and state = 'done'"\ % (rec.id, rec.question_id.id)) res = cr.fetchone() @@ -603,8 +602,8 @@ class survey_answer(osv.osv): 'in_visible_answer_type': fields.boolean('Is Answer Type Invisible??') } _defaults = { - # 'sequence': lambda * a: 1, - 'type': lambda * a: 'char', + # 'sequence': 1, + 'type': 'char', 'in_visible_answer_type': _get_in_visible_answer_type, } @@ -632,8 +631,8 @@ class survey_response(osv.osv): 'email': fields.char("Email", size=64, readonly=1), } _defaults = { - 'state': lambda * a: "new", - 'response_type': lambda * a: "manually", + 'state': "new", + 'response_type': "manually", } def name_get(self, cr, uid, ids, context=None): @@ -671,7 +670,7 @@ class survey_response_line(osv.osv): 'single_text': fields.char('Text', size=255), } _defaults = { - 'state': lambda * a: "draft", + 'state': "draft", } survey_response_line() diff --git a/addons/survey/survey_view.xml b/addons/survey/survey_view.xml index 104411ac755..bbc45e8a179 100644 --- a/addons/survey/survey_view.xml +++ b/addons/survey/survey_view.xml @@ -21,19 +21,21 @@
-
-

@@ -1064,6 +1046,7 @@ + -