How to change selection fields with filters search in odoo? [Odoo 9]












2















I have created a state on models



state = fields.Selection([
('new', 'New'),
('draft', 'Draft'),
('approved', 'Approved')
],default='new')


I make menuitems that are different for user and admin. But in the admin groups, i get an error after adding filters search.



<record id="view_admin_filter" model="ir.ui.view">
<field name="name">Admin</field>
<field name="model">mymodels</field>
<field name="arch" type="xml">
<search string="Admin">
<filter string="Draft" name="state" domain="[('state','=','draft')]"/>
</search>
</field>
</record>


and



<record id="open_module_tree_admin" model="ir.actions.act_window">
<field name="name">Admin</field>
<field name="res_model">mymodels</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="context">{
"search_default_state": 1,
"default_state": 1}
</field>
<field name="domain"></field>
<field name="view_ids" eval="[(5, 0, 0),
(0, 0, {'view_mode': 'tree', 'view_id': ref('view_admin_tree')}),
(0, 0, {'view_mode': 'form', 'view_id': ref('view_admin_form')})]"/>
<field name="search_view_id" ref="view_admin_filter"/>
<field name="help" type="html">
<p class="oe_view_nocontent_create">
Click to create.
</p>
</field>
</record>


I found an error like this



ValueError: Wrong value for mail.mail.state: 1


I have tried to replace it like this



"search_default_state": 'draft',
"default_state": 'draft'}


but it still doesn't work and getting error



ValueError: Wrong value for mail.mail.state: u'draft'


how should I fix it?










share|improve this question

























  • Can you put the definition of your model. _name, _inherit and when do you get the error exactly when you try to apply the filter, when you open view or click on create?

    – EasyOdoo
    Nov 23 '18 at 7:13













  • @Cherif in my model _name = "mymodels", _inherit = ['mail.thread']. I get an error when create.

    – Kenji Reita Moe
    Nov 23 '18 at 8:43
















2















I have created a state on models



state = fields.Selection([
('new', 'New'),
('draft', 'Draft'),
('approved', 'Approved')
],default='new')


I make menuitems that are different for user and admin. But in the admin groups, i get an error after adding filters search.



<record id="view_admin_filter" model="ir.ui.view">
<field name="name">Admin</field>
<field name="model">mymodels</field>
<field name="arch" type="xml">
<search string="Admin">
<filter string="Draft" name="state" domain="[('state','=','draft')]"/>
</search>
</field>
</record>


and



<record id="open_module_tree_admin" model="ir.actions.act_window">
<field name="name">Admin</field>
<field name="res_model">mymodels</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="context">{
"search_default_state": 1,
"default_state": 1}
</field>
<field name="domain"></field>
<field name="view_ids" eval="[(5, 0, 0),
(0, 0, {'view_mode': 'tree', 'view_id': ref('view_admin_tree')}),
(0, 0, {'view_mode': 'form', 'view_id': ref('view_admin_form')})]"/>
<field name="search_view_id" ref="view_admin_filter"/>
<field name="help" type="html">
<p class="oe_view_nocontent_create">
Click to create.
</p>
</field>
</record>


I found an error like this



ValueError: Wrong value for mail.mail.state: 1


I have tried to replace it like this



"search_default_state": 'draft',
"default_state": 'draft'}


but it still doesn't work and getting error



ValueError: Wrong value for mail.mail.state: u'draft'


how should I fix it?










share|improve this question

























  • Can you put the definition of your model. _name, _inherit and when do you get the error exactly when you try to apply the filter, when you open view or click on create?

    – EasyOdoo
    Nov 23 '18 at 7:13













  • @Cherif in my model _name = "mymodels", _inherit = ['mail.thread']. I get an error when create.

    – Kenji Reita Moe
    Nov 23 '18 at 8:43














2












2








2








I have created a state on models



state = fields.Selection([
('new', 'New'),
('draft', 'Draft'),
('approved', 'Approved')
],default='new')


I make menuitems that are different for user and admin. But in the admin groups, i get an error after adding filters search.



<record id="view_admin_filter" model="ir.ui.view">
<field name="name">Admin</field>
<field name="model">mymodels</field>
<field name="arch" type="xml">
<search string="Admin">
<filter string="Draft" name="state" domain="[('state','=','draft')]"/>
</search>
</field>
</record>


and



<record id="open_module_tree_admin" model="ir.actions.act_window">
<field name="name">Admin</field>
<field name="res_model">mymodels</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="context">{
"search_default_state": 1,
"default_state": 1}
</field>
<field name="domain"></field>
<field name="view_ids" eval="[(5, 0, 0),
(0, 0, {'view_mode': 'tree', 'view_id': ref('view_admin_tree')}),
(0, 0, {'view_mode': 'form', 'view_id': ref('view_admin_form')})]"/>
<field name="search_view_id" ref="view_admin_filter"/>
<field name="help" type="html">
<p class="oe_view_nocontent_create">
Click to create.
</p>
</field>
</record>


I found an error like this



ValueError: Wrong value for mail.mail.state: 1


I have tried to replace it like this



"search_default_state": 'draft',
"default_state": 'draft'}


but it still doesn't work and getting error



ValueError: Wrong value for mail.mail.state: u'draft'


how should I fix it?










share|improve this question
















I have created a state on models



state = fields.Selection([
('new', 'New'),
('draft', 'Draft'),
('approved', 'Approved')
],default='new')


I make menuitems that are different for user and admin. But in the admin groups, i get an error after adding filters search.



<record id="view_admin_filter" model="ir.ui.view">
<field name="name">Admin</field>
<field name="model">mymodels</field>
<field name="arch" type="xml">
<search string="Admin">
<filter string="Draft" name="state" domain="[('state','=','draft')]"/>
</search>
</field>
</record>


and



<record id="open_module_tree_admin" model="ir.actions.act_window">
<field name="name">Admin</field>
<field name="res_model">mymodels</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="context">{
"search_default_state": 1,
"default_state": 1}
</field>
<field name="domain"></field>
<field name="view_ids" eval="[(5, 0, 0),
(0, 0, {'view_mode': 'tree', 'view_id': ref('view_admin_tree')}),
(0, 0, {'view_mode': 'form', 'view_id': ref('view_admin_form')})]"/>
<field name="search_view_id" ref="view_admin_filter"/>
<field name="help" type="html">
<p class="oe_view_nocontent_create">
Click to create.
</p>
</field>
</record>


I found an error like this



ValueError: Wrong value for mail.mail.state: 1


I have tried to replace it like this



"search_default_state": 'draft',
"default_state": 'draft'}


but it still doesn't work and getting error



ValueError: Wrong value for mail.mail.state: u'draft'


how should I fix it?







odoo xml-rpc odoo-9






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 '18 at 0:06







Kenji Reita Moe

















asked Nov 22 '18 at 19:16









Kenji Reita MoeKenji Reita Moe

133




133













  • Can you put the definition of your model. _name, _inherit and when do you get the error exactly when you try to apply the filter, when you open view or click on create?

    – EasyOdoo
    Nov 23 '18 at 7:13













  • @Cherif in my model _name = "mymodels", _inherit = ['mail.thread']. I get an error when create.

    – Kenji Reita Moe
    Nov 23 '18 at 8:43



















  • Can you put the definition of your model. _name, _inherit and when do you get the error exactly when you try to apply the filter, when you open view or click on create?

    – EasyOdoo
    Nov 23 '18 at 7:13













  • @Cherif in my model _name = "mymodels", _inherit = ['mail.thread']. I get an error when create.

    – Kenji Reita Moe
    Nov 23 '18 at 8:43

















Can you put the definition of your model. _name, _inherit and when do you get the error exactly when you try to apply the filter, when you open view or click on create?

– EasyOdoo
Nov 23 '18 at 7:13







Can you put the definition of your model. _name, _inherit and when do you get the error exactly when you try to apply the filter, when you open view or click on create?

– EasyOdoo
Nov 23 '18 at 7:13















@Cherif in my model _name = "mymodels", _inherit = ['mail.thread']. I get an error when create.

– Kenji Reita Moe
Nov 23 '18 at 8:43





@Cherif in my model _name = "mymodels", _inherit = ['mail.thread']. I get an error when create.

– Kenji Reita Moe
Nov 23 '18 at 8:43












1 Answer
1






active

oldest

votes


















1














From what you said you are setting a default value for state some where in your code
with a value that is not in selection.



like for example when you did this:



   "default_state": 1 


This will cause this error to happen because I'm sure that 1 is not valid value
instead doing this is correct.



  "default_state": 'draft'


But only if your selection has this value 'draft'.



One thing you should know in XML removing the code of the context from the action
definition will not remove it from the data base (you will keep having the same problem).



To fix this problem remove this default values from your code then do it again step by step
and make sure you upgrade the moduel and restart the server.



    <record id="open_module_tree_admin" model="ir.actions.act_window">
<field name="name">Admin</field>
<field name="res_model">mymodels</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="context">{}</field> <!-- this will update the context to {} -->
.....
....


and check your python code for default value or onchange event make sure your not setting
the state field to a wrong value.



  fields.Selection(.... default='draft')


Hope this helps you



And for your filter don't give them names like your fields names



  <filter string="Draft" name="draft_state" domain="[('state','=','draft')]"/>


This way you can apply this filter in the context of the action like this:*



  {'search_default_draft_state': 1}


I think it's safer.






share|improve this answer
























  • I changed fields name from filters. This is worked. Thanks for your suggest code.

    – Kenji Reita Moe
    Nov 23 '18 at 14:50











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53436963%2fhow-to-change-selection-fields-with-filters-search-in-odoo-odoo-9%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














From what you said you are setting a default value for state some where in your code
with a value that is not in selection.



like for example when you did this:



   "default_state": 1 


This will cause this error to happen because I'm sure that 1 is not valid value
instead doing this is correct.



  "default_state": 'draft'


But only if your selection has this value 'draft'.



One thing you should know in XML removing the code of the context from the action
definition will not remove it from the data base (you will keep having the same problem).



To fix this problem remove this default values from your code then do it again step by step
and make sure you upgrade the moduel and restart the server.



    <record id="open_module_tree_admin" model="ir.actions.act_window">
<field name="name">Admin</field>
<field name="res_model">mymodels</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="context">{}</field> <!-- this will update the context to {} -->
.....
....


and check your python code for default value or onchange event make sure your not setting
the state field to a wrong value.



  fields.Selection(.... default='draft')


Hope this helps you



And for your filter don't give them names like your fields names



  <filter string="Draft" name="draft_state" domain="[('state','=','draft')]"/>


This way you can apply this filter in the context of the action like this:*



  {'search_default_draft_state': 1}


I think it's safer.






share|improve this answer
























  • I changed fields name from filters. This is worked. Thanks for your suggest code.

    – Kenji Reita Moe
    Nov 23 '18 at 14:50
















1














From what you said you are setting a default value for state some where in your code
with a value that is not in selection.



like for example when you did this:



   "default_state": 1 


This will cause this error to happen because I'm sure that 1 is not valid value
instead doing this is correct.



  "default_state": 'draft'


But only if your selection has this value 'draft'.



One thing you should know in XML removing the code of the context from the action
definition will not remove it from the data base (you will keep having the same problem).



To fix this problem remove this default values from your code then do it again step by step
and make sure you upgrade the moduel and restart the server.



    <record id="open_module_tree_admin" model="ir.actions.act_window">
<field name="name">Admin</field>
<field name="res_model">mymodels</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="context">{}</field> <!-- this will update the context to {} -->
.....
....


and check your python code for default value or onchange event make sure your not setting
the state field to a wrong value.



  fields.Selection(.... default='draft')


Hope this helps you



And for your filter don't give them names like your fields names



  <filter string="Draft" name="draft_state" domain="[('state','=','draft')]"/>


This way you can apply this filter in the context of the action like this:*



  {'search_default_draft_state': 1}


I think it's safer.






share|improve this answer
























  • I changed fields name from filters. This is worked. Thanks for your suggest code.

    – Kenji Reita Moe
    Nov 23 '18 at 14:50














1












1








1







From what you said you are setting a default value for state some where in your code
with a value that is not in selection.



like for example when you did this:



   "default_state": 1 


This will cause this error to happen because I'm sure that 1 is not valid value
instead doing this is correct.



  "default_state": 'draft'


But only if your selection has this value 'draft'.



One thing you should know in XML removing the code of the context from the action
definition will not remove it from the data base (you will keep having the same problem).



To fix this problem remove this default values from your code then do it again step by step
and make sure you upgrade the moduel and restart the server.



    <record id="open_module_tree_admin" model="ir.actions.act_window">
<field name="name">Admin</field>
<field name="res_model">mymodels</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="context">{}</field> <!-- this will update the context to {} -->
.....
....


and check your python code for default value or onchange event make sure your not setting
the state field to a wrong value.



  fields.Selection(.... default='draft')


Hope this helps you



And for your filter don't give them names like your fields names



  <filter string="Draft" name="draft_state" domain="[('state','=','draft')]"/>


This way you can apply this filter in the context of the action like this:*



  {'search_default_draft_state': 1}


I think it's safer.






share|improve this answer













From what you said you are setting a default value for state some where in your code
with a value that is not in selection.



like for example when you did this:



   "default_state": 1 


This will cause this error to happen because I'm sure that 1 is not valid value
instead doing this is correct.



  "default_state": 'draft'


But only if your selection has this value 'draft'.



One thing you should know in XML removing the code of the context from the action
definition will not remove it from the data base (you will keep having the same problem).



To fix this problem remove this default values from your code then do it again step by step
and make sure you upgrade the moduel and restart the server.



    <record id="open_module_tree_admin" model="ir.actions.act_window">
<field name="name">Admin</field>
<field name="res_model">mymodels</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="context">{}</field> <!-- this will update the context to {} -->
.....
....


and check your python code for default value or onchange event make sure your not setting
the state field to a wrong value.



  fields.Selection(.... default='draft')


Hope this helps you



And for your filter don't give them names like your fields names



  <filter string="Draft" name="draft_state" domain="[('state','=','draft')]"/>


This way you can apply this filter in the context of the action like this:*



  {'search_default_draft_state': 1}


I think it's safer.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 23 '18 at 11:03









EasyOdooEasyOdoo

7,2292923




7,2292923













  • I changed fields name from filters. This is worked. Thanks for your suggest code.

    – Kenji Reita Moe
    Nov 23 '18 at 14:50



















  • I changed fields name from filters. This is worked. Thanks for your suggest code.

    – Kenji Reita Moe
    Nov 23 '18 at 14:50

















I changed fields name from filters. This is worked. Thanks for your suggest code.

– Kenji Reita Moe
Nov 23 '18 at 14:50





I changed fields name from filters. This is worked. Thanks for your suggest code.

– Kenji Reita Moe
Nov 23 '18 at 14:50




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53436963%2fhow-to-change-selection-fields-with-filters-search-in-odoo-odoo-9%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Xamarin.form Move up view when keyboard appear

Post-Redirect-Get with Spring WebFlux and Thymeleaf

Anylogic : not able to use stopDelay()