1

I'm trying to make a list of boolean fields required based on a field selection (which is 'the state field').

But, even when I choose Lotissement and check the boolean fields, OpenERP still tells me that the boolean is required, and just doesn't want to save the form.

I tried this code :

def _get_selection(self, cursor, user_id, context=None):
    return (('i', 'Construction Immeuble'),
            ('d', 'Démolition'),
            ('l', 'Lotissement'),
            ('m', 'Morcelement'),
            ('v','Construction Villa')
           ) 

_columns = {
        'state': fields.selection(_get_selection, 'Type de la demande', required=False),
        'active0': fields.boolean('Plan de situation en coordonnées Lambert', 
                          required= False, states={'l':[('required',True)]}),
        'active1': fields.boolean('Plan de masse et terrasse',
                          required= False, states={'l':[('required',True)]}),
        'active2': fields.boolean('Plan des différents niveaux',
                          required= False, states={'l':[('required',True)]}),
        'active3': fields.boolean('Deux coupes',required= False,
                          states={'l':[('required',True)]}),
        'active4': fields.boolean('Plan des façades'),
        'active5': fields.boolean('Demande avec engagement',
                          required= False, states={'l':[('required',True)]}),
        'active6': fields.boolean('Fiche de statistique',
                          required= False, states={'l':[('required',True)]}),
        'active7': fields.boolean('Contrat d’architecte',
                          required= False, states={'l':[('required',True)]}),
        'active8': fields.boolean('Certificat de propriété',
                          required= False, states={'l':[('required',True)]}),
        'active9': fields.boolean('Plan cadastral',
                          required= False, states={'l':[('required',True)]}),
}
Döme
  • 835
  • 11
  • 23
  • 1
    This isn't related to your question directly, but I would like to recommend that you read over [PEP 8: Style Guide for Python Code](http://legacy.python.org/dev/peps/pep-0008/). If other code reads like this of yours, it looks incredibly messy. – nerdwaller May 06 '14 at 15:15
  • i only wrote the intresting part without paying attention to the structure of the code, since the nature of error isn't about syntaxe. The code is well written. – user3540754 May 06 '14 at 15:55
  • did u try this with attrs in xml ? – Senthilnathan May 07 '14 at 09:10
  • Yeah i did. it works only for some of the fields. i'm having trouble writing the right condition. If i want a field to be required only in 3 out of the 5 choices in my (fields.seletion). how should i write it I tried this : – user3540754 May 07 '14 at 10:32
  • Have you tried returning a list instead of a tuple in _get_selection? – miq May 07 '14 at 11:45

1 Answers1

1

Does not make sense, because boolean value is false by default, so the user input always valid (same situation with float or integer).
But in this case, the openERP has a bug, so it expects the True value.

In my opinion, you should use selection type!

Other:
If you want to define required field on a view, you should do it in a xml file when you define the view!
For example:

<!-- Simple field-->
<field name='example' />
<!-- Required field (variations on a theme) -->
<field name='example' required="1" />
<field name='example' attrs="{'required': True}" />
Döme
  • 835
  • 11
  • 23