In res.partner form view of sale.order, you got this code:
<field name="partner_id" on_change="onchange_partner_id(partner_id, context)" domain="[('customer','=',True)]" context="{'search_default_customer':1, 'show_address': 1}" options='{"always_reload": True}'/>
This view takes res.partner address into form ie: context="{'search_default_customer':1, 'show_address': 1}" now, I want this same behavior BUT on tree view.
I just copied this context into tree view, on partner_id field, but nothing happens, I tried many ways, with no results.
I'd like to have the partner's address on tree view also.
Anybody knows how to accomplish this?
Thanks in advance!
As per my point of view, context is used for often available as contextual actions on resources;
context is nothing but a python directory.
In your case this context will be update with your predefined value like here you have update it with 2 keys.
so when you use any method on this field like on_change so in that case you can use this updated context.
Related
By default, the create contact form from Contacts and create Vendor form from Purchase appears to have the same External ID ie, base.view_partner_form. I want to replace the form view for create contact. Now, i know that to replace a view i'll have to do this in my custom form view.
<field name="inherit_id" ref="external_id_of_form"/>
So how can i replace the form view in this case so that only the contact create form gets replaced? Can i replace the form view based on action? `
You're not "replacing" by inheriting, but changing/extending other views.
Indeed you should change the menu actions, because it is possible to set the target views.
But there is more than one approach. I'll try to list some of them, plus you can combine them.
full single views
one or more ir.ui.view of same type for the same model
can be referenced in actions and code
only one of them can be the default view of that type, which odoo will use for example in actions without a view reference, keep that in mind!
one base form with different extension views
one base view for a model
multiple primary extension views to that base view
you can either use those primary extensions as reference in actions
or you can set security groups in those extensions to show these extensions only to users of those groups
one view with extension views
that's the usual approach
you have a base view and lot of extensions
visibility is defined in the arch with groups, attrs, invisible, etc.
IMO the best approach for you is the first one. An Odoo example are the views for model account.invoice, because there are two form views: one for customer invoices and one for supplier invoices.
In Odoo Opportunity Report I would like to add field customer from res.partner.
I created addon (which installed, and does other things besides, so I am sure that addon works) in which I have inherited from https://github.com/odoo/odoo/blob/10.0/addons/crm/report/crm_opportunity_report.py .
And added a field
customer = fields.Boolean('Customer', related='partner_id.customer', readonly=True)
But field Customer doesn't appear in report when I click '+' in Reports->Pipeline.
What did I miss?
It is not enough to define a field. Odoo reporting is working on database views. So by adding a new field, you have to change the view, too. Normally or in newer versions Odoo has good extendable view definitions by using the init(). In your example it's the old "bad to extend" view definition, so you have to override the whole init.
I need to control visibility of the field based on the value of another field. That another field is a reference. I think I need to do a lookup pretty much the same way as I can do in a module with browse or search methods. But how to do in a view?
View:
<field name="org_no" attrs="{'invisible':[('country_id','!=','Sweden')]}"/>
Model (standard res.partner):
country_id: fields.many2one('res.country', 'Country')
field_view_get is static solution problem where once you set the value on domain, view will follow that, so if that's your requirement you can use it.
or else you can use below solution for better and dynamic behavior.
Take one Boolean field on your object where you wanna control visibility and add it in field as invisible.
Write on_change method of your field based on what you wanna control visibility and using the on change method you can set the value of the above boolean field.
using the First step boolean field on attrs to make field visible on demand.
Thank You
You can directly use this:
<field name="org_no" attrs="{'invisible':[('country_id.name','!=','Sweden')]}"/>
because country_id just stores the ID of the country that is selected in your many2one field
Leaving aside the hard coding, you pretty much have it. Just ensure that the country_id field is on the form so it can be used in the attrs on org_no. If you don't want the user to see the country, just put it on as an invisible field.
I'm facing a complex problem, at least for me.
I have a form called "Task", which contains all the normal info, and I would like to add users to that Task.
If I want to add multiple users to that task, I should use the widget one2many, am I right? If so, is it possible to display a dropdown or something and add the users already registered? Because, with the default one2many, I have to register the users (like a Form) and then I can add them..but if they are already in the table, it should appear me a dropdown menu or something..
After the task is created, the users should only see the task with their name, only administrator can view it all. I think that to achieve this I need to create rules, right? If so, do I need to create them by code or could I use the openERP rule menu? And this will be enough: ('user_id', '=', user.id)]? The first column "user_id" is created on "Task" table?
I do not need to have a auxiliary table that would contain something like: id, task_id, id_user..and by this I could get which tasks belongs to whichs users??
Thanks guys
For your cases:
You can try using Many2Many relation so as to choose the record of users.
Use Groups to obtain your desired result.
For example:
<field name="user_id" groups="your_group" />
By doing this you can provide what fields to be visible to which user based on access rights provided in your GROUPS.
I am a current web2py user, but find I still go back to Django once in a while (where I started). Specifically when working on projects where I want to make use of some specific django apps/plugins/extensions that don't yet exist in web2py.
One thing that I can't live without in web2py, which I am looking for a solution for in Django, is the way to create html forms from a db table and being able to then customize their look and layout in the view, without javascript.
Key things I am looking for:
Generate html form from a db table
Assign custom css classes/ids to each field in the generated html form (js disabled)
Place each form field/element in a pre-made html view via a method call in the view
i.e.
I have a table A. In web2py I can do (in controller):
def display_form():
form = SQLFORM(db.table_A)
#Can I do the following in Django? Assign custom CSS to each form field?
form.element(_name='email')['_class'] = = "custom_css_classes, list"
if form.accepts(request.vars, session):
response.flash = 'form accepted'
elif form.errors:
response.flash = 'form has errors'
else:
response.flash = 'please fill out the form'
return dict(form=form)
Then, in the View I can do:
form.custom.start
form.custom.widget.name
form.custom.widget.email
form.custom.widget.form_field_name
...
<div class="span-5 last"><input type="submit" class="register_btn" value="Sign Up"></input></div>
form.custom.end
The above takes a DB table, creates an HTML form, and then lets me stick each separate form field in any place in the pre-made HTML that I want (using those "custom" method calls on the passed "form" object. Including the custom css classes I assigned to each separate field of the generated html form.
See documentation for details on the above code:
http://web2py.com/book/default/chapter/06?search=define_table
http://web2py.com/book/default/chapter/07?search=sqlform#SQLFORM
http://web2py.com/book/default/chapter/05?search=#Server-side-DOM-and-Parsing
http://web2py.com/book/default/chapter/07?search=form.custom
How do I do the above in Django without dirtying my javascript with layout hacks. Assume javascript is disabled in the browsers where I need my app to run. Furthermore, I would love to make use of Django admin. Pylons solutions also welcome!
Links to articles/tutorials/howtos for this would be greatly appreciated.
Also, please make an equivalent result of the above code using the method you mention in your response...
Use ModelForm and override any field you wanna customize by explicitly declaring them.
If you want to set field attributes like class and id, you need to do something like this:
name = forms.CharField(
widget=forms.TextInput(attrs={'class':'special'}))
In case you are interested, you may change the order of the fields by specifying a fields sequence in your Meta class:
class Meta:
model = YourModel
fields = ('title', 'content')
You may read the full documentation here:
http://docs.djangoproject.com/en/dev/ref/forms/widgets/#django.forms.Widget.attrs
If you haven't already, take a look at Django's ModelForm. I am assuming that you have models mapped to the tables in question. Vanilla ModelForm instances will work without JS. However ModelForms are usually defined ahead of time and not constructed on the fly. I suppose they can be created on the fly but that would be a bit tricky.