From 1551c1a4100da28e217f54e8a05d1ff4f2547b17 Mon Sep 17 00:00:00 2001
From: Arnaud Fontaine <arnaud.fontaine@nexedi.com>
Date: Mon, 27 Jan 2014 15:24:56 +0900
Subject: [PATCH] ERP5Form: Returned field default value for ListBox was not
 consistent with non-ListBox field.

So, Relation Fields in ListBox were ignored during validation as the input
value is compared with the current (default), thus the field could not be
cleared as the value from the actual object was not retrieved at all.
---
 product/ERP5Form/Form.py       | 8 +++++---
 product/ERP5Form/ProxyField.py | 3 ++-
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/product/ERP5Form/Form.py b/product/ERP5Form/Form.py
index fdeb1ed097..7d4ca9dce4 100644
--- a/product/ERP5Form/Form.py
+++ b/product/ERP5Form/Form.py
@@ -226,13 +226,14 @@ class OverrideValue(StaticValue):
 
 class DefaultValue(StaticValue):
   def __init__(self, field_id, value):
-    self.key = field_id[3:]
+    self.key = field_id.split('_', 1)[1]
     self.value = value
 
   def __call__(self, field, id, **kw):
+    REQUEST = get_request()
     try:
       form = field.aq_parent
-      ob = getattr(form, 'aq_parent', None)
+      ob = REQUEST.get('cell', getattr(form, 'aq_parent', None))
       value = self.value
       try:
         if value not in (None, ''):
@@ -308,7 +309,8 @@ def getFieldValue(self, field, id, **kw):
 
   field_id = field.id
 
-  if id == 'default' and field_id.startswith('my_'):
+  if id == 'default' and (field_id.startswith('my_') or
+                          field_id.startswith('listbox_')):
     if field.meta_type == 'ProxyField' and \
         field.getRecursiveTemplateField().meta_type == 'CheckBoxField' or \
         self.meta_type == 'CheckBoxField':
diff --git a/product/ERP5Form/ProxyField.py b/product/ERP5Form/ProxyField.py
index bf2d05a0b9..abd07f5885 100644
--- a/product/ERP5Form/ProxyField.py
+++ b/product/ERP5Form/ProxyField.py
@@ -683,7 +683,8 @@ class ProxyField(ZMIField):
     value = copyMethod(value)
     cacheable = isCacheable(value)
 
-    if id == 'default' and field_id.startswith('my_'):
+    if id == 'default' and (field_id.startswith('my_') or
+                            field_id.startswith('listbox_')):
       # XXX far from object-oriented programming
       if template_field.meta_type == 'CheckBoxField':
         return DefaultCheckBoxValue(field_id, value), cacheable
-- 
2.30.9