Display a simple message box - odoo

How to display a simple message box inside method of a button at the user click.
When the user click on the button he see a message box.

If you just want to show a message box before executing the button function then you need to add an attribute conform in your button xml tag. For example
<button name="button_process" string="Proceed" confirm="Do you want to proceed?" type="object" class="oe_highlight"/>
When user click on this button Proceed a dialog box will be showed with message "Do you want to proceed?", when you click ok on that dialog box, then only the button_process will be executed.

I have Just Add small method in .py file and generate the message box on button click
XML File
<record id="view_hr_payroll_payslip_wizard" model="ir.ui.view">
<field name="name">hr.payroll.payslip.wizards</field>
<field name="model">hr.payroll.payslip.wizard</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="moves" version="7.0">
<footer>
<button name="generate_msg" string="Click To Me" type="object" class="oe_highlight"/>or
</footer>
</form>
</field>
</record>
same name of method are define in my button name attribute in my .py file
from openerp.tools.translate import _
def generate_msg(self, cr, uid, ids, context=None):
raise osv.except_osv(_("Warning!"), _(" Hello Mehdi Mokni !!."))
python Library can be added for covert your message in your Language
I hope this should helpful for you ..:)

Related

Adding a combination of leave type in the TimeOff module in the LeaveForm? Odoo13

I needed to add a feature that can combine two leave types in the TimeOff module form, and when a user submits the form the leaves gets deducted from the respective time off type. (In the form I am thinking to add a second dropdown menu where he/she can add the other time off).
I am using Odoo13, I am inheriting the module, but can't figure it out to add a dropdown in which the user can select multiple leaves.
model=hr.leave, externalid = hr_holidays.hr_leave_view_form
Work that I have done:
I have created a module which inherits the hr_holidays module in Odoo13, In the leave form i have sucessfully added the dropdown which is above but it is selecting the same time-off type which is selected above.
Here is the xml file:
<?xml version='1.0' encoding='UTF-8' ?>
<odoo>
<!--Adding the Drop Down-->
<record id="hr_leave_view_form_addnewleave" model="ir.ui.view">
<field name="name">leave.addleave</field>
<field name="model">hr.leave</field>
<field name="inherit_id" ref="hr_holidays.hr_leave_view_form"/>
<field name="arch" type="xml">
<xpath expr="//div[#name='description']" position="before">
<div class="row" name="status_id">
<label class="col-2 mr-0" for="holiday_status_id"/>
<!-- RLI FIXME: we should avoid redefining the domain in the view when there already is a domain on the model -->
<field name="holiday_status_id" domain="['&', ('virtual_remaining_leaves', '>', 0), '|', ('allocation_type', 'in', ['fixed_allocation', 'no']),'&',('allocation_type', '=', 'fixed'), ('max_leaves', '>', '0')]" context="{'employee_id':employee_id, 'default_date_from':date_from}" options="{'no_create': True, 'no_open': True}" class="col-9 pl-0" nolabel="1"/>
</div>
</xpath>
</field>
</record>
</odoo>
In this the code with is for the dropdown.
The LeaveForm image with dropdowm
Thanks in advance.Please look into the photo that I uploaded.

Adding menu to Odoo 10 in custom module

I want to add a submenu to Settings->Technical menu in Odoo 10.
I have tried with the following code, apparently the menu item is loaded (you can see that it is one of the menus created by the custom module) but it is not displayed.
Any tip/suggestion on why?
<?xml version="1.0"?>
<odoo>
<menuitem id="sale_order_custom_document"
name="Sale Order Custom Documen"
parent="base.menu_custom"
/>
</odoo>
Thanks
You have to define the action in menuitem then only it is visible. menuitem without any action will became normal string for display purpose. So either add sub menu with action or directly assign any action to it.
<menuitem name="Sale Order Custom Document" action="<your_action_id>" id="sale_order_custom_document" parent="base.menu_custom" sequence="20"/>
Here's a description link for odoo action
you must also create the actions 's record named:
product.product_template_action_custom_docs for example
declare your menu just after
Try this:
<odoo>
<data>
<!-- your initial code in your <app>_view.xml -->
<record id="product.product_template_action_custom_docs" model="ir.actions.act_window">
<field name="name">Sale Order Custom Document</field>
<field name="res_model">product.template</field>
<field name="view_mode">tree,kanban,form</field>
<field name="view_type">form</field>
<field name="context">{"search_default_filter_to_sell":1}</field>
<field name="help" type="html">
<p> here you write the help form your form</p>
</field>
</record>
<!-- after the action, you can now paste your menu declaration
your specified "action", "id","name","sequence" and "parent"-->
<menuitem action="product.product_template_action_custom_docs"
id="sale_order_custom_document" parent="base.menu_custom" sequence="20" name="Sale Order Custom Document" />
</data>
<odoo>

Inherit TransientModel and have two views ( website.config.settings )

I am trying to inherit the Website settings menu and have two views. website.config.settings is a models.TransientModel
When I am inheriting that and viewing with a new menuitem it overwrites the previous view. Like - There are two views now, the new record I defined named Website Event Settings . When I click on that it loads the new modified view but when I click on existing Settings menu, it shows nothing.
In summary, the existing website settings menu not working and new menu does. I need both of them.
The py code and record view I used are following -
class cofair_website_design_config(models.TransientModel):
_name = 'website.config.settings'
_inherit = 'website.config.settings'
event_title = fields.Char(related='website_id.event_title', string='Event Title')
XML:
<record id="view_website_event_config_settings" model="ir.ui.view">
<field name="name">Website Event Settings</field>
<field name="model">website.config.settings</field>
<field name="arch" type="xml">
<form class="oe_form_configuration">
<header>
<button string="Apply" type="object" name="execute" class="oe_highlight"/>
<button string="Cancel" type="object" name="cancel" class="oe_link"/>
</header>
<div>
<group string="Event Page Section">
<group>
<field name="event_title_color"/>
</group>
</group>
</div>
</form>
</field>
</record>
<record id="action_website_event_configuration" model="ir.actions.act_window">
<field name="name">Website Event Settings</field>
<field name="res_model">website.config.settings</field>
<field name="view_mode">form</field>
<field name="target">inline</field>
<field name="view_id" ref="view_website_event_config_settings"/>
</record>
<menuitem id="menu_website_event_settings" parent="website.menu_website_configuration" name="Website Event Settings" action="action_website_event_configuration"/>
Instead of renaming the modules (which causes relational error), I found a workaround. I have inherited the main settings and put a view id there and called it with menuitem -
<!-- Bring settings menu out -->
<record id="website.action_website_configuration" model="ir.actions.act_window">
<field name="name">Website Settings</field>
<field name="res_model">website.config.settings</field>
<field name="view_mode">form</field>
<field name="target">inline</field>
<field name="view_id" ref="website.view_website_config_settings"/>
</record>
<menuitem id="website.menu_website_website_settings" parent="website.menu_website_configuration" name="Website Admin" action="website.action_website_configuration"/>
Then I called my record action and it loaded the view and action. Another catch point is I had to show website_id to show the values of specific websites or the transient model will always be empty.
Change the _name attribute in your model definition to something else and also modify the xml appropraitely.
class cofair_website_design_config(models.TransientModel):
_name = 'something.else'
_inherit = 'website.config.settings'
event_title = fields.Char(related='website_id.event_title', string='Event Title')
ir.ui.view
<field name="model">something.else</field>
and ir.actions.act_window
<field name="res_model">something.else</field>
That should copy all the fields and methods from website.config.settings to the new model something.else and keep it separate from website.config.settings

Odoo 9 yes/no pop-up box python

Odoo v9.
I would like to prompt the user with a yes/no option before certain python code is executed.
If this were in a button I could use the confirm="text?" attribute, however I do not want to trigger any database updates irrespective of the users answer to this particular prompt.
e.g. onchange event triggers yes/no box, which can then manipulate page, however the user still has to press "save" to keep any changes.
Is there any way of doing this using base odoo?
onchange events can't return a dialog because they were simply not built to do that https://www.odoo.com/forum/how-to/developers-13/what-should-onchange-methods-do-and-return-57760
You can use a wizard (it's not really a wizard it's just a form) and show it as a popup. our wizard model will be a Transient model, which would be discarded by odoo after a specified amount of time.
from openerp import fields, models, api
class test_model(models.Model):
_name = 'test.model'
name = fields.Char(string='Value')
#api.multi
def call_up_wizard(self):
return {
'name': 'Are you sure?',
'type': 'ir.actions.act_window',
'res_model': 'wizard',
'view_mode': 'form',
'view_type': 'form',
'target': 'new',
}
class wizard(models.TransientModel):
_name = 'wizard'
yes_no = fields.Char(default='Do you want to proceed?')
#api.multi
def yes(self):
pass
# sure continue!
#api.multi
def no(self):
pass # don't do anything stupid
This is how your view would look like
<record id="cashadvance_list" model="ir.ui.view">
<field name="name">Test Dialog</field>
<field name="model">test.model</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Test Dialog" version="8.0">
<group>
<button class="oe_highlight" name="call_up_wizard" string="confirm" type="object" />
</group>
</form>
</field>
</record>
<record model="ir.ui.view" id="wizard_form">
<field name="name">wizard.form</field>
<field name="model">wizard</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Confirm dialog">
<field name="yes_no" readonly="1" />
<footer>
<button class="oe_highlight" name="yes" string="Yes" />
<button class="oe_highlight" name="no" string="No" />
</footer>
</form>
</field>
</record>
<record model="ir.actions.act_window" id="action_test">
<field name="name">Cash advance list</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">test.model</field>
<field name="view_type">form</field>
<field name="view_mode">form,tree</field>
<field name="help" type="html">
<p class="oe_view_nocontent_create">
It's empty, create something
</p>
</field>
</record>
In our test_model view we have a button that's shows the wizard as a popup, and then in the wizard buttons are handled by the yes and no methods respectively, this gives you better control over the buttons as you know have separate methods controlling the two buttons you have on the form.
I just put this answer, for anyone who happens to stumble on this thread and wants to know how to create a popup from a button.

Show form field and tree view together odoo

I managed to add two custom fields to the settings by inheriting res.config.settings in a new module created. The xml page of the same is
<record id="op_product_fast_moving_parts_form" model="ir.ui.view">
<field name="name">Configure Fast Moving Parts</field>
<field name="model">fastmovingparts.config.settings</field>
<field name="arch" type="xml">
<form string="FastMoving">
<header>
<button string="Apply" type="object" name="execute" class="oe_highlight"/>
or
<button string="Cancel" type="object" name="cancel" class="oe_link"/>
</header>
<separator string="Configure Fast Moving Parts"/>
<group name="Configure Fast Moving Parts">
<field string="Minimum Quantity" name="fast_moving_parts_min_qty"/>
</group>
<group>
<field string="Interval" name="fast_moving_parts_chk_interval"/>
</group>
</form>
</field>
</record>
It is updating the settings when clicking on the Apply button.
Here I have one more requirement that I need to open a wizard on clicking Apply button which will display products tree. How can I achieve this?
Thanks in advance
I didn't get your question, but I think that you want to open a wizard on clicking Apply button which will display products tree.