I'd like to know is it possible to have different form views for edit mode and create mode in odoo ?
Actually I just want to hide some elements in create mode and show it in edit mode.
I've tried to using attrs like :
<button name="%(print_invoice)d" string="Cetak Struk" type="action" attrs="{'invisible':[('id', '!=', False)]}" />
But when i open the form it gives me error like this :
Uncaught Error: Unknown field id in domain [["id","!=",false]]
Any help would be appreciated.
Thank you
I have used attrs="{'invisible': [('id', '=', False)]}" to hide a field on creation. You must have id as a (hidden) field in your view, like <field name="id" invisible="1" />
you can easily work around this by using "create_date" as a trafic light.
1st expose the field
# make creation date visible
create_date = fields.Date(
'Data',
invisible=False,
readonly=True,
)
then add it to the form and use it into attrs property
<field name="create_date" invisible="1" />
<ELEM attrs="{'invisible': [('create_date', '!=', False)]}">
[...]
</ELEM>
You can have different views for read, edit and create like this if desired
<div class="oe_read_only">
READ ONLY
</div>
<div class="oe_edit_only" attrs="{'invisible':[('id', '=', False)]}">
EDIT ONLY
</div>
<div attrs="{'invisible':[('id', '!=', False)]}">
CREATE ONLY
</div>
#qatz
You cannot have different views based on "Edit" or "Create" of record.
You can try this by adding "state" field and based on the value of state you can hide show the elements.
Hope this helps !!
Related
Hello I need to add some information to the delete record confirmation dialog on Odoo 12, adding some information of how many dependent records will be deleted. Something like:
Are you sure you want to delete this record ?
Doing this you will lose N records.
Currently is defined on "addons/web/static/src/js/views/basic/basic_controller.js" on _deleteRecords method. But if I change it there it will be changed for all my modules.
I'm wondering if there is a method to overwrite this... Or my other idea is to hide the button and use a wizard to do it.
any idea?
By default odoo can do that from xml file but if you need dynamic message than
please create one transient model for wizard and this model have two fields which is your message field and your main form view id after that you simply override the method unlink and in method do your computations if you want confirmation in deletion then return from that condition like this:
return{
'type':'ir.actions.act_window',
'name':'Message',
'res_model':'your.wizard.model',
'view_type':'form',
'view_mode':'form',
'target':'new',
'context':{'thesis_obj':self.id,'text_message_field':'course Work completed'},
'res_id':value.id
}
After wizard opened you have your wizard's form view right?
in wizard form view if user click on OK button then call your original method from which you have to do it in first place.
Wizard View Reference:
<record id="wizard_message_form_view" model="ir.ui.view">
<field name="name">Approval Message</field>
<field name="model">your.wizard.model</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Message">
<separator string="Message" colspan="6"/>
<field name="text_message" colspan="4" nolabel="1" readonly="1" widget="html"/>
<newline/>
<separator colspan="6"/>
<footer>
<button name="btn_approve_oric" type="object" string="OK" class="oe_highlight"/>
<button special="cancel" string="No"/>
</footer>
</form>
</field>
Feel free to ask.
This might be a simple question.but,does any one know how to disable a button after clicking it in Odoo? Thanks for all your help.
Most of Odoo module use state for this kind of problem. the general idea of it that you must have a field and the button is displayed based on the value of that field.
Ex:
# in you model
bool_field = fields.Boolean('Same text', default=False)
In your view:
<button name="some_method"......... attrs="{'invisible': [('bool_field', '=', True)]}" />
...
...
...
<!-- keep the field invisible because i don't need the user to see
it, the value of this field is for technical purpuse -->
<field name="bool_field" invisible="1"/>
In your model:
#api.multi
def some_method(self):
# in this method i will make sure to change the value of the
# field to True so the button is not visible any more for user
self.bool_field = True
...
...
...
So if you all ready have a field that the button change it's value you can use it directly
or create a special field for this purpose.
I want to use Chatter for students model, so that, when value of some field is changed then it is logged under student form
To achieve this, I did the following things:
1. Added this div
<div class="oe_chatter">
<field name="message_follower_ids" widget="mail_followers"/>
<field name="message_ids" widget="mail_thread"/>
</div>
in the student form.
It added the chatter, but when i clicked on New Message button, it gave the following error.
This could be because i haven't inherited mail.thread in student model.
Then i inherited this class in student model.
Then it again gave an error as shown below
I search this topic, but couldn't found anything.
It would be appreciated if someone could help me out.
In order to log changes of specific fields you need so set the track_visibility attribute on each field you want to track:
class OpStudent(models.Model):
_name = 'op.student'
_inherits = {
'res.partner': 'partner_id',
}
_inherit = [
'mail.thread',
'ir.needaction_mixin',
]
foo = fields.Char(track_visibility='always')
You may read more about it in the official documentation.
You're using Chatter for keeping the track on student details.
So I'll suggest another module which is working absolutely fine and keeps the track on student or any other model you want as I have personally used it.
I used audit log. It tracks all the CRUD operations. It will create Audit
the menu in setting tab from there you can set the model which you want to track.
For reference you can check this image also.
I had the same problem, but with res.company, I solved it like this:
class ResCompany(models.Model):
_name = 'res.company'
_inherit = ['res.company','mail.thread', 'mail.activity.mixin']
date_end = fields.Date(string="Fin Date",tracking=True)
and in xml:
<xpath expr="//form/sheet" position="after">
<div class="oe_chatter">
<field name="message_follower_ids" widget="mail_followers"/>
<field name="message_ids" widget="mail_thread" />
</div>
</xpath>
I hope, that it serves you.
I have two forms. First task_view.xml display all task for all users. In second form user_view.xml after open one user I'm add
button
<button class="oe_inline oe_stat_button" style="float:right;" type="action" icon="fa-folder" name="%(task_view_form)d"
context="{'??????}">
<field string="total" name=total_qty" widget="statinfo" />
</button>
Now when click on button I get all task for all users, how use context or any other solution after click on button I need (filter) only task for that users.
I need filter project_task_user_id = id user from form where is placed button.
Try this:
context="{'search_default_project_task_user_id ': active_id}"
I think to achieve this you need to add the domain to you action:
<record id="task_view_form" ...>
...
...
<field name="domain">[('project_task_user_id','=' , uid)] </field>
</record>
I'm working on Odoo 8.
I added a smart button on my partner form to display the current opportunities of the partner. When i click on the button, i want to open the list of the filtered opportunities. This works, but not in a list of opportunities (should be crm_case_tree_view_oppor); it opens a list of leads (with my opportunities inside ??? > crm_case_tree_view_leads).
And so, when i click on the create button (on the top of the list), it opens the lead form and not the opportunity form.
Here's my code :
Smart button in my inherited partner form :
<button class="oe_inline oe_stat_button" type="action" name="%(action_current_opportunity_partner_list)d" icon="fa fa-star-o">
<field string="Opp. en cours" name="opportunity_current_count" widget="statinfo"/>
</button>
And the associated action :
<record id="action_current_opportunity_partner_list" model="ir.actions.act_window">
<field name="domain">[('partner_id.id', '=', active_id), ('probability', '!=', 0), ('probability', '!=', 100)]</field>
<field name="view_mode">tree,form</field>
</record>
How can i tell Odoo to open the list of opportunities (crm.crm_case_tree_view_oppor) and after, make the button create to create an opportunity and not a lead ?
You need to add a view_id on your ir.actions.act_window like:
<field name="view_id" ref="crm.crm_case_tree_view_oppor" />
Don't forget to set crm in your module dependencies (__openerp__.py)
For the second Problem (create) add a context to your action:
<field name="context">{'stage_type': 'opportunity', 'default_type': 'opportunity', 'default_user_id': uid, 'needaction_menu_ref': 'sale.menu_sale_quotations'}</field>
That one is just copied from the window action behind the Opportunities menu item.
So i just replace my button with this :
<button class="oe_inline oe_stat_button" type="action" name="crm.crm_case_category_act_oppor11" icon="fa fa-star" context="{'search_default_partner_id': active_id}">
<field string="Opportunités" name="opportunity_total_count" widget="statinfo"/>
</button>
Just change the name to "crm.crm_case_category_act_oppor11" and erase my own actions.
Works now.
The list worked before, button not the "Create" button. I haven't any explanations.