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>
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.
I am trying to get some values from (hr.payslip) model. Before that I need to add one more option in Action (dropdown list) where you can delete or export selected payslip. So when I select a payslip from treeView (checkbox in the image below) that new option should show up a wizard showing a table One2many having the selected payslip so I can Print or do some other action.
This is the scenario and i did not start any coding to do that.
I am new to odoo. I hope you can help me with some example.
you have to create new action and new object also
create new object
class NewObject(models.TransientModel):
_name = 'new.object'
_description = 'Description of new object'
#api.multi
def generate_report(self):
payslip_ids = self._.get('active_ids',[])
#payslip_ids this will be your selected payslip ids in list view.
<act_window
name="Your Action string"
res_model="new.object"
src_model="hr.payslip"
view_mode="form"
view_type="form"
target="new"
multi="True"
key2="client_action_multi"
id="id_of_act_window"
view_id="view of new object"
/>
then create view for new object
<record id="id of new view" model="ir.ui.view">
<field name="name">Name of view</field>
<field name="model">model of new view</field>
<field name="arch" type="xml">
<form string="">
<button name="generate_report" string="Generate Report
type="object" class="oe_highlight" />
</form>
</field>
</record>
and here you can add your code you want like.
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.
I would like to make a many2one field invisible when called by 'add an item' in the One2many view, for exemple :
parent view :
Name = 'this is One2many field'
value 1 =
value 2 : add an item
child view :
Parent Name = 'this is Many2one field'
value 1 = ....
and when i click on 'add an item' i'd like to get the folowing view :
child view :
value 1 = ...
I tried setting attrs="{'invisible':[('parent_id', '!=', False)]}" in the child view but this is always true because the parent fields are not created yet. Any idea ?
There is very simple way to achieve this by defining inline form view for that one2many field.
Here is an example for your reference.
<field name="one2many_field_name">
<tree>
<field name="field1" />
<field name="field2" />
<field name="field3" />
</tree>
<form>
<field name="field1" invisible="1" />
<field name="field2" />
<field name="field3" />
</form>
</field>
While you click on "Add an item" it will render form view which is defined inline and if there is no inline view defined then it will take form view which you have created externally.
So, that way you can define inline view for many2many / one2many fields, in that manner you can define behavior of any fields directly.
You can achieve it by setting context in one2many field in parent form view.
I will explain you by example.
placement_line is the parent view one2many field. In that set the context like below code.
<field name="placement_line" context="{'one2many':True}" />
Here, student_id is the manyone child form view field. See the below code.
<field name="student_id" invisible="context.get('one2many')"/>
By settings like above code in your parent form and child form you can invisible child field(many2one) when child form open from 'add an item' in the One2many view.
I'm a new Odoo developer and I need to hide the edit button when my form is entering a custom state, I need this because of a security problem.
This code in XML does not work when I try to give an attribute to the form.
<record model="ir.ui.view" id="pesan_form_view">
<field name="name">pesan_service_form</field>
<field name="model">pesan.service</field>
<field name="arch" type="xml">
<form string="Booking Service" attrs="{edit:'false':[('state','in','baru')]}">
<!-- structure of form -->
</record>
I don't know why it doesn't work.
qWeb conditions doesn't work for FormView.
You can check it here(path_to_odoo/addons/web/static/src/js/framework/view.js):
/**
* Return whether the user can perform the action ('create', 'edit', 'delete') in this view.
* An action is disabled by setting the corresponding attribute in the view's main element,
* like: <form string="" create="false" edit="false" delete="false">
*/
is_action_enabled: function(action) {
var attrs = this.fields_view.arch.attrs;
return (action in attrs) ? JSON.parse(attrs[action]) : true;
},
This method calls from template FormView.buttons in path_to_odoo/addons/web/static/src/xml/base.xml:
<button t-if="widget.is_action_enabled('edit')"
type="button"
class="oe_form_button_edit btn btn-default btn-sm" accesskey="E">
Edit
</button>
These problems are solved in Odoo with the help of rules(ir.rule object of Odoo)
You can find and edit rules in GUI here: Settings(top menu) -> Security(left menu) -> Access Rules(left menu). Use admin user in debug mode for this.
At the same you can add some rules to data.xml of your module for import. They will be added when you install or update module.
Be careful! Record rules do not apply to the Administrator user.
At the same you can try to expand widget FormView.
Hope this helps you.
Try this code.
<record model="ir.ui.view" id="pesan_form_view">
<field name="name">pesan_service_form</field>
<field name="model">pesan.service</field>
<field name="arch" type="xml">
<form string="Booking Service" attrs="{'edit': [('state', 'in', ['baru'])]}">
<!-- structure of form -->
</record>