user_id = res[0]
elif conf['create_user']:
_logger.debug("Creating new OpenERP user \"%s\" from LDAP" % login)
- user_obj = self.pool.get('res.users')
+ user_obj = self.pool['res.users']
values = self.map_ldap_attributes(cr, uid, conf, login, ldap_entry)
if conf['user']:
+ values['active'] = True
user_id = user_obj.copy(cr, SUPERUSER_ID, conf['user'],
- default={'active': True})
- user_obj.write(cr, SUPERUSER_ID, user_id, values)
+ default=values)
else:
user_id = user_obj.create(cr, SUPERUSER_ID, values)
return user_id
user_id = super(users, self).login(db, login, password)
if user_id:
return user_id
- cr = self.pool.db.cursor()
- ldap_obj = self.pool['res.company.ldap']
- for conf in ldap_obj.get_ldap_dicts(cr):
- entry = ldap_obj.authenticate(conf, login, password)
- if entry:
- user_id = ldap_obj.get_or_create_user(
- cr, SUPERUSER_ID, conf, login, entry)
- if user_id:
- cr.execute("""UPDATE res_users
- SET login_date=now() AT TIME ZONE 'UTC'
- WHERE login=%s""",
- (tools.ustr(login),))
- cr.commit()
- break
- cr.close()
- return user_id
+ registry = RegistryManager.get(db)
+ with registry.cursor() as cr:
+ ldap_obj = registry.get('res.company.ldap')
+ for conf in ldap_obj.get_ldap_dicts(cr):
+ entry = ldap_obj.authenticate(conf, login, password)
+ if entry:
+ user_id = ldap_obj.get_or_create_user(
+ cr, SUPERUSER_ID, conf, login, entry)
+ if user_id:
+ break
+ return user_id
- def check(self, db, uid, passwd):
+ def check_credentials(self, cr, uid, password):
try:
- return super(users,self).check(db, uid, passwd)
+ super(users, self).check_credentials(cr, uid, password)
except openerp.exceptions.AccessDenied:
- pass
- cr = self.pool.db.cursor()
- cr.execute('SELECT login FROM res_users WHERE id=%s AND active=TRUE',
- (int(uid),))
- res = cr.fetchone()
- if res:
- ldap_obj = self.pool['res.company.ldap']
- for conf in ldap_obj.get_ldap_dicts(cr):
- if ldap_obj.authenticate(conf, res[0], passwd):
- self._uid_cache.setdefault(db, {})[uid] = passwd
- cr.close()
- return True
- cr.close()
- raise openerp.exceptions.AccessDenied()
+ cr.execute('SELECT login FROM res_users WHERE id=%s AND active=TRUE',
+ (int(uid),))
+ res = cr.fetchone()
+ if res:
+ ldap_obj = self.pool['res.company.ldap']
+ for conf in ldap_obj.get_ldap_dicts(cr):
+ if ldap_obj.authenticate(conf, res[0], password):
+ return
+ raise
-users()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
attachments.append((attach.datas_fname, base64.b64decode(attach.datas)))
# specific behavior to customize the send email for notified partners
email_list = []
- if recipient_ids:
- for partner in self.pool.get('res.partner').browse(cr, SUPERUSER_ID, recipient_ids, context=context):
- email_list.append(self.send_get_email_dict(cr, uid, mail, partner=partner, context=context))
- else:
+ if mail.email_to:
email_list.append(self.send_get_email_dict(cr, uid, mail, context=context))
+ for partner in mail.recipient_ids:
+ email_list.append(self.send_get_email_dict(cr, uid, mail, partner=partner, context=context))
# build an RFC2822 email.message.Message object and send it without queuing
+ res = None
for email in email_list:
msg = ir_mail_server.build_email(
email_from = mail.email_from,
from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT, DATETIME_FORMATS_MAP
from openerp.tools import float_compare
from openerp.tools.translate import _
-from openerp import netsvc
from openerp import tools
+ from openerp import SUPERUSER_ID
#----------------------------------------------------------
# Work Centers
return result
def _src_id_default(self, cr, uid, ids, context=None):
- src_location_id = self.pool.get('ir.model.data').get_object(cr, uid, 'stock', 'stock_location_stock', context=context)
- return src_location_id.id
+ try:
+ location_model, location_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'stock', 'stock_location_stock')
+ self.pool.get('stock.location').check_access_rule(cr, uid, [location_id], 'read', context=context)
+ except (orm.except_orm, ValueError):
+ location_id = False
+ return location_id
def _dest_id_default(self, cr, uid, ids, context=None):
- dest_location_id = self.pool.get('ir.model.data').get_object(cr, uid, 'stock', 'stock_location_stock', context=context)
- return dest_location_id.id
+ try:
+ location_model, location_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'stock', 'stock_location_stock')
+ self.pool.get('stock.location').check_access_rule(cr, uid, [location_id], 'read', context=context)
+ except (orm.except_orm, ValueError):
+ location_id = False
+ return location_id
+ def _get_progress(self, cr, uid, ids, name, arg, context=None):
+ """ Return product quantity percentage """
+ result = dict.fromkeys(ids, 100)
+ for mrp_production in self.browse(cr, uid, ids, context=context):
+ if mrp_production.product_qty:
+ done = 0.0
+ for move in mrp_production.move_created_ids2:
+ if not move.scrapped and move.product_id == mrp_production.product_id:
+ done += move.product_qty
+ result[mrp_production.id] = done / mrp_production.product_qty * 100
+ return result
+
_columns = {
'name': fields.char('Reference', size=64, required=True, readonly=True, states={'draft': [('readonly', False)]}),
'origin': fields.char('Source Document', size=64, readonly=True, states={'draft': [('readonly', False)]},