BenSmith
BenSmith

Reputation: 163

Default values for Binary fields in Odoo

In brief, what is the default value for a binary field in Odoo?

More specifically, I'm trying to construct a computed field based on whether or not certain documents have been included in a record (i.e. a sort of status bar on the number of completed fields in the record).

As a toy example if bin1 and bin2 are binary fields and bool is boolean, then my progress would be computed as

progress = 100.0 * (1*bool + 1*(bin1 is not None) + 1*(bin2 is not None)) / 3

Fortunately, this computation works fine after the record is saved. However, while in Edit mode the progress is shown as if it were 2/3.

This brings be to the question of default values for binary fields or any ideas on how to extract the information about whether of not a binary field is filled or not.

Upvotes: 0

Views: 1326

Answers (1)

simahawk
simahawk

Reputation: 2431

An empty binary field is False a valued one contains base64 encoded string.

So, before you do your computatation you must do something like:

if item.bin_field:
    bin_val = item.bin_field.decode('base64')

Your check if failing because you are doing an "identity comparison" so you are basically saying "is my value identical to None?" instead of checking if is boolean-ly false.

Upvotes: 1

Related Questions