This is what I have tried so far, but it seems that it doesn't work the way it would word on a field. Also I tried making it options="{'edit': [('template_is_locked', '=', False)]}".
<form string="Templates" attrs="{'edit': [('template_is_locked', '=', False)]}">
</form>
Another thing that I've tried is adding an attribute inside a form and header like this:
<attribute name="edit">
[('template_is_locked', '=', False)]
</attribute>
Seems like form element simple don't react to any field changes. Maybe some of you had similar problem and you could share it with me.
Unfortunately, there isn't any way to dynamically lock the entire form itself. The only workaround, as #danidee mentioned, is to set the readonly attrs on each field individually.
Normally Odoo core models handle this situation like this:
name = fields.Char('Name', readonly=True, states={'draft': [('readonly', False)]})
Model with a field, state, which other fields can be readonly based on the state.
The name field is always readonly unless the record is in the Draft state.
Related
Currently, I had a view form and there is some field that need to be hide or unhide by click a button.
I tried to use State, Boolean field but unable to achieve the result.
My question is could I do it on Odoo and how?
I used State and Boolean field and set by condition on field, however the result was not good.
When a user clicks a button, hidden field will appear back
Yes, you can do it.
Button action in odoo triggers write method before being executed.
You should be aware of this before implementing your logic and your domains in order to show/hide fields in XML Views.
Your need is to use invisible attribute applied to a domain inside your field.
invisible is normally static, but can be elasticised inside attrs attribute.
Another important thing is, field-based domains requires the field to be present in view in order to access it. A good practice is to make these fields invisible and put them on top of your view.
In your model:
show_fields = fields.Boolean(default=False)
field_to_show = fields.Char()
def show_fields_action(self):
for record in self: record.show_fields = True
In your view:
<field name="show_fields" invisible="1" />
<field name="field_to_show" attrs="{'domain': [('show_fields','=',True])}" />
<button name="show_fields_action" type="object" string="Show Fields" />
If your question UI/UX related, consider using notebooks instead.
example/models/example.py
class Example(models.Model)
_name = 'example.model'
product_tmpl_id = fields.Many2one('product.template','Product Template',delegate=True,ondelete='cascade',required=True)
example/models/product_template.py
class ProductTemplate(models.Model)
_inherit='product.template
example_ids = fields.One2many('example.model','product_tmpl_id',string='Item')
example/views/example.xml
<form>
<field name="product_tmpl_id" widget="many2one"/>
</form>
My understanding was that a product_template record would be automatically created with example, but this field is required and not letting me save a new record. When I perform an import of the example data adding these columns at the beginning for product_template ("exampleNN", "name", "type", "categ_id/id", "sale_ok", "purchase_ok",...) I get a matching product template with an id of "exampleNN_product_template" and identical name (though example does not have name so it must be using product template).
product_tmpl_id does not like being on the form view as it is required, yet not created yet with delegation inheritance. I used tree view instead to see product_tmpl_id. I was curious about its value after doing an import.
I defined a Many2many field for ir.attachemnt. The problem is i can' see the Add an item link to add the records.
*.py
attachment_ids = fields.Many2many('ir.attachment', string='Attachments')
*.xml
<notebook>
<page string='Attachments'>
<field name="attachment_ids"/>
</page>
</notebook>
I also tried this:
<field name="attachment_ids" widget="many2many" />
Any idea?
There is only two thing that make Odoo behave like this.
Your view is in edit mode but I think I'm seeing a place holder comments this means it's not the case
Your user is not allowed to create an ir.attachment which is more likely not the case
Your field is readonly.
If not one of this cases these is wired but if you didn't understand what happen you can force that link to appear by using embedded tree with create attribute set to true
<field..... >
<tree create='1'>
....
It'a a bug. If you have more many2many fields in the some class and for one of this you haven't right access rules, all the many2many fields are showed in readonly mode.
Is there any way to put into website template Selection field (fields.Selecton) of some model or dropdown selection of some model records ?
Or only one way is to call some python methods and get some data and then put it data into web page using JS ?
It turned out that you can add field using editor.
Also all fields are in the black list for website posting by default. To remove it from blacklist you will need to do stuff like this:
<function model="ir.model.fields" name="formbuilder_whitelist">
<value>crm.lead</value>
<value eval="[
'contact_name',
'description',
'email_from',
'name',
'partner_name',
'phone',
]"/>
</function>
I need to know what command to add to the transition of DRAFT > CONFIRMED state of a document in ODOO-8 to make all fields READ ONLY.
I've attached an image below to see the fields that can be edited even though the state is confirmed.
I'm new to STACKOVERFLOW, thanks alot and i await replies
You should add the attrs attribute to each field in the view definition like this:
<field name="field_name" attrs="{'readonly': [('state', '=', 'confirmed')]}"/>
Or, as #CZoellner said, you can do that in the .py:
field_x = fields.Char(string="X", states={'confirmed': [('readonly', True)]})