How to add a new button inside the action menu Odoo 12? - odoo

Im trying to add a button inside the action in the model named 'consultation', After clicking the button i need to open up the wizard i created follow,But im stuck in some errors
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="specialist_no_show" model="ir.ui.view">
<field name="name">specialist no show</field>
<field name="model">specialist.no.show</field>
<field name="arch" type="xml">
<form string="No Show">
<group>
<group>
<field name="partner_id" readonly="1"/>
</group>
</group>
<footer>
<button name="update_no_show" string="Confirm" type="object" class="btn-primary"/>
<button string="Cancel" class="btn-secondary" special="cancel"/>
</footer>
</form>
</field>
</record>
<act_window name="No Show"
id="specialist_no_show"
res_model="specialist_no_show" #model created for the wizard
binding_model="consultation" #model where i want to show the button in the action
binding_views="form"
view_mode="list"
target="new"
/>
</odoo>

I can spot some problems that you can try:
The XML ID for the form and the act_window must be different. In your example it is both specialist_no_show
The res_model must be specialist.no.show
The structure for the act_window is different depending on your Odoo Version (see below).
For Odoo Version 12.0
<act_window name="No Show"
id="action_specialist_no_show"
res_model="specialist.no.show"
src_model="consultation"
view_mode="form"
target="new"
/>
For Odoo Version 13.0
<act_window name="No Show"
id="action_specialist_no_show"
res_model="specialist.no.show"
binding_model="consultation"
view_mode="form"
target="new"
/>
Also, the error logs would be helpful as #Kenly suggested. Always post those.

Related

Place button in one2many field tree view

I want to add button in one2many tree view line. I have placed button in tree view and these button shows successfully.
But when i click on button, it display form define against one2many field instead of function call.
Need guidance how to call function/form on button click.
<page name="component_line_id" string="Component Lines">
<field name="component_line_id">
<tree>
<field name="purchase_order_id" required="1"/>
<field name="description"/>
<field name="payable_amount"/>
<field name="file_name" string="Attachment"/>
<button string="Create Bill" name="create_bill" type="object" class="oe_highlight" icon="fa-icon_you_like"/>
<button string="View Bill" name="view_bill" type="object" class="oe_highlight" icon="fa-icon_you_like"/>
</tree>
<form string="Component Lines">
<group>
<group>
<field name="purchase_order_id"/>
<field name="description"/>
<field name="payable_amount"/>
</group>
<group>
<field name="attachment_file" filename="file_name"/>
<field name="file_name" invisible="1"/>
</group>
</group>
</form>
</field>
</page>
I think you need to save the record first to be able to run the button. Are you sure it was not on edit mode?

Open pop up form in edit mode

Is it possible to have a one2many field in a form view that when you click it, it will pop open the form view of that one2many model but give the user the option to edit and save?
Currently, it pops open the form view of the corresponding model but it doesn't give edit option. Therefore users can only view the details.
I have tried using editable bottom. But this is for inline editing.
Thanks
Below is the example I am facing. If I click on the consultation_ids I get a pop-up form without the ability to edit it.
<record id="view_patient_form" model="ir.ui.view">
<field name="name">medical.record.form</field>
<field name="model">fhg.patient</field>
<field name="priority" eval="1"/>
<field name="arch" type="xml">
<form string="Patient">
<sheet>
<div class="container-fluid">
<field style="z-index: 100" name="image_medium" widget="image" class="openerp oe_left oe_avatar" nolabel="1" />
<div class="oe_title">
<field name="barcode_preview" readonly="1" />
<field name="unique_number" string="Ref:" readonly="1" />
<field name="legacy_unique_number" string="Legacy ref:" />
</div>
</div>
<notebook>
<page string="Outpatient">
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
<field name="consultation_ids" nolabel="1">
<tree>
<field name="date" string="Date" />
<field name="medical_specialty_id" string="Medical Specialty" />
<field name="consultation_type" string="Consultation Type" />
<field name="medical_staff_id" string="Medical Staff" />
<field name="medical_center_id" string="Medical Center" />
<field name="state" string="State" />
</tree>
</field>
</div>
</div>
</div>
</page>
</notebook>
</sheet>
</form>
</field>
</record>

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

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.

Customer Invoice validate button

I have created a button named 'Confirm' in customer invoice. When i click 'Confirm' button 'state1' will be 'confirmed'. I want to hide Validate button when 'state1'='draft' and show the Validate button when 'state1'='confirmed'. I tried below code but it is not working. Can anyone help me?
<!-- inherit account invoice form -->
<record id="invoice_form_inheritai" model="ir.ui.view">
<field name="name">account.invoice.form.inheritai</field>
<field name="model">account.invoice</field>
<field name="inherit_id" ref="account.invoice_form"/>
<field name="arch" type="xml">
<button name="invoice_print" position="after">
<field name="state1" invisible="1"/>
<button name="invoice_check" string="Confirm" type="object" attrs="{'invisible': [('state1','not in', ['draft'])]}" class="oe_highlight" groups="base.group_user"/>
</button>
<button name="invoice_open" position="replace">
<button name="invoice_open" state="draft" string="Validate" attrs="{'invisible': [('state1','!=', ['confirmed'])]}" groups="base.group_user"/>
</button>
</field>
</record>
<button name="invoice_open" string="Validate" attrs="{'invisible': [('state1','not in', ['confirmed']),('state','not in',['draft'])]}" groups="base.group_user"/>
Please avoid using both invisible attribute and states.
Try using 'states' instead of 'state'. And even attr won't be required. It will work automatically. Ex:
<button name="invoice_open" states="confirmed" string="Validate" groups="base.group_user"/>