[FIX] ir_values: fallback when no condition
authorMartin Trigaux <mat@openerp.com>
Thu, 17 Jul 2014 12:22:20 +0000 (14:22 +0200)
committerMartin Trigaux <mat@openerp.com>
Thu, 17 Jul 2014 13:07:58 +0000 (15:07 +0200)
When searching for default values, if we set a condition (e.g. 'type=out_invoice'), fetch also the default values without any condition set. Thanks to the order by clause, the one with a condition have an higher priority than the one without and will not affect existing result.
This fixes default journal/currency on an invoice where the journal is retrieved in the onchange_company_id method (domain is forced). Without this patch only ir.values with a domain set will match, opw 610645

openerp/addons/base/ir/ir_values.py

index bf0128d..953d1aa 100644 (file)
@@ -310,10 +310,10 @@ class ir_values(osv.osv):
                              (SELECT company_id from res_users where id = %%s)
                           )
                       %s
-                   ORDER BY v.user_id, u.company_id"""
+                   ORDER BY v.user_id, u.company_id, v.key2"""
         params = ('default', model, uid, uid)
         if condition:
-            query %= 'AND v.key2 = %s'
+            query %= 'AND (v.key2 = %s OR v.key2 IS NULL)'
             params += (condition[:200],)
         else:
             query %= 'AND v.key2 is NULL'