OpenERP tree view - odoo

I want to replace one of the defaults buttons in treeview header by one with a funcionality made by my... I try using xpath in this way but not worked
<field name= "types_id" colspan="8" nolabel="1">
<tree options='{"deletable": false, "addable":null, "isClarkGable": false}'>
<field name="type_id"/>
<field name="fundamentation"/>
<xpath expr="//tree/button[#string='Add']" position="replace">
<button name="button_cancel" string="Mark to Cancel" type="object" icon="gtk-cancel"/>
</xpath>
</tree>
</field>

The option you are using is for field not for the tree tag. so your xml will be like,
<field name= "types_id" colspan="8" nolabel="1" options='{"deletable": false, "addable":null}'>
<tree delete="false" string='YOUR STRING'>
<field name="type_id"/>
<field name="fundamentation"/>
<xpath expr="//tree/button[#string='Add']" position="replace">
<button name="button_cancel" string="Mark to Cancel" type="object" icon="gtk-cancel"/>
</xpath>
</tree>
</field>

Related

How to display button when checkbox is true if both are from different models.?

I am trying to add custom settings in purchase order.
In that I am facing problem to link action of checkbox with button. I am trying to display a button when the checkbox in purchase settings is "True" if not then do not display.
Here's my code:
I am using wizard which inherits purchase.config.settings to add a checkbox "allow_settings"
class ConfigSettingsWizard(models.TransientModel):
_inherit = 'purchase.config.settings'
allow_settings = fields.Boolean("settings")
inherited_purchase_config_settings_views.xml:
<record id="inherited_purchase_config_settings_form_views" model="ir.ui.view">
<field name="model">purchase.config.settings</field>
<field name="inherit_id" ref="purchase.view_purchase_configuration"/>
<field name="arch" type="xml">
<xpath expr="//field[#name='group_warning_purchase']" position="after">
<label string="Setting"/>
<div>
<field name="allow_settings" class="oe_inline"/>
<label for="allow_settings"/>
</div>
</xpath>
</field>
</record>
And a model "Mymodel" which inherit purchase.order
class MyModel(models.Model):
_inherit = 'purchase.order'
xml:
<field name="model">purchase.order</field>
<field name="inherit_id" ref="purchase.purchase_order_form"/>
<field name="arch" type="xml">
<xpath expr="//button[#name='button_cancel']" position="after">
<button name="add_button" string="Add" type="object" class="btn-primary" />
</xpath>
</field>
Both button and the checkbox are in different models and are inherited from different models.
Is there any way to get data from one model to another model?
Try below code.
class ConfigSettingsWizard(models.TransientModel):
_inherit = 'purchase.config.settings'
allow_settings = fields.Selection([(0, 'Not Visible'),(1, 'Make visible')],
"Settings", implied_group='your_module.group_name')
In xml file:
<field name="model">purchase.order</field>
<field name="inherit_id" ref="purchase.purchase_order_form"/>
<field name="arch" type="xml">
<xpath expr="//button[#name='button_cancel']" position="after">
<button name="add_button" string="Add" type="object" class="btn-primary" groups="your_module.group_name" />
</xpath>
</field>
Hope it will help you.

odoo many2many show selection Odoo10

we have a list of items in one model named us_inventory_line. We have another model named ladings...
class inventory_line(models.Model):
# ...
lading_item = fields.Many2one('res.lading', ondelete='set null', string="lading", index=True)
class Lading(models.Model):
# ...
us_inventory_line_item = fields.One2many(comodel_name='rodals.us_inventory_line', string="shippments", inverse_name='lading_item')
In the form, we have just simply put the field that represent one2many:
<!-- Form -->
<record model="ir.ui.view" id="us_inventory_line_form_view">
<field name="name">lading.form</field>
<field name="model">rodals.lading</field>
<field name="arch" type="xml">
<form string="Invetory Line Form">
<sheet>
<group>
<field name="delivery_date"/>
<field name="us_inventory_line_item"/>
</group>
</sheet>
</form>
</field>
</record>
When the application is opened, when the user opens the lading page, he is only able to add new us_inventory_line.
How do we go about in order to connect the tow ? Like the user need to choose, from a list of us_inventory_line that does not have a lading (because if its has lading, this means that its already shipped).
Thank you very much for the help !
<record model="ir.ui.view" id="us_inventory_line_form_view">
<field name="name">lading.form</field>
<field name="model">rodals.lading</field>
<field name="arch" type="xml">
<form string="Invetory Line Form">
<sheet>
<group>
<field name="delivery_date"/>
<field name="us_inventory_line_item">
<tree string="US Inventory Item">
<field name="lading_item"/>
</tree>
</field>
</group>
</sheet>
</form>
</field>
</record>

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.

Can't remove top "Save" button from Odoo

I want to remove the top "Save" button from the formview of my custom module.
I know that we perform this by setting write/create to false in the XML, which I did and can't figure out why it is still there.
My view:
<record id="view_module_genall_form" model="ir.ui.view">
<field name="name">module.genall.form</field>
<field name="model">module.genall</field>
<field name="arch" type="xml">
<form string="Automatically generate bills" edit="false" create="false" delete="false" write="false">
<button name="generate_all" type="object" string="Generate bills" icon="oe_highlight"/>
</form>
</field>
</record>
The related action:
<record model="ir.actions.act_window" id="action_module_genall">
<field name="name">Automatically generate bills</field>
<field name="res_model">alkivi.genall</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="view_id" ref="view_module_genall_form" />
</record>
Do you have an idea ? Thanks!
From it's title it looks like the purpose of your form is to run a server method to perform some business logic.
For that you should use a Wizard instead of a regular Model: for that the module.genalshould be a models.TransientModel instead of a models.Model.

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