how to access/print selection base values

Asked by Ferdinand

Hi!
How can I access the list of base values of selection fields which are stored in the database

Example
'account_type': fields.selection([('cash','Cash'), ('check','Check'), ('bank','Bank')], 'Account Type', size=32),
I want to get the python list ['cash','check','bank']

thank you

Question information

Language:
English Edit question
Status:
Answered
For:
Odoo Server (MOVED TO GITHUB) Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
xrg (xrg) said :
#1

On Saturday 01 January 2011, you wrote:
> New question #139851 on OpenObject Server:
> https://answers.launchpad.net/openobject-server/+question/139851
>
> Hi!
> How can I access the list of base values of selection fields which are
> stored in the database
>
> Example
> 'account_type': fields.selection([('cash','Cash'), ('check','Check'),
> ('bank','Bank')], 'Account Type', size=32), I want to get the python list
> ['cash','check','bank']

I can think of two ways:
in SQL, you can list the _used_ values like:
SELECT DISTINCT type FROM account_account; -- which is quick and dirty

or in ORM methods: (bqi syntax without cr, uid)

BQI> orm account.account
BQI account.account> print this
    ....
    (which suggests the following expression: )
BQI account.account> print [x[0] for x in type['selection']]
Result:
[
    "view",
    "other",
    "receivable",
    "payable",
    "liquidity",
    "consolidation",
    "closed"
]

Can you help with this problem?

Provide an answer of your own, or ask Ferdinand for more information if necessary.

To post a message you must log in.