how we can add a default value to a feild?pls give me an exmaple
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Financeiro
- Inventário
- PoS
- Project
- MRP
Esta pergunta foi sinalizada
Hi Aneesh,
If you are working with odoo 8, using the new api, you can try like this:
Eg:
from openerp import models, fields, api
class Session(models.Model):
_name = 'model.name'
discount = fields.Float(string='Discount (%)', default = 0.0)
state = fields.Selection(
[('draft',"Draft"),
('confirmed',"Confirmed"),
('done',"Done")],
default='draft')
You can see, I have set the default values for two fields, discount and state. In new api, you don't need to use '_defaults' to set the default values, you can give it in the field definition itself.
Hope this helps you.
Hello aneesh,
try this code may be helpfull.
write this code in .py file
_columns = {
'gender' : fields.selection([('m','Male'),('f','Female')],'Gender')
}
_defaults = {
'gender' : 'm'
}
using this code by default value set Male in gender selection field.
if you find this answer helpful, please give me a thumbs up vote
Thanks & Regards,
Ankit H Gandhi
if you want some small number of fields as default value means ,you can use
_default = {
'your_field' : 'your_default_value'
}
otherwise,if you want to diplay more values as default means ,you can use
default_get() method
Try it my way if you want to make this happen without coding. Just remember that you're setting default values only for your current database. I set the default country name to Canada for new clients in this scenario:
- Activate the developer mode in "About Odoo" page
- Open a client with your desired values, in this case a client from Canada (You need to see the client in Form View)
- On the top left corner choose the "set defaults" in the dropdownlist
- In the pop-up window choose "Country = Canada"
- Select the target users (only you or everyone)
- Click on "Save Default" button
You can do this for different fields in the same form by repeating steps 3 to 6
If you want to change the default value to something that is not listed in the Default dropdown, then you should do the following (it's way faster and there's no need to change the code):
Fill the field with wanted value which you want to set to default and THEN go to the developer mode, Click on Debug View dropdown (in the upper corner) and select Set Defaults. Now you see you have a NEW (exactly the one you wanted) default value in the dropdown, which you can select.
It can't get any easier than that :)
Está gostando da discussão? Não fique apenas lendo, participe!
Crie uma conta hoje mesmo para aproveitar os recursos exclusivos e interagir com nossa incrível comunidade!
Inscreva-se