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')
Related
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>
please, i want to change the address format in customer form view odoo? how can i do that?.
I tried to change the code to XML but nothing changes!
<xpath expr="//div[#class='o_address_format']" position="replace">
<div class="o_address_format">
<field name="street" placeholder="Street..." class="o_address_street"/>
<field name="city" placeholder="City" class="o_address_city"/>
<field name="state_id" class="o_address_state" placeholder="State" options='{"no_open": True}'/>
<field name="zip" placeholder="Code postal"/>
<field name="country_id" placeholder="Country" class="o_address_country" options='{"no_open": True, "no_create": True}'/>
</div>
</xpath>
Finally there was another module that inherited the street field, so my code doesn't work; so the solution is to make the changes I wanted in the first module.
So my problem is solved
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.
I create two class hr_comp and hr_applicant
after i create lien between hr_comp and hr_applicant with the id comp_ids .
i create a widget in the model hr_applicant .
<notebook colspane="1">
<page string="Compétences">
<field name="comp_ids" colspan="4" nolabel="1" widget="one2many_list">
<tree string="compétence" editable="bottom">
<field name="cat_id" />
<!-- ici c'est l'appel de la fonction au niveau de l wml -->
<field name="niv" />
<field name="tech" />
</tree>
</field>
</page>
</notebook>
helpi want to create a filterr with the field cat_id but it doesnt work
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"/>