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

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.

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 do I link Odoo clickable statusbar with the workflow?

I have defined state actions, buttons, and the workflow. They work just fine, the problem is when I tried to add a clickable statusbar and everytime I click the status bar, it won't actually do anything other than changing the record's state.
How do I link the statusbar to the workflow/actions?
model.py
def action_state_draft(self, cr, uid, ids):
self.write(cr, uid, ids, { 'state' : 'draft' })
return True
def action_state_confirmed(self, cr, uid, ids):
self.write(cr, uid, ids, { 'state' : 'confirmed' })
return True
def action_state_posted(self, cr, uid, ids):
self.write(cr, uid, ids, { 'state' : 'posted' })
return True
def action_state_cancelled(self, cr, uid, ids):
self.write(cr, uid, ids, { 'state' : 'cancelled' })
return True
def hello_world(self):
print "Hello World!"
def hello_world_second(self):
print "Hello World Second!"
model_view.xml
<header>
<button name="action_state_confirmed" string="Confirm" states="draft" />
<button name="action_state_posted" string="Post" states="confirmed" />
<button name="action_state_cancelled" string="Cancel" states="draft,confirmed,posted" />
<field name="state" widget="statusbar" clickable="True" statusbar_visible="draft,confirmed,posted,cancelled"/>
</header>
model_workflow.xml
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<record id="ig_account_voucher_wkf" model="workflow">
<field name="name">ig.account.voucher.wkf</field>
<field name="osv">ig.account.voucher</field>
<field name="on_create">True</field>
</record>
<record id="act_draft" model="workflow.activity">
<field name="wkf_id" ref="ig_account_voucher_wkf"/>
<field name="name">draft</field>
<field name="flow_start">True</field>
</record>
<record id="act_confirmed" model="workflow.activity">
<field name="wkf_id" ref="ig_account_voucher_wkf"/>
<field name="name">confirmed</field>
<field name="action">
write({'state':'confirmed'})
hello_world()
hello_world_second()
</field>
<field name="kind">function</field>
</record>
<record id="act_posted" model="workflow.activity">
<field name="wkf_id" ref="ig_account_voucher_wkf"/>
<field name="name">posted</field>
<field name="action">write({'state':'posted'})</field>
<field name="kind">function</field>
</record>
<record id="act_posted" model="workflow.activity">
<field name="wkf_id" ref="ig_account_voucher_wkf"/>
<field name="name">cancelled</field>
<field name="action">write({'state':'cancelled'})</field>
<field name="kind">function</field>
<field name="flow_stop">True</field>
</record>
<record id="transition_draft_confirmed" model="workflow.transition">
<field name="act_from" ref="act_draft"/>
<field name="act_to" ref="act_confirmed"/>
<field name="condition">True</field>
<field name="signal">action_state_confirmed</field>
</record>
<record id="transition_confirmed_posted" model="workflow.transition">
<field name="act_from" ref="act_confirmed"/>
<field name="act_to" ref="act_posted"/>
<field name="condition">True</field>
<field name="signal">action_state_posted</field>
</record>
<record id="transition_confirmed_cancelled" model="workflow.transition">
<field name="act_from" ref="act_confirmed"/>
<field name="act_to" ref="act_posted"/>
<field name="condition">True</field>
<field name="signal">action_state_cancelled</field>
</record>
</data>
</openerp>
Another relevant little question: Why do we need workflow instead of just using buttons and actions?
In your code you have missing commas on workflow action when u pass the multiple method in workflow action.
please make is correct first
<record id="act_confirmed" model="workflow.activity">
<field name="wkf_id" ref="ig_account_voucher_wkf"/>
<field name="name">confirmed</field>
<field name="action">
write({'state':'confirmed'}),
hello_world(),
hello_world_second()
</field>
<field name="kind">function</field>
</record>
Another Answer of your Question is :
Why Work flow is needed instead of button ??
The Main Goal is that the work flow is define as the business process flow.
Another goals are :
description of document evolution in time
automatic trigger of actions if some conditions are met
management of company roles and validation steps
management of interactions between the different objects/modules
graphical tool for visualization of document flows
I hope this should helpful for you ..:)

ODOO 8 on_change

Please I am facing somes problems with the new odoo 8 api, I have the following classes
class TypeProcessus(models.Model):
_name = 'atom.promaintenance.type.processus'
name = fields.Char()
id_phases = fields.One2many('atom.promaintenance.phases','id_processus','Liste des Phases')
class Phases(models.Model):
_name = 'atom.promaintenance.phases'
name = fields.Char()
autoriserCommentaire = fields.Boolean()
autoriserPiecesJointes = fields.Boolean()
id_processus = fields.Many2one('atom.promaintenance.type.processus')
parent_id = fields.Many2one('atom.promaintenance.phases','Phase Parent', select=True, ondelete='cascade')
commentaire = fields.Text()
#api.one
#api.onchange('name')
def phases_write(self):
print 'test'
<record model="ir.ui.view" id="atom_promaintenance_type_processus">
<field name="name">atom.promaintenance.type.processus.form</field>
<field name="model">atom.promaintenance.type.processus</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Type Processus" >
<sheet>
<h1>UPDATED</h1>
<field name="name" />
<tree string="note_evaluation_tree" editable="bottom">
<field name="id_phases" />
</tree>
</sheet>
</form>
</field>
</record>
First of all my problem is when Creating a new Processus, and adding phases, there is a relation parent child between phases and the drop down list for parent stay empty unless u save the processus to make them available.
i managed to add onChange event to the phases to persist them to database but i can't figure out how to save those records with the new api system, thank you
If you mean what I understand, you need to use the widget one2many_list in the XML code, which by the way, I think is wrong. It should be something like this:
<record model="ir.ui.view" id="atom_promaintenance_type_processus">
<field name="name">atom.promaintenance.type.processus.form</field>
<field name="model">atom.promaintenance.type.processus</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Type Processus" >
<sheet>
<h1>UPDATED</h1>
<field name="name" />
<field name="id_phases" widget="one2many_list">
<tree string="note_evaluation_tree" editable="bottom">
<field name="name"/>
<field name="autoriserCommentaire"/>
<field name="autoriserPiecesJointes"/>
<field name="parent_id"/>
<field name="commentaire"/>
</tree>
</field>
</sheet>
</form>
</field>
</record>
The widget will allow you to add phases for a processus and then save it.
The new API uses self for all the record modifications. So in your case, if you want to change the name, write like this:
#api.one
#api.onchange('name')
def onchange_name(self):
self.name = 'what you want to save'

OpenERP tree view

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>