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.
Related
Say, in odoo I have a Model A with a many2one field to model B.
Model B has a field "city".
Now I want to create a form for model A in which I want the "city" field of model B.
I can do this by adding the city field of Model B to model A as well and giving it the related flag.
b_city = fields.Char(related='b_id.city', depends=['b_id'])
But I dont like this because than I have to add this field to my model. I would prefer if can do this without creating this field. Is this possible?
-----------Edit---------------
Something that I'm looking for is like this:
<page string="Offers">
<field name="offer_ids">
<tree>
<field name="price"/>
<field name="partner_id"/>
<field name="validity"/>
<field name="date_deadline"/>
<button name="accept" type="object" icon="fa-check"/>
<button name="reject" string="X" type="object" icon="fa-xmark"/>
<field name="status"/>
</tree>
</field>
</page>
This a page in a form where the corresponding model has a one2many field which is being displayed in a tree view. Now, I want to the other way around. I want to display in a form some fields of another model to which the there is a many2one field.
Is it possible to do this in the the xml view?
There is no way to do that in Odoo unless using related field.
Check Odoo ORM documentation
USING PYTHON CODE :
Example 1:
invoice_partner_icon = fields.Char(compute='_compute_invoice_partner_display_info', store=False, compute_sudo=True)
#api.depends('partner_id', 'invoice_source_email')
def _compute_invoice_partner_display_info(self):
for move in self:
vendor_display_name = move.partner_id.display_name
if not vendor_display_name:
if move.invoice_source_email:
vendor_display_name = _('From: ') + move.invoice_source_email
move.invoice_partner_icon = '#'
else:
vendor_display_name = _('Created by: %s') % (move.sudo().create_uid.name or self.env.user.name)
move.invoice_partner_icon = '#'
else:
move.invoice_partner_icon = False
move.invoice_partner_display_name = vendor_display_name
OR USING UI :
As admin, You can create a new field in Model B which is related to model A without storing it in the database : in App Settings, switch to debug mode by adding "?debug=1" in your url, reload the page, then go to the new Technical Menu-tab > Fields.
Then, create your new related field using the panel "Advanced Properties" Related Field: ...
and then uncheck [ ] Stored
I tried removing it from the file account-> models-> account_invoice.py.
But it is showing error. So, is there any other way I can remove it from python file. How can I customize predefined model in odoo?
Definitely agree with Michele Zacceddu having the correct answer where you should be overriding the model, and updating properties on that field such as required or readonly, especially for important fields such as account_id.
But you do have the option to remove fields all together if there happens to be a scenario where you absolutely need it. You will want to make sure that you handle removing all references in the xml views and python methods to the field you are about to delete.
<record>
...
<field name="arch" type="xml">
<field name="account_id" position="replace"/>
</field>
</record>
class Invoice(models.Model):
_inherit = 'account.invoice'
def _method(self):
# override methods that reference or use the fields we
# are about to delete so that we don't break core
delattr(odoo.addons.account.models.account_invoice.AccountInvoice, 'account_id')
You can not remove fields. You can remove the required property, but not the field itself.
To do that you have to inherit account.invoice model and redefine that field.
Like:
class AccountInherit(models.Model):
_inherit = 'account.invoice'
< here define that field, it must be the same as the original but the required property >
I have one field which i want to hide when specific journal selected.
<field name="any_field" attrs="{'invisible':[('journal_id','=',10])]}"/>
And For that above code is working fine.
I sure it is not a way to check condition.So, i tried this way.
<field name="any_field" attrs="{'invisible':[('journal_id','=',ref('my_module.account_journal_10'))]}"/>
It's working then i tried by using the static field on the journal eg. code.
<field name="any_field" attrs="{'invisible':[('journal_id.code','=','CARD')]}"/>
But still not working and getting error from view.
I am thinking if i can return the attrs from .py like i do for domain.
eg.
return {'domain':
{
'any_field':[('journal_id','=',self.env.ref('my_module.account_journal_10').id)]
}
}
Can anybody help me in this?
Thank you.
As far as i know these attrs domains/filters are client-side so you can't use something like journal_id.code or partner_id.customer, because the client doesn't know about such data.
A possible workaround is to define a related field on the model you're trying to do this. Let's assume the model is my.model and already has this Many2one field journal_id:
journal_code = fields.Char(string="Journal Code", related="journal_id.code")
Now you need to extend the view of my.model:
<field name="journal_code" invisible="1" />
<field name="any_field" attrs="{'invisible':[('journal_code','=','CARD')]}"/>
Good Day! is it possible to disable pop of tree view in the form. I tried no_open="True" readonly="1" edit="False" both on field and tree view but didn't worked.
<field name="payment_line">
<tree editable="top" create="false">
<field name="product"/>
<field name="description"/>
<field name="account"/>
<field name="unit"/>
<field name="qty"/>
<field name="amount"/>
<field name="total"/>
</tree>
</field>
I've coped with the same issue in odoo 10, my one2many treeview always make a popup on click. No matter editable='bottom' option was set.
Suddenly I've found web_tree_no_open module from codingforfun, that adds a new option:
< tree open="false" >
It's for version 8 but it can be used in 10 just renaming openerp.py to manifest.py
It can be downloaded from here:
https://github.com/initOS/web/tree/8.0-tree-view-no-select/web_tree_no_open
Worked for me, I hope it helps
Use this style to disable click in read as well as edit mode:
<field name="your_o2m" style="pointer-events:none;" />
Use editable='bottom' in this case, like:
<field name='line_ids'>
<tree create='false' editable='bottom'>
<field name='so_line_id' readonly='1'/>
<tree>
</field>
Odoo Version 10.0
web_tree_no_open module adds a new option: <tree open="false">
Lists
The root element of list views is <tree> 3. The list view's root can have the following attributes:
editable
by default, selecting a list view's row opens the corresponding form view. The editable attributes makes the list view itself editable in-place.
Valid values are top and bottom, making new records appear respectively at the top or bottom of the list.
The architecture for the inline form view is derived from the list view. Most attributes valid on a form view's fields and buttons are thus accepted by list views although they may not have any meaning if the list view is non-editable
default_order
overrides the ordering of the view, replacing the model's default order. The value is a comma-separated list of fields, postfixed by desc to sort in reverse order:
<tree default_order="sequence,name desc">
create, edit, delete
allows disabling the corresponding action in the view by setting the corresponding attribute to false
on_write
only makes sense on an editable list. Should be the name of a method on the list's model. The method will be called with the id of a record after having created or edited that record (in database).
The method should return a list of ids of other records to load or update.
string
alternative translatable label for the view
Deprecated since version 8.0: not displayed anymore
Note
if the list view is editable, any field attribute from the form view is also valid and will be used when setting up the inline form
view
in the form and tree view you can add create='false' to disable the create button and edit='false' to disable the edit button.Also use editable="top" or editable="bottom" if you dont want the form view to popup. for example
<tree string="Sale Order" create="false" edit="false" editable="bottom">
...
...
...
</tree>
I want to change the tabindex in a form in opererp
how can I change it in the xml file or the python code
I am using openerp 6.1
example to what I need
in sales order form ,user want to change the focus of the element using tab button
he need to write first the order reference field then go to customer service field using a tab button,but when I press tab I go to the date button not the custom service even that the date button has a default value
Thanks
You can inherit and change both the models (defined in python files) and views (defined in xml files). More details about inheritance can be found here Object Inheritance
and Inheritance in Views
you can overwrite the original xml arch in your view and change the sequence of pages as per your requirement
like:
<record id="**account.invoice_supplier_form**" model="ir.ui.view">
<field name="name">account.invoice.supplier.form</field>
<field name="model">account.invoice</field>
<field name="priority">2</field>
<field name="arch" type="xml">
<form string="Supplier Invoice" version="7.0">
as shown above you can write the same xml arch as define in account for supplier invoice,
and you can now change sequence of pages
hope this help