Open pop up form in edit mode - odoo

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>

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?

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

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.

Odoo - calculation on add or edit of one2many field

I have customer and deposit field in customer form which is one2many actually but user add a line in deposit and submit or edit some existing. I want to do some calculations on that event . I tried onchange and compute both but its not working.
add or edit One2many fields is FormView.
so you just put the field what you what to do calculate in FormView *.xml
Ex. with my SUM fields
<record model="ir.ui.view" id="view_nstda_bst_dbill_form">
<field name="name">nstda.bst.dbill.form</field>
<field name="model">nstda.bst.dbill</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="nstda_bst_dbill" class="nstda_bst_dbill_form" >
<group>
<field name="status" invisible="1" />
<field name="matno" />
<!-- <field name="matdesc" /> -->
<label for="balance" />
<div>
<field name="balance" style="width: 20%%" />
<field name="uom_1" style="width: 10%%;"
attrs="{'invisible':[('matno','=',False)]}" />
</div>
<label for="balance_rs" />
<div>
<field name="balance_rs" style="color:Red;width: 20%%" />
<field name="uom_2" style="width: 10%%;"
attrs="{'invisible':[('matno','=',False)]}" />
</div>
<label for="qty" />
<div>
<field name="qty" style="width: 20%%"
attrs="{'required':[('status','in',['draft','edit',False])]}" />
<field name="uom" style="width: 10%%;"
attrs="{'invisible':[('matno','=',False)]}" />
</div>
<!-- <field name="unitprice" /> -->
<label for="unitprice" />
<div>
<field name="unitprice" style="width: 20%%" />
<field name="currency" style="width: 10%%;" />
</div>
<field name="sum" invisible="1" />
<field name="dbill_discount_sum" invisible="1" />
</group>
</form>
</field>
</record>
and the *.py side is...
Ex.
#api.one
#api.onchange('qty','matno')
#api.depends('qty','matno')
def _set_sum(self):
self.sum = self.unitprice * self.qty
sum = fields.Float(string="summary", store=True, compute='_set_sum')
matno = fields.Many2one('bst.stock', 'matno')
qty = fields.Integer('qty')

How can I delete the "sheet" node keeping its content intact?

I would like to remove the node <sheet></sheet> from a form view. For instance, I have this view:
<record id="view_account_period_form" model="ir.ui.view">
<field name="name">account.period.form</field>
<field name="model">account.period</field>
<field name="arch" type="xml">
<form string="Account Period">
<header>
[...]
</header>
<sheet>
<group>
<group>
<field name="name"/>
<field name="fiscalyear_id" widget="selection"/>
<label for="date_start" string="Duration"/>
<div>
<field name="date_start" class="oe_inline" nolabel="1"/> -
<field name="date_stop" nolabel="1" class="oe_inline"/>
</div>
</group>
<group>
<field name="code"/>
<field name="special"/>
<field name="company_id" widget="selection" groups="base.group_multi_company"/>
</group>
</group>
</sheet>
</form>
</field>
</record>
I would like to convert it in this other view without the node, but keeping all the elements within it:
<record id="view_account_period_form" model="ir.ui.view">
<field name="name">account.period.form</field>
<field name="model">account.period</field>
<field name="arch" type="xml">
<form string="Account Period">
<header>
[...]
</header>
<group>
<group>
<field name="name"/>
<field name="fiscalyear_id" widget="selection"/>
<label for="date_start" string="Duration"/>
<div>
<field name="date_start" class="oe_inline" nolabel="1"/> -
<field name="date_stop" nolabel="1" class="oe_inline"/>
</div>
</group>
<group>
<field name="code"/>
<field name="special"/>
<field name="company_id" widget="selection" groups="base.group_multi_company"/>
</group>
</group>
</form>
</field>
</record>
Is that possible or I need to override the complete code again?
Maybe something similar to:
<xpath expr="//form/sheet" position="replace">
<!-- [...] -->
</xpath>
There is an open issue in Git Hub asking for solving this here, but I think that maybe anyone knows how to do it without programming a new feature in Odoo.
Just use fields_view_get:
from lxml import etree
def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
res = models.Model.fields_view_get(self, cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar, submenu=submenu)
if view_type == 'form':
doc = etree.XML(res['arch'])
for sheet in doc.xpath("//sheet"):
parent = sheet.getparent()
index = parent.index(sheet)
for child in sheet:
parent.insert(index, child)
index += 1
parent.remove(sheet)
res['arch'] = etree.tostring(doc)
return res
improved in case of oe_chatting presence
I am from the future. I found a module time ago that made wider forms in a much easier way: web_sheet_full_width. It works for all the forms. The sheet is not removed, but the result is almost the same because the form fits in the entire screen with full width.

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"/>