[MERGE] base, report: several bugfixes (see bug links)
authorYSA (OpenERP) <ysa@openerp.com>
Wed, 29 Dec 2010 20:12:50 +0000 (21:12 +0100)
committerOlivier Dony <odo@openerp.com>
Wed, 29 Dec 2010 20:12:50 +0000 (21:12 +0100)
bzr revid: odo@openerp.com-20101229201250-q7le63xa3rbsce6o

bin/addons/base/base_demo.xml
bin/addons/base/base_update.xml
bin/addons/base/res/res_config.xml
bin/addons/base/res/res_user.py
bin/addons/base/test/test_context.xml
bin/report/render/rml2pdf/utils.py

index 7779171..73f6fa4 100644 (file)
@@ -1,14 +1,27 @@
 <?xml version="1.0" encoding="utf-8"?>
 <openerp>
     <data noupdate="1">
+
+        <record id="demo_address" model="res.partner.address">
+            <field name="name">Fabien Dupont</field>
+            <field name="street">Chaussee de Namur</field>
+            <field name="zip">1367</field>
+            <field name="city">Gerompont</field>
+            <field name="phone">(+32).81.81.37.00</field>
+            <field name="type">default</field>
+            <field model="res.country" name="country_id" ref="be"/>
+            <!-- Company ID will be set later -->
+            <field name="company_id" eval="None"/>
+        </record>
+
         <record id="user_demo" model="res.users">
             <field name="login">demo</field>
             <field name="password">demo</field>
             <field name="name">Demo User</field>
             <field name="signature">Mr Demo</field>
-            <field name="address_id" ref="main_address"/>
+            <field name="address_id" ref="demo_address"/>
             <field name="company_id" ref="main_company"/>
-            <field name="groups_id" eval="[(6,0,[ref('base.group_user')])]"/> 
+            <field name="groups_id" eval="[(6,0,[ref('base.group_user')])]"/>
         </record>
     </data>
 </openerp>
index 2448306..411d67e 100644 (file)
     Users
     ======================
     -->
+
+        <record id="view_change_user_password_form" model="ir.ui.view">
+            <field name="name">change.user.password</field>
+            <field name="model">change.user.password</field>
+            <field name="type">form</field>
+            <field name="arch" type="xml">
+                <form string="Change Password">
+                    <field name="current_password" password="True" readonly="0" colspan="4"/>
+                    <field name="new_password" password="True" readonly="0" colspan="4"/>
+                    <field name="confirm_password" password="True" readonly="0" colspan="4"/>
+                    <label colspan="1" string=""/>
+                    <label colspan="3" string="You must logout and login again after changing your password."/>
+                    <separator colspan="4" />
+                    <label align="0.0" colspan="2" string=""/>
+                    <button colspan="1" icon="gtk-cancel" special="cancel" string="Cancel"/>
+                    <button colspan="1" icon="gtk-ok" name="change_password" string="Change" type="object"/>
+                </form>
+            </field>
+        </record>
+
+        <record id="action_view_change_password_form" model="ir.actions.act_window">
+            <field name="name">Change Password</field>
+            <field name="type">ir.actions.act_window</field>
+            <field name="res_model">change.user.password</field>
+            <field name="view_type">form</field>
+            <field name="view_mode">form</field>
+            <field name="target">new</field>
+        </record>
+
         <record id="view_users_form_simple_modif" model="ir.ui.view">
             <field name="name">res.users.form.modif</field>
             <field name="model">res.users</field>
                             <newline/>
                         </page>
                          <page string="Preferences">
-                            <field name="password" password="True" readonly="0" />
                             <field name="context_lang" completion="1" readonly="0"/>
-                            <label string="" colspan="1"/>
-                            <label colspan="3" string="You must logout and login again after changing your password."/>
                             <field name="context_tz" completion="1" readonly="0"/>
                             <field name="menu_tips" colspan="2" readonly="0"/>
+                            <label string="" colspan="1"/>
+                            <button name="%(action_view_change_password_form)d" string="Change Password" type="action" icon="gtk-execute"/>
                             <separator string="Email &amp; Signature" colspan="4"/>
                             <group colspan="4"><field name="user_email" widget="email" readonly="0"/></group>
                             <field colspan="4" name="signature" readonly="0" nolabel="1"/>
index 24728d0..56432f5 100644 (file)
@@ -7,7 +7,7 @@
       <field name="arch" type="xml">
        <form>
          <group colspan="4" col="8">
-           <group colspan="1" width="220" height="250">
+           <group colspan="1" width="220">
              <field name="config_logo" widget="image" width="220" height="130" nolabel="1"/>
              <newline/>
              <label align="0.0" string="description" width="200" colspan="2"/>
index e7f881c..c8aa83f 100644 (file)
@@ -448,7 +448,7 @@ class users(osv.osv):
             return True
         cr = pooler.get_db(db).cursor()
         try:
-            cr.execute('SELECT COUNT(1) FROM res_users WHERE id=%s AND password=%s AND active=%s', 
+            cr.execute('SELECT COUNT(1) FROM res_users WHERE id=%s AND password=%s AND active=%s',
                         (int(uid), passwd, True))
             res = cr.fetchone()[0]
             if not bool(res):
@@ -547,7 +547,7 @@ class groups2(osv.osv): ##FIXME: Is there a reason to inherit this object ?
             if len(user_names) >= 5:
                 user_names = user_names[:5]
                 user_names += '...'
-            raise osv.except_osv(_('Warning !'), 
+            raise osv.except_osv(_('Warning !'),
                         _('Group(s) cannot be deleted, because some user(s) still belong to them: %s !') % \
                             ', '.join(user_names))
         return super(groups2, self).unlink(cr, uid, ids, context=context)
@@ -574,5 +574,39 @@ class res_config_view(osv.osv_memory):
 
 res_config_view()
 
+class change_user_password(osv.osv_memory):
+    _name = 'change.user.password'
+    _columns = {
+        'current_password':fields.char('Current Password', size=64, required=True, help="Enter your current password."),
+        'new_password': fields.char('New Password', size=64, required=True, help="Enter the new password."),
+        'confirm_password': fields.char('Confirm Password', size=64, required=True, help="Enter the new password again for confirmation."),
+    }
+    _defaults={
+        'current_password' : '',
+        'new_password' : '',
+        'confirm_password' : '',
+    }
+
+    def change_password(self, cr, uid, ids, context=None):
+        for form_id in ids:
+            password_rec = self.browse(cr, uid, form_id, context)
+            if password_rec.new_password != password_rec.confirm_password:
+                raise osv.except_osv(_('Error !'), _('The new and confirmation passwords do not match, please double-check them.'))
+
+            # Validate current password without reading it from database,
+            # as it could be stored differently (LDAP, encrypted/hashed, etc.)
+            is_correct_password = False
+            try:
+                user_obj = self.pool.get('res.users')
+                is_correct_password = user_obj.check(cr.dbname, uid, password_rec.current_password)
+            except Exception:
+                pass
+            if not is_correct_password:
+                raise osv.except_osv(_('Error !'), _('The current password does not match, please double-check it.'))
+            user_obj.write(cr, uid, [uid], {'password': password_rec.new_password}, context=context)
+        return {}
+
+change_user_password()
+
 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
 
index 4475164..d308fc3 100644 (file)
@@ -6,15 +6,15 @@
 <!--            model="res.currency"-->
 <!--            id="INR"-->
 <!--            string="Indian rupee rate in 2009">-->
-            <!-- date specified in data element's context --> 
+            <!-- date specified in data element's context -->
 <!--            <test expr="str(rate)">65.8287</test>-->
 <!--        </assert> -->
-        <assert 
+        <assert
             model="res.currency"
             id="INR"
             string="Indian rupee rate in 2002"
             context="{'date': '2010-06-01'}">
-            <test expr="str(rate)">59.9739</test>
+            <test expr="rate_ids and str(rate_ids[0].rate)">59.9739</test>
         </assert>
     </data>
 </openerp>
index 6f8616d..e631fcd 100644 (file)
@@ -131,7 +131,7 @@ def _process_text(self, txt):
                     pass
                 if isinstance(txt, basestring):
                     result += str2xml(txt)
-                elif (txt is not None) and (txt is not False):
+                elif txt and (txt is not None) and (txt is not False):
                     result += ustr(txt)
         return result