Hi i am working on Odoo16
I am trying to create an integer field in product.template model.
And i want this field to have whatever is saved in the website_sequence field.
So if the website sequence for customizable desk is 987
My field should also have 987 by default.
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Accounting
- Inventory
- PoS
- Project
- MRP
This question has been flagged
Did you find a way to achieve your task ? I tried all suggested methods here but nothing to have my field as an editable copy from another one in the same model and same view...
Hi,
You can add default values for a field in different ways.
1) By compute method
example:
int_field = fields.Int(compute='_compute_int_field', store = True, readonly=False')
def _compute_int_field(self):
for rec in self:
rec.int_field = rec.website_sequence
2) Related field
example:
int_field = fields.Int(related='related_model_field.website_sequence',readonly=False')
3)lambda method
example:
int_field = fields.Int(default=lambda self:self.related_model_field.website_sequence)
4) Writing default function
def _default_website_sequence(self):
rec.int_field = rec.website_sequence
int_field = fields.Int(default=_default_website_sequence)
You can use all the above methods, The above given are just examples.
Hope it helps
Hi,
You can make it a related field or computed field based on the website_sequence field.
So your options are
* related field
* computed field
* by over riding the write method
Thanks
I dont want it to be related or computed>
I just want it to have default value as website_sequence field but i want it to be editable.
Enjoying the discussion? Don't just read, join in!
Create an account today to enjoy exclusive features and engage with our awesome community!
Sign up