diff --git a/addons/delivery/stock.py b/addons/delivery/stock.py index c8781244fe0..3d6a552245a 100644 --- a/addons/delivery/stock.py +++ b/addons/delivery/stock.py @@ -53,7 +53,7 @@ class stock_picking(osv.osv): _columns = { 'carrier_id':fields.many2one("delivery.carrier","Carrier"), - 'volume': fields.float('Volume'), + 'volume': fields.float('Volume', copy=False), 'weight': fields.function(_cal_weight, type='float', string='Weight', digits_compute= dp.get_precision('Stock Weight'), multi='_cal_weight', store={ 'stock.picking': (lambda self, cr, uid, ids, c={}: ids, ['move_lines'], 40), @@ -64,8 +64,8 @@ class stock_picking(osv.osv): 'stock.picking': (lambda self, cr, uid, ids, c={}: ids, ['move_lines'], 40), 'stock.move': (_get_picking_line, ['picking_id', 'product_id','product_uom_qty','product_uom'], 40), }), - 'carrier_tracking_ref': fields.char('Carrier Tracking Ref'), - 'number_of_packages': fields.integer('Number of Packages'), + 'carrier_tracking_ref': fields.char('Carrier Tracking Ref', copy=False), + 'number_of_packages': fields.integer('Number of Packages', copy=False), 'weight_uom_id': fields.many2one('product.uom', 'Unit of Measure', required=True,readonly="1",help="Unit of measurement for Weight",), } diff --git a/addons/mail/mail_thread.py b/addons/mail/mail_thread.py index db1ea225713..2fe15d0e53f 100644 --- a/addons/mail/mail_thread.py +++ b/addons/mail/mail_thread.py @@ -1442,18 +1442,34 @@ class mail_thread(osv.AbstractModel): if follower.email == email_address: partner_id = follower.id # second try: check in partners that are also users + # Escape special SQL characters in email_address to avoid invalid matches + email_address = (email_address.replace('\\', '\\\\').replace('%', '\\%').replace('_', '\\_')) + email_brackets = "<%s>" % email_address if not partner_id: - ids = partner_obj.search(cr, SUPERUSER_ID, [ - ('email', 'ilike', email_address), - ('user_ids', '!=', False) - ], limit=1, context=context) + # exact, case-insensitive match + ids = partner_obj.search(cr, SUPERUSER_ID, + [('email', '=ilike', email_address), + ('user_ids', '!=', False)], + limit=1, context=context) + if not ids: + # if no match with addr-spec, attempt substring match within name-addr pair + ids = partner_obj.search(cr, SUPERUSER_ID, + [('email', 'ilike', email_brackets), + ('user_ids', '!=', False)], + limit=1, context=context) if ids: partner_id = ids[0] # third try: check in partners if not partner_id: - ids = partner_obj.search(cr, SUPERUSER_ID, [ - ('email', 'ilike', email_address) - ], limit=1, context=context) + # exact, case-insensitive match + ids = partner_obj.search(cr, SUPERUSER_ID, + [('email', '=ilike', email_address)], + limit=1, context=context) + if not ids: + # if no match with addr-spec, attempt substring match within name-addr pair + ids = partner_obj.search(cr, SUPERUSER_ID, + [('email', 'ilike', email_brackets)], + limit=1, context=context) if ids: partner_id = ids[0] partner_ids.append(partner_id) @@ -1473,13 +1489,15 @@ class mail_thread(osv.AbstractModel): partner_id = partner_ids[idx] partner_info = {'full_name': email_address, 'partner_id': partner_id} result.append(partner_info) - # link mail with this from mail to the new partner id if link_mail and partner_info['partner_id']: + # Escape special SQL characters in email_address to avoid invalid matches + email_address = (email_address.replace('\\', '\\\\').replace('%', '\\%').replace('_', '\\_')) + email_brackets = "<%s>" % email_address message_ids = mail_message_obj.search(cr, SUPERUSER_ID, [ '|', - ('email_from', '=', email_address), - ('email_from', 'ilike', '<%s>' % email_address), + ('email_from', '=ilike', email_address), + ('email_from', 'ilike', email_brackets), ('author_id', '=', False) ], context=context) if message_ids: diff --git a/addons/mail/tests/test_mail_gateway.py b/addons/mail/tests/test_mail_gateway.py index 5de41cc5d7a..cc732b007a2 100644 --- a/addons/mail/tests/test_mail_gateway.py +++ b/addons/mail/tests/test_mail_gateway.py @@ -68,7 +68,7 @@ MAIL_TEMPLATE_PLAINTEXT = """Return-Path: +From: Sylvie Lelitre Subject: {subject} MIME-Version: 1.0 Content-Type: text/plain @@ -525,6 +525,16 @@ class TestMailgateway(TestMail): self.assertEqual(frog_group.message_ids[0].author_id.id, extra_partner_id, 'message_process: email_from -> author_id wrong') + # Do: post a new message with a non-existant email that is a substring of a partner email + format_and_process(MAIL_TEMPLATE, email_from='Not really Lombrik Lubrik ', + subject='Re: news (2)', + msg_id='', + extra='In-Reply-To: <1198923581.41972151344608186760.JavaMail@agrolait.com>\n') + frog_groups = self.mail_group.search(cr, uid, [('name', '=', 'Frogs')]) + frog_group = self.mail_group.browse(cr, uid, frog_groups[0]) + # Test: author must not be set, otherwise the system is confusing different users + self.assertFalse(frog_group.message_ids[0].author_id, 'message_process: email_from -> mismatching author_id') + # Do: post a new message, with a known partner -> duplicate emails -> user frog_group.message_unsubscribe([extra_partner_id]) self.res_users.write(cr, uid, self.user_raoul_id, {'email': 'test_raoul@email.com'}) diff --git a/addons/mrp/mrp.py b/addons/mrp/mrp.py index 5d5bd4b3be6..b9529b31638 100644 --- a/addons/mrp/mrp.py +++ b/addons/mrp/mrp.py @@ -22,7 +22,7 @@ import time import openerp.addons.decimal_precision as dp from openerp.osv import fields, osv, orm -from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT +from openerp.tools import DEFAULT_SERVER_DATE_FORMAT from openerp.tools import float_compare from openerp.tools.translate import _ from openerp import tools, SUPERUSER_ID @@ -217,8 +217,8 @@ class mrp_bom(osv.osv): else: # neither product nor template, makes no sense to search return False - domain = domain + [ '|', ('date_start', '=', False), ('date_start', '<=', time.strftime(DEFAULT_SERVER_DATETIME_FORMAT)), - '|', ('date_stop', '=', False), ('date_stop', '>=', time.strftime(DEFAULT_SERVER_DATETIME_FORMAT))] + domain = domain + [ '|', ('date_start', '=', False), ('date_start', '<=', time.strftime(DEFAULT_SERVER_DATE_FORMAT)), + '|', ('date_stop', '=', False), ('date_stop', '>=', time.strftime(DEFAULT_SERVER_DATE_FORMAT))] # order to prioritize bom with product_id over the one without ids = self.search(cr, uid, domain, order='product_id', context=context) # Search a BoM which has all properties specified, or if you can not find one, you could @@ -277,8 +277,8 @@ class mrp_bom(osv.osv): }) for bom_line_id in bom.bom_line_ids: - if bom_line_id.date_start and bom_line_id.date_start > time.strftime(DEFAULT_SERVER_DATETIME_FORMAT) or \ - bom_line_id.date_stop and bom_line_id.date_stop < time.strftime(DEFAULT_SERVER_DATETIME_FORMAT): + if bom_line_id.date_start and bom_line_id.date_start > time.strftime(DEFAULT_SERVER_DATE_FORMAT) or \ + bom_line_id.date_stop and bom_line_id.date_stop < time.strftime(DEFAULT_SERVER_DATE_FORMAT): continue # all bom_line_id variant values must be in the product if bom_line_id.attribute_value_ids: @@ -662,6 +662,28 @@ class mrp_production(osv.osv): return {'value': result} + def _prepare_lines(self, cr, uid, production, properties=None, context=None): + # search BoM structure and route + bom_obj = self.pool.get('mrp.bom') + uom_obj = self.pool.get('product.uom') + bom_point = production.bom_id + bom_id = production.bom_id.id + if not bom_point: + bom_id = bom_obj._bom_find(cr, uid, product_id=production.product_id.id, properties=properties, context=context) + if bom_id: + bom_point = bom_obj.browse(cr, uid, bom_id) + routing_id = bom_point.routing_id.id or False + self.write(cr, uid, [production.id], {'bom_id': bom_id, 'routing_id': routing_id}) + + if not bom_id: + raise osv.except_osv(_('Error!'), _("Cannot find a bill of material for this product.")) + + # get components and workcenter_lines from BoM structure + factor = uom_obj._compute_qty(cr, uid, production.product_uom.id, production.product_qty, bom_point.product_uom.id) + # product_lines, workcenter_lines + return bom_obj._bom_explode(cr, uid, bom_point, production.product_id, factor / bom_point.product_qty, properties, routing_id=production.routing_id.id, context=context) + + def _action_compute_lines(self, cr, uid, ids, properties=None, context=None): """ Compute product_lines and workcenter_lines from BoM structure @return: product_lines @@ -669,8 +691,6 @@ class mrp_production(osv.osv): if properties is None: properties = [] results = [] - bom_obj = self.pool.get('mrp.bom') - uom_obj = self.pool.get('product.uom') prod_line_obj = self.pool.get('mrp.production.product.line') workcenter_line_obj = self.pool.get('mrp.production.workcenter.line') for production in self.browse(cr, uid, ids, context=context): @@ -678,23 +698,10 @@ class mrp_production(osv.osv): prod_line_obj.unlink(cr, SUPERUSER_ID, [line.id for line in production.product_lines], context=context) #unlink workcenter_lines workcenter_line_obj.unlink(cr, SUPERUSER_ID, [line.id for line in production.workcenter_lines], context=context) - # search BoM structure and route - bom_point = production.bom_id - bom_id = production.bom_id.id - if not bom_point: - bom_id = bom_obj._bom_find(cr, uid, product_id=production.product_id.id, properties=properties, context=context) - if bom_id: - bom_point = bom_obj.browse(cr, uid, bom_id) - routing_id = bom_point.routing_id.id or False - self.write(cr, uid, [production.id], {'bom_id': bom_id, 'routing_id': routing_id}) - - if not bom_id: - raise osv.except_osv(_('Error!'), _("Cannot find a bill of material for this product.")) - # get components and workcenter_lines from BoM structure - factor = uom_obj._compute_qty(cr, uid, production.product_uom.id, production.product_qty, bom_point.product_uom.id) - # product_lines, workcenter_lines - results, results2 = bom_obj._bom_explode(cr, uid, bom_point, production.product_id, factor / bom_point.product_qty, properties, routing_id=production.routing_id.id, context=context) + res = self._prepare_lines(cr, uid, production, properties=properties, context=context) + results = res[0] # product_lines + results2 = res[1] # workcenter_lines # reset product_lines in production order for line in results: diff --git a/addons/point_of_sale/point_of_sale.py b/addons/point_of_sale/point_of_sale.py index c81b8e80e3b..07fead7d3c2 100644 --- a/addons/point_of_sale/point_of_sale.py +++ b/addons/point_of_sale/point_of_sale.py @@ -393,7 +393,7 @@ class pos_session(osv.osv): if not pos_config.journal_id: jid = jobj.default_get(cr, uid, ['journal_id'], context=context)['journal_id'] if jid: - jobj.write(cr, uid, [pos_config.id], {'journal_id': jid}, context=context) + jobj.write(cr, openerp.SUPERUSER_ID, [pos_config.id], {'journal_id': jid}, context=context) else: raise osv.except_osv( _('error!'), _("Unable to open the session. You have to assign a sale journal to your point of sale.")) @@ -407,8 +407,8 @@ class pos_session(osv.osv): if not cashids: cashids = journal_proxy.search(cr, uid, [('journal_user','=',True)], context=context) - journal_proxy.write(cr, uid, cashids, {'journal_user': True}) - jobj.write(cr, uid, [pos_config.id], {'journal_ids': [(6,0, cashids)]}) + journal_proxy.write(cr, openerp.SUPERUSER_ID, cashids, {'journal_user': True}) + jobj.write(cr, openerp.SUPERUSER_ID, [pos_config.id], {'journal_ids': [(6,0, cashids)]}) pos_config = jobj.browse(cr, uid, config_id, context=context) diff --git a/addons/point_of_sale/security/ir.model.access.csv b/addons/point_of_sale/security/ir.model.access.csv index faa14f1d490..d3826c0dd1b 100644 --- a/addons/point_of_sale/security/ir.model.access.csv +++ b/addons/point_of_sale/security/ir.model.access.csv @@ -37,7 +37,7 @@ access_product_template_pos_manager,product.template pos manager,product.model_p access_account_move_line,account.move.line,account.model_account_move_line,group_pos_user,1,1,1,0 access_account_move_line_manager,account.move.line manager,account.model_account_move_line,group_pos_manager,1,1,1,1 access_account_move,account.move,account.model_account_move,group_pos_manager,1,0,0,0 -access_account_journal,account.journal,account.model_account_journal,group_pos_user,1,1,1,0 +access_account_journal,account.journal,account.model_account_journal,group_pos_manager,1,1,1,0 access_account_journal_period_user,account.journal.period user,account.model_account_journal_period,group_pos_user,1,1,1,1 access_account_journal_period_manager,account.journal.period manager,account.model_account_journal_period,group_pos_manager,1,0,0,0 access_account_analytic_line,account.analytic.line,analytic.model_account_analytic_line,group_pos_user,1,1,1,0 @@ -55,7 +55,8 @@ access_res_partner_manager,res.partner manager,base.model_res_partner,group_pos_ access_product_category_manager,product.category manager,product.model_product_category,group_pos_manager,1,1,1,1 access_product_pricelist_manager,product.pricelist manager,product.model_product_pricelist,group_pos_manager,1,0,0,0 access_pos_session_user,pos.session user,model_pos_session,group_pos_user,1,1,1,0 -access_pos_config_user,pos.config user,model_pos_config,group_pos_user,1,1,1,0 +access_pos_config_user,pos.config user,model_pos_config,group_pos_user,1,0,0,0 +access_pos_config_manager,pos.config user,model_pos_config,group_pos_manager,1,1,1,0 access_ir_sequence_manager,ir.sequence manager,base.model_ir_sequence,group_pos_manager,1,1,1,1 access_product_category_pos_manager,pos.category manager,model_pos_category,group_pos_manager,1,1,1,1 access_product_category_pos_user,pos.category user,model_pos_category,group_pos_user,1,0,0,0 diff --git a/addons/purchase_requisition/purchase_requisition.py b/addons/purchase_requisition/purchase_requisition.py index 5af69a65a99..1a51dbfe30f 100644 --- a/addons/purchase_requisition/purchase_requisition.py +++ b/addons/purchase_requisition/purchase_requisition.py @@ -300,7 +300,7 @@ class purchase_requisition_line(osv.osv): _rec_name = 'product_id' _columns = { - 'product_id': fields.many2one('product.product', 'Product'), + 'product_id': fields.many2one('product.product', 'Product', domain=[('purchase_ok', '=', True)]), 'product_uom_id': fields.many2one('product.uom', 'Product Unit of Measure'), 'product_qty': fields.float('Quantity', digits_compute=dp.get_precision('Product Unit of Measure')), 'requisition_id': fields.many2one('purchase.requisition', 'Call for Bids', ondelete='cascade'), diff --git a/addons/warning/warning.py b/addons/warning/warning.py index ee4b2099c98..1834ef9f2cc 100644 --- a/addons/warning/warning.py +++ b/addons/warning/warning.py @@ -76,7 +76,9 @@ class sale_order(osv.osv): warning['title'] = title and title +' & '+ result['warning']['title'] or result['warning']['title'] warning['message'] = message and message + ' ' + result['warning']['message'] or result['warning']['message'] - return {'value': result.get('value',{}), 'warning':warning} + if warning: + result['warning'] = warning + return result class purchase_order(osv.osv): @@ -104,7 +106,9 @@ class purchase_order(osv.osv): warning['title'] = title and title +' & '+ result['warning']['title'] or result['warning']['title'] warning['message'] = message and message + ' ' + result['warning']['message'] or result['warning']['message'] - return {'value': result.get('value',{}), 'warning':warning} + if warning: + result['warning'] = warning + return result @@ -143,7 +147,9 @@ class account_invoice(osv.osv): warning['title'] = title and title +' & '+ result['warning']['title'] or result['warning']['title'] warning['message'] = message and message + ' ' + result['warning']['message'] or result['warning']['message'] - return {'value': result.get('value',{}), 'warning':warning} + if warning: + result['warning'] = warning + return result class stock_picking(osv.osv): @@ -171,8 +177,9 @@ class stock_picking(osv.osv): warning['title'] = title and title +' & '+ result['warning']['title'] or result['warning']['title'] warning['message'] = message and message + ' ' + result['warning']['message'] or result['warning']['message'] - return {'value': result.get('value',{}), 'warning':warning} - + if warning: + result['warning'] = warning + return result class product_product(osv.osv): _inherit = 'product.template' @@ -221,7 +228,9 @@ class sale_order_line(osv.osv): warning['title'] = title and title +' & '+result['warning']['title'] or result['warning']['title'] warning['message'] = message and message +'\n\n'+result['warning']['message'] or result['warning']['message'] - return {'value': result.get('value',{}), 'warning':warning} + if warning: + result['warning'] = warning + return result class purchase_order_line(osv.osv): @@ -252,7 +261,9 @@ class purchase_order_line(osv.osv): warning['title'] = title and title +' & '+result['warning']['title'] or result['warning']['title'] warning['message'] = message and message +'\n\n'+result['warning']['message'] or result['warning']['message'] - return {'value': result.get('value',{}), 'warning':warning} + if warning: + result['warning'] = warning + return result diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index 076154b71ef..1ea2ddb4566 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -3516,7 +3516,7 @@ instance.web.form.FieldMany2One = instance.web.form.AbstractField.extend(instanc reinit_value: function(val) { this.internal_set_value(val); this.floating = false; - if (this.is_started) + if (this.is_started && !this.no_rerender) this.render_value(); }, initialize_field: function() { @@ -3767,7 +3767,7 @@ instance.web.form.FieldMany2One = instance.web.form.AbstractField.extend(instanc } if (! no_recurse) { var dataset = new instance.web.DataSetStatic(this, this.field.relation, self.build_context()); - this.alive(dataset.name_get([self.get("value")])).done(function(data) { + var def = this.alive(dataset.name_get([self.get("value")])).done(function(data) { if (!data[0]) { self.do_warn(_t("Render"), _t("No value found for the field "+self.field.string+" for value "+self.get("value"))); return; @@ -3780,6 +3780,9 @@ instance.web.form.FieldMany2One = instance.web.form.AbstractField.extend(instanc self.display_value["" + self.get("value")] = self.display_value_backup["" + self.get("value")]; self.render_value(true); }); + if (this.view && this.view.render_value_defs){ + this.view.render_value_defs.push(def); + } } }, display_string: function(str) { @@ -4263,7 +4266,7 @@ instance.web.form.FieldOne2Many = instance.web.form.AbstractField.extend({ this.dataset.index = 0; } this.trigger_on_change(); - if (this.is_started) { + if (this.is_started && !this.no_rerender) { return self.reload_current_view(); } else { return $.when(); @@ -4408,12 +4411,19 @@ instance.web.form.One2ManyListView = instance.web.ListView.extend({ return true; } var r; - return _.every(this.records.records, function(record){ + if (_.isEmpty(this.records.records)){ + return true; + } + current_values = {}; + _.each(this.editor.form.fields, function(field){ + field._inhibit_on_change_flag = true; + field.no_rerender = true; + current_values[field.name] = field.get('value'); + }); + var valid = _.every(this.records.records, function(record){ r = record; _.each(self.editor.form.fields, function(field){ - field._inhibit_on_change_flag = true; - field.internal_set_value(r.attributes[field.name]); - field._inhibit_on_change_flag = false; + field.set_value(r.attributes[field.name]); }); return _.every(self.editor.form.fields, function(field){ field.process_modifiers(); @@ -4421,6 +4431,12 @@ instance.web.form.One2ManyListView = instance.web.ListView.extend({ return field.is_valid(); }); }); + _.each(this.editor.form.fields, function(field){ + field.set('value', current_values[field.name]); + field._inhibit_on_change_flag = false; + field.no_rerender = false; + }); + return valid; }, do_add_record: function () { if (this.editable()) { diff --git a/addons/web/static/src/js/view_list_editable.js b/addons/web/static/src/js/view_list_editable.js index 62a0717d374..d8358f69865 100644 --- a/addons/web/static/src/js/view_list_editable.js +++ b/addons/web/static/src/js/view_list_editable.js @@ -231,8 +231,9 @@ this.records.add(record, { at: this.prepends_on_create() ? 0 : null}); } - - return this.ensure_saved().then(function () { + return this.ensure_saved().then(function(){ + return $.when.apply(null, self.editor.form.render_value_defs); + }).then(function () { var $recordRow = self.groups.get_row_for(record); var cells = self.get_cells_for($recordRow); var fields = {}; diff --git a/openerp/addons/base/res/res_users.py b/openerp/addons/base/res/res_users.py index 27efb08e3bf..65a2251dd86 100644 --- a/openerp/addons/base/res/res_users.py +++ b/openerp/addons/base/res/res_users.py @@ -729,6 +729,10 @@ class groups_view(osv.osv): # and introduces the reified group fields # we have to try-catch this, because at first init the view does not exist # but we are already creating some basic groups + if not context or context.get('install_mode'): + # use installation/admin language for translatable names in the view + context = dict(context or {}) + context.update(self.pool['res.users'].context_get(cr, uid)) view = self.pool['ir.model.data'].xmlid_to_object(cr, SUPERUSER_ID, 'base.user_groups_view', context=context) if view and view.exists() and view._name == 'ir.ui.view': xml1, xml2 = [], [] diff --git a/openerp/models.py b/openerp/models.py index f6128f9435f..23c967e07f1 100644 --- a/openerp/models.py +++ b/openerp/models.py @@ -5927,10 +5927,10 @@ def itemgetter_tuple(items): def convert_pgerror_23502(model, fields, info, e): m = re.match(r'^null value in column "(?P\w+)" violates ' r'not-null constraint\n', - str(e)) + tools.ustr(e)) field_name = m and m.group('field') if not m or field_name not in fields: - return {'message': unicode(e)} + return {'message': tools.ustr(e)} message = _(u"Missing required value for the field '%s'.") % field_name field = fields.get(field_name) if field: @@ -5942,10 +5942,10 @@ def convert_pgerror_23502(model, fields, info, e): def convert_pgerror_23505(model, fields, info, e): m = re.match(r'^duplicate key (?P\w+) violates unique constraint', - str(e)) + tools.ustr(e)) field_name = m and m.group('field') if not m or field_name not in fields: - return {'message': unicode(e)} + return {'message': tools.ustr(e)} message = _(u"The value for the field '%s' already exists.") % field_name field = fields.get(field_name) if field: @@ -5958,7 +5958,7 @@ def convert_pgerror_23505(model, fields, info, e): PGERROR_TO_OE = defaultdict( # shape of mapped converters - lambda: (lambda model, fvg, info, pgerror: {'message': unicode(pgerror)}), { + lambda: (lambda model, fvg, info, pgerror: {'message': tools.ustr(pgerror)}), { # not_null_violation '23502': convert_pgerror_23502, # unique constraint error