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.
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've a conditional readonly field in the view of a model. This model is used as a One2many field on it's parent model.
When I edit one of the elements of the One2many field, click another of the elements the value of the field that has the conditional readonly disappears.
In my searches for this problem I've found the next related issue on odoo github.
My problem is quite similar, but the value of the field completely disappears when the readonly condition is False. When the condition is True the value reappears after clicking outside of the element (another element or outside of the form).
Basically, the models are:
One2many class:
class ChildClass(models.Model):
_name = 'child.class'
some_field = fields.Integer()
conditional_field = fields.Boolean()
conditional_readonly_field = fields.Integer()
parent_field = fields.Many2one(
'parent.class'
)
Parent class:
class ParentClass(models.Model):
_name = 'parent.class'
one2many_field = fields.One2many(
'child.class',
'parent_field'
)
View
<odoo>
<data>
<record model="ir.ui.view" id="view_draft_order_form">
<field name="name">parent.class.form</field>
<field name="model">parent.class</field>
<field name="arch" type="xml">
<form>
<field name="one2many_field">
<form>
<field name="some_field"/>
<field name="conditional_readonly_field" attrs="{'readonly': [('conditional_field', '=', True)]}"/>
</form>
</field>
</form>
</field>
</data>
<odoo>
So, the value of the conditional_readonly_field disappears after editing some_field and clicking on another element of the One2many field. The problem is that it may be after the first, second or some number of clicks (I've been trying and it's not consistent).
For the record, when the readonly condition is removed, the problem disappears.
Thanks in advance for any suggestions!
Yes, It will disappear when you give readonly attributes.
For overcome this problem, pass the value in create method as well in the write method. This will solve your problem.
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 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>