Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

How to fill in the default value by view, rather than models? [Closed]

By
Gavin Yap
on 7/22/15, 1:57 AM 560 views

I've extended  the partner model as below.

from openerp import models, fields, api, exceptions
class Partner(models.Model):
_name = 'res.partner'
_inherit = 'res.partner'
@api.model
def _get_partner_category(self):
id = self.env['res.partner.category'].search([['name', '=', 'Registrant']]).id
return [(6,0,[id])]
national_id = fields.Char(string="National ID")
_defaults = {
'category_id': _get_partner_category,
}


As above, the code has made category_id and set the default tag to "Registrant". 


However, this affect other modules that uses the res.partner model.

Can I set defaults on my views instead via the model?


0
Gavin Yap
On 7/23/15, 3:02 AM

Solution

Create a data xml that has a tag that I want.

        <record model="res.partner.category" id="registrant_tag">
<field name="name">Registrant</field>
</record>


Now on my window action reference the to the tag with an eval option.

 <record model="ir.actions.act_window" id="registrant_list_action">
<field name="name">Registrant</field>
<field name="res_model">res.partner</field>
<field name="domain">[('category_id.name','ilike','Registrant')]</field>
<field name="context" eval="{'default_category_id': [(6,0,[ref('warranty.registrant_tag')])] }"/>
<field name="view_type">form</field>
<field name="view_mode">kanban,tree,form</field>
<field name="help" type="html">
<p class="oe_view_nocontent_create">Add a registrant
</p>
</field>
</record>


4

Emipro Technologies Pvt. Ltd.

--Emipro Technologies Pvt. Ltd.--
Tiny ERP Pvt Ltd
http://www.odoo.com
5995
| 6 7 8
Rajkot, India
--Emipro Technologies Pvt. Ltd.--

Being an emerging leader in IT market since 2011, Emipro Technologies Pvt. Ltd. has been providing a wide range of business solutions in Odoo & Magento. We are pleased to have a large pool of contented customers with our meticulous work in the domain of ERP & e-Commerce. A ray of relief & satisfaction to  our customers heart by our successful deployment in their organization, purely represents our success in Odoo platform. Hence, we take pride for being an Odoo partner with a vision of expanding our strategic alliances with our customers to offer them high value-added, trustworthy & cost effective solutions.

 

Since establishment, our business has span across 11 countries of the world. Our customers are companies of all sizes ranging from start-ups to large enterprises, who realize that they need a professional business solutions to generate revenue streams, establish proper communication channels or streamline business operations. Standing with strong determination of customer satisfaction, observing each minute detail of their business processes, providing proper guidance and moving forth to develop product accordingly adds our value and reliability among our customers. 

 

We are blessed with efficient, passionate & eclectic young developers who have come across almost all kinds of business profiles, working with full dedication, applying creativity & new features in existing modules and completing customer's projects successfully on predefined target. Our in-depth knowledge while giving business solutions in Odoo allows us to offer following services to our customers :

 

  • Consulting
  • Installation, Configuration & Customization
  • Training & Support
  • Maintenance
  • Upgradation
  • Documentation
  • Crafting community modules
  • Drafting videos on demand
  • Smart Apps development

We will be :) to welcome you @ www.emiprotechnologies.com to solve any kind of your business needs around Odoo. However we are just an inch away from you by email info@emiprotechnologies.com or a tweet to @EmiproTech

Emipro Technologies Pvt. Ltd.
On 7/22/15, 2:37 AM

Hello,

You can't set default value in View wise.  However you can set default values in Window Action.

For example, 

1. Go to Window Action menu, find "Countries" action and open it.

2. In context field, set "{'default_name':'India'}" 

3. Go to Countries menu Sales >> Configuration >> Address Book >> Localization >> Countries and open it. Try to create new record. You will see name "India" by default.

Tip : In order to set default from front end, You need to add your exact field name followed by "default_" prefix in Window Action's context field.

 Hope this helps,

It works partially. In the context field, I set "{'default_category_id':'[(6,0,[18])]'}" where'18' is the "Registrant" index. how do I assigned a function value to it? I tried "{'default_category_id': _get_partner_category}" it doesnt work.

Gavin Yap
on 7/22/15, 3:23 AM

Thanks for the tip, I have found my solution. :)

Gavin Yap
on 7/23/15, 2:58 AM
0

Ahmed M.Elmubarak

--Ahmed M.Elmubarak--
2988
| 5 3 5
Sudan
--Ahmed M.Elmubarak--


Ahmed M.Elmubarak
On 7/22/15, 8:13 AM

Hello,

Your function _get_partner_category , catch the context that comes from the action, So you can add some custom value to the action's context just like:

{'my_menu': 'my_custom_menu'}

Then in your function check if the context contains the value 'my_menu' if yes then return the calculated value ...


Regards,

Sorry, but I still don't quite understand what you mean.? In Emipro's is already using an action and a context. Now you are suggesting to use another action ?

Gavin Yap
on 7/22/15, 11:11 AM

No, no another action. Empiro suggested to use the [ default_ ] in the action's context, to set the defaults value, but you can add a new value to the context. Then add some checks to your function. Just try to print the context in your function to get it . in your function just write: print self._context or self.env.context

Ahmed M.Elmubarak
on 7/23/15, 2:47 AM

Thanks Ahmed, I think I know where you are getting at but I think I'm quite satisfied with the tip Empiro provide me and manage to achieve what I want

Gavin Yap
on 7/23/15, 9:15 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

3 follower(s)

Stats

Asked: 7/22/15, 1:57 AM
Seen: 560 times
Last updated: 8/31/15, 10:30 AM