diff --git a/addons/auth_signup/res_users.py b/addons/auth_signup/res_users.py index 38beb087c7a..6b79e1ab461 100644 --- a/addons/auth_signup/res_users.py +++ b/addons/auth_signup/res_users.py @@ -260,10 +260,9 @@ class res_users(osv.Model): # send email to users with their signup url template = False if context.get('create_user'): - try: - template = self.pool.get('ir.model.data').get_object(cr, uid, 'auth_signup', 'set_password_email') - except ValueError: - pass + template = self.pool.get('ir.model.data').get_object(cr, uid, 'auth_signup', 'set_password_email') + if not template.exists(): + template = False if not bool(template): template = self.pool.get('ir.model.data').get_object(cr, uid, 'auth_signup', 'reset_password_email') assert template._name == 'email.template' diff --git a/addons/edi/models/res_partner.py b/addons/edi/models/res_partner.py index 057e84b5541..3c3ca45949f 100644 --- a/addons/edi/models/res_partner.py +++ b/addons/edi/models/res_partner.py @@ -55,7 +55,7 @@ class res_partner(osv.osv, EDIMixin): res_partner_bank_type = self.pool.get('res.partner.bank.type') try: return self.pool.get('ir.model.data').get_object(cr, uid, 'base', 'bank_normal', context=context).code - except ValueError: + except: pass # second option: create a new custom type for EDI or use it if already created, as IBAN type is # not always appropriate: we need a free-form bank type for max flexibility (users can correct diff --git a/addons/mail/mail_thread.py b/addons/mail/mail_thread.py index 9692b94f159..44973696cb7 100644 --- a/addons/mail/mail_thread.py +++ b/addons/mail/mail_thread.py @@ -461,9 +461,8 @@ class mail_thread(osv.AbstractModel): posted = False for subtype in subtypes: - try: - subtype_rec = self.pool.get('ir.model.data').get_object(cr, uid, subtype.split('.')[0], subtype.split('.')[1], context=context) - except ValueError, e: + subtype_rec = self.pool.get('ir.model.data').get_object(cr, uid, subtype.split('.')[0], subtype.split('.')[1], context=context) + if not subtype_rec.exists(): _logger.debug('subtype %s not found, giving error "%s"' % (subtype, e)) continue message = format_message(subtype_rec.description if subtype_rec.description else subtype_rec.name, tracked_values) diff --git a/addons/mail/update.py b/addons/mail/update.py index bcf9bb8c7c9..3d07ce739ab 100644 --- a/addons/mail/update.py +++ b/addons/mail/update.py @@ -94,13 +94,11 @@ class publisher_warranty_contract(osv.osv): # old behavior based on res.log; now on mail.message, that is not necessarily installed IMD = self.pool['ir.model.data'] user = self.pool['res.users'].browse(cr, SUPERUSER_ID, SUPERUSER_ID) - try: - poster = IMD.get_object(cr, SUPERUSER_ID, 'mail', 'group_all_employees') - except ValueError: - # Cannot found group, post the message on the wall of the admin - poster = user + poster = IMD.get_object(cr, SUPERUSER_ID, 'mail', 'group_all_employees') if not poster.exists(): - return True + if not user.exists(): + return True + poster = user for message in result["messages"]: try: poster.message_post(body=message, subtype='mt_comment', partner_ids=[user.partner_id.id]) diff --git a/addons/sale/res_config.py b/addons/sale/res_config.py index 04958521ab5..70ef3371d41 100644 --- a/addons/sale/res_config.py +++ b/addons/sale/res_config.py @@ -87,12 +87,9 @@ Example: 10% for retailers, promotion of 5 EUR on this product, etc."""), user = self.pool.get('res.users').browse(cr, uid, uid, context) res['time_unit'] = user.company_id.project_time_mode_id.id else: - try: - product = ir_model_data.get_object(cr, uid, 'product', 'product_product_consultant') + product = ir_model_data.get_object(cr, uid, 'product', 'product_product_consultant') + if product.exists(): res['time_unit'] = product.uom_id.id - except ValueError: - # keep default value in that case - _logger.warning("Product with xml_id 'product.product_product_consultant' not found") return res def _get_default_time_unit(self, cr, uid, context=None): @@ -108,10 +105,10 @@ Example: 10% for retailers, promotion of 5 EUR on this product, etc."""), wizard = self.browse(cr, uid, ids)[0] if wizard.time_unit: - try: - product = ir_model_data.get_object(cr, uid, 'product', 'product_product_consultant') + product = ir_model_data.get_object(cr, uid, 'product', 'product_product_consultant') + if product.exists(): product.write({'uom_id': wizard.time_unit.id, 'uom_po_id': wizard.time_unit.id}) - except ValueError: + else: _logger.warning("Product with xml_id 'product.product_product_consultant' not found, UoMs not updated!") if wizard.module_project and wizard.time_unit: diff --git a/addons/stock/wizard/stock_fill_inventory.py b/addons/stock/wizard/stock_fill_inventory.py index b367e6069d8..71deb99a9d6 100644 --- a/addons/stock/wizard/stock_fill_inventory.py +++ b/addons/stock/wizard/stock_fill_inventory.py @@ -27,8 +27,10 @@ class stock_fill_inventory(osv.osv_memory): _description = "Import Inventory" def _default_location(self, cr, uid, ids, context=None): + location = self.pool.get('ir.model.data').get_object(cr, uid, 'stock', 'stock_location_stock') + if not location.exists(): + return False try: - location = self.pool.get('ir.model.data').get_object(cr, uid, 'stock', 'stock_location_stock') location.check_access_rule('read', context=context) location_id = location.id except (ValueError, orm.except_orm), e: diff --git a/addons/website/controllers/main.py b/addons/website/controllers/main.py index 26ee229fa33..e2839e5c75d 100644 --- a/addons/website/controllers/main.py +++ b/addons/website/controllers/main.py @@ -129,6 +129,7 @@ class Website(openerp.addons.web.controllers.main.Home): result.append({ 'name': v.inherit_option_id.name, 'id': v.id, + 'inherit_id': v.inherit_id.id, 'header': True, 'active': False }) @@ -136,6 +137,7 @@ class Website(openerp.addons.web.controllers.main.Home): result.append({ 'name': v.name, 'id': v.id, + 'inherit_id': v.inherit_id.id, 'header': False, 'active': (v.inherit_id.id == v.inherit_option_id.id) or (not optional and v.inherit_id.id) }) diff --git a/addons/website/data/website_data.xml b/addons/website/data/website_data.xml index 5ab70bf76be..d457fdafa96 100644 --- a/addons/website/data/website_data.xml +++ b/addons/website/data/website_data.xml @@ -37,7 +37,7 @@ - + @@ -130,10 +130,10 @@ gears - gears.jpg + gears.png ir.ui.view url - /website/static/src/img/library/gears.jpg + /website/static/src/img/library/gears.png diff --git a/addons/website/models/ir_http.py b/addons/website/models/ir_http.py index 8eadebf676d..ebef3459bc8 100644 --- a/addons/website/models/ir_http.py +++ b/addons/website/models/ir_http.py @@ -25,7 +25,7 @@ class ir_http(orm.AbstractModel): def _auth_method_public(self): if not request.session.uid: request.uid = request.registry['website'].get_public_user( - request.cr, openerp.SUPERUSER_ID, request.context).id + request.cr, openerp.SUPERUSER_ID, request.context) else: request.uid = request.session.uid @@ -46,13 +46,9 @@ class ir_http(orm.AbstractModel): else: self._auth_method_public() request.website = request.registry['website'].get_current_website(request.cr, request.uid, context=request.context) - langs = request.context['langs'] = [lg.code for lg in request.website.language_ids] - lang_cookie = request.httprequest.cookies.get('lang', None) - if lang_cookie in langs: - request.context['lang_cookie'] = lang_cookie - request.context['lang_default'] = request.website.default_lang_id.code + langs = [lg.code for lg in request.website.language_ids] if not hasattr(request, 'lang'): - request.lang = request.context['lang_default'] + request.lang = request.website.default_lang_id.code request.context['lang'] = request.lang request.website.preprocess_request(request) if not func: @@ -62,7 +58,6 @@ class ir_http(orm.AbstractModel): path = '/'.join(path) or '/' return self.reroute(path) return self._handle_404() - return super(ir_http, self)._dispatch() def reroute(self, path): diff --git a/addons/website/models/website.py b/addons/website/models/website.py index a442f95bd95..64e649dffde 100644 --- a/addons/website/models/website.py +++ b/addons/website/models/website.py @@ -36,8 +36,8 @@ def url_for(path_or_uri, lang=None, keep_query=None): if request and not url.netloc and not url.scheme: location = urlparse.urljoin(request.httprequest.path, location) lang = lang or request.context.get('lang') - langs = request.context.get('langs') - if location[0] == '/' and len(langs) > 1 and lang != request.context['lang_default']: + langs = [lg.code for lg in request.website.language_ids] + if location[0] == '/' and len(langs) > 1 and lang != request.website.default_lang_id.code: ps = location.split('/') if ps[1] in langs: ps[1] = lang @@ -69,6 +69,20 @@ def urlplus(url, params): )) class website(osv.osv): + def _get_menu_website(self, cr, uid, ids, context=None): + # IF a menu is changed, update all websites + return self.search(cr, uid, [], context=context) + + def _get_menu(self, cr, uid, ids, name, arg, context=None): + root_domain = [('parent_id', '=', False)] + menus = self.pool.get('website.menu').search(cr, uid, root_domain, order='id', context=context) + menu = menus and menus[0] or False + return dict( map(lambda x: (x, menu), ids) ) + + def _get_public_user(self, cr, uid, ids, name='public_user', arg=(), context=None): + ref = self.get_public_user(cr, uid, context=context) + return dict( map(lambda x: (x, ref), ids) ) + _name = "website" # Avoid website.website convention for conciseness (for new api). Got a special authorization from xmo and rco _description = "Website" _columns = { @@ -82,9 +96,13 @@ class website(osv.osv): 'social_linkedin': fields.char('LinkedIn Account'), 'social_youtube': fields.char('Youtube Account'), 'social_googleplus': fields.char('Google+ Account'), + 'public_user': fields.function(_get_public_user, relation='res.users', type='many2one', string='Public User'), + 'menu_id': fields.function(_get_menu, relation='website.menu', type='many2one', string='Main Menu', + store= { + 'website.menu': (_get_menu_website, ['sequence','parent_id','website_id'], 10) + }) } - public_user = None def new_page(self, cr, uid, name, template='website.default_page', ispage=True, context=None): context=context or {} # completely arbitrary max_length @@ -133,11 +151,9 @@ class website(osv.osv): return False def get_public_user(self, cr, uid, context=None): - if not self.public_user: - uid = openerp.SUPERUSER_ID - ref = self.pool['ir.model.data'].get_object_reference(cr, uid, 'website', 'public_user') - self.public_user = self.pool[ref[0]].browse(cr, uid, ref[1]) - return self.public_user + uid = openerp.SUPERUSER_ID + res = self.pool['ir.model.data'].get_object_reference(cr, uid, 'website', 'public_user') + return res and res[1] or False def get_current_website(self, cr, uid, context=None): # TODO: Select website, currently hard coded @@ -147,19 +163,13 @@ class website(osv.osv): def redirect(url): return werkzeug.utils.redirect(url_for(url)) request.redirect = redirect - is_public_user = request.uid == self.get_public_user(cr, uid, context).id - - user = self.pool['res.users'].browse(cr, uid, uid, context=context) - website_publisher_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'base', 'group_website_publisher')[1] - is_website_publisher = website_publisher_id in [g.id for g in user.groups_id] - + is_website_publisher = self.pool.get('ir.model.access').check_groups(cr, uid, 'base.group_website_publisher') lang = request.context['lang'] is_master_lang = lang == request.website.default_lang_id.code request.context.update({ - 'is_public_user': is_public_user, 'is_master_lang': is_master_lang, 'editable': is_website_publisher, - 'translatable': not is_public_user and not is_master_lang, + 'translatable': not is_master_lang, }) def get_template(self, cr, uid, ids, template, context=None): @@ -174,7 +184,6 @@ class website(osv.osv): def _render(self, cr, uid, ids, template, values=None, context=None): user = self.pool.get("res.users") - if not context: context = {} @@ -200,8 +209,9 @@ class website(osv.osv): if 'main_object' not in qweb_context: qweb_context['main_object'] = view - - return view.render(qweb_context, engine='website.qweb', context=context) + #context['debug'] = True + result = view.render(qweb_context, engine='website.qweb', context=context) + return result def render(self, cr, uid, ids, template, values=None, context=None): def callback(template, values, context): @@ -333,7 +343,7 @@ class website(osv.osv): """ router = request.httprequest.app.get_db_router(request.db) # Force enumeration to be performed as public user - uid = self.get_public_user(cr, uid, context=context).id + uid = self.get_public_user(cr, uid, context=context)[1].id for rule in router.iter_rules(): if not self.rule_is_enumerable(rule): continue @@ -465,8 +475,6 @@ class website(osv.osv): html += request.website._render(template, {'object_id': object_id}) return html - def get_menu(self, cr, uid, ids, context=None): - return self.pool['website.menu'].get_menu(cr, uid, ids[0], context=context) class website_menu(osv.osv): _name = "website.menu" @@ -492,12 +500,7 @@ class website_menu(osv.osv): _parent_order = 'sequence, name' _order = "parent_left" - def get_menu(self, cr, uid, website_id, context=None): - root_domain = [('parent_id', '=', False)] # ('website_id', '=', website_id), - menu_ids = self.search(cr, uid, root_domain, order='id', context=context) - menu = self.browse(cr, uid, menu_ids, context=context) - return menu[0] - + # would be better to take a menu_id as argument def get_tree(self, cr, uid, website_id, context=None): def make_tree(node): menu_node = dict( @@ -512,7 +515,7 @@ class website_menu(osv.osv): for child in node.child_id: menu_node['children'].append(make_tree(child)) return menu_node - menu = self.get_menu(cr, uid, website_id, context=context) + menu = self.pool.get('website').browse(cr, uid, website_id, context=context).menu_id return make_tree(menu) def save(self, cr, uid, website_id, data, context=None): diff --git a/addons/website/static/src/img/library/gears.jpg b/addons/website/static/src/img/library/gears.jpg deleted file mode 100644 index 868c2532c41..00000000000 Binary files a/addons/website/static/src/img/library/gears.jpg and /dev/null differ diff --git a/addons/website/static/src/img/library/gears.png b/addons/website/static/src/img/library/gears.png new file mode 100644 index 00000000000..1d3c7d85ca0 Binary files /dev/null and b/addons/website/static/src/img/library/gears.png differ diff --git a/addons/website/static/src/js/website.ace.js b/addons/website/static/src/js/website.ace.js index 685ace69467..1156ac5165e 100644 --- a/addons/website/static/src/js/website.ace.js +++ b/addons/website/static/src/js/website.ace.js @@ -59,8 +59,12 @@ website.ace.ViewOption = openerp.Widget.extend({ template: 'website.ace_view_option', init: function (parent, options) { + var indent = "- "; this.view_id = options.id; this.view_name = options.name; + for (var i = 0; i - -