proper way to replace view form - odoo

I need to override account.account_aged_balance_view in order to hide a field (Period Length (days)) as well add new field in the same time.
I tried the following in my custom module view:
<openerp>
<data>
<record id="account_aged_balance_view" model="ir.ui.view">
<field name="name">Aged Partner Balance</field>
<field name="model">account.aged.trial.balance</field>
<field name="inherit_id" ref="account.account_aged_balance_view" />
<field name="arch" type="xml">
<form string="Report Options">
<separator string="Aged Partner Balance"/>
<label string="Dariel Partner Balance is a more detailed report of your receivables by intervals. When opening that report, Odoo asks for the name of the company, the Start Date and the size of the interval to be analyzed (in days). Odoo then calculates a table of credit balance by start Date. So if you request an interval of 30 days Odoo generates an analysis of creditors for the past month, past two months, and so on. "/>
<group col="4">
<field name="date_from"/>
<newline/>
<field name="result_selection" widget="radio"/>
<field name="target_move" widget="radio"/>
</group>
<field name="journal_ids" required="0" invisible="1"/>
</form>
</field>
</record>
</data>
</openerp>
those XML appended to the modal form instead of replacing the original form, like shown in the image.
so, am I doing it right (ofcourse it's not right) or how the proper way of doing it?

You can both replace the whole form view or remove and add only the fields you want. You have to use the xpath to do that.
To replace the whole view:
<record id="account_aged_balance_view" model="ir.ui.view">
<field name="name">Aged Partner Balance</field>
<field name="model">account.aged.trial.balance</field>
<field name="inherit_id" ref="account.account_aged_balance_view" />
<field name="arch" type="xml">
<xpath expr='//form' position='replace'>
< your form view >
</xpath>
</field>
</record>
Or you can remove only what you don't want and add what you want with:
<record id="account_aged_balance_view" model="ir.ui.view">
<field name="name">Aged Partner Balance</field>
<field name="model">account.aged.trial.balance</field>
<field name="inherit_id" ref="account.account_aged_balance_view" />
<field name="arch" type="xml">
<xpath expr='//field[#name="period_length"]' position='replace'/>
<xpath expr='//field[#name=" < name of the field you want to put yours after > "]' position='after'>
<field name=' < your field name > '/>
</xpath>
</field>
</record>
I did not try it, but it should work.

Related

how to make an odoo field invisible if a many2many field value is "rice"

I am trying to make a duration character field visible 'only if' parent field called category_ids Many2Many field value "Non-Permanent" is selected. I have tried so many things but seems not working. Below is my code snippet
Model:
class hr_employee(models.Model):
_inherit = 'hr.employee'
identification_id = fields.Char(string="Employee No")
duration = fields.Char(string="Duration")
View:
<!-- Employee Form View -->
<record model="ir.ui.view" id="hr_custom_form_view">
<field name="name">hr.custom</field>
<field name="model">hr.employee</field>
<field name="inherit_id" ref="hr.view_employee_form"/>
<field name="groups_id" eval="[(4, ref('base.group_hr_user'))]"/>
<field name="arch" type="xml">
<xpath expr="//field[#name='user_id']" position="after">
<field name="duration"/>
</xpath>
</field>
</record>

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 to make display like sales order lines in odoo

I am a newbie in odoo development, can someone tell me how to make display like in picture sales order line in odoo, Thank you before
This is One2many field in Odoo
to made one like this you have to add some things like this:
In python code
from openerp import fields,models
class sale_order(models.Model):
_inherit='sale.order'
field_One2many=field.One2many('sale.order.line','order_id','Order')
sale_order()
class sale_order_line(models.model):
_inherit='sale.order.line'
order_id=fields.Many2one('sale.order','Order')
sale_order_line()
and you have some code for the view in your Xml file like:
<record model="ir.ui.view" id="view_test">
<field name="name">sale.order.form</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale_order.form_view_id"/>
<field name="arch" type="xml">
<data>
<xpath expr="pass of position" position="the postion">
<field name='field_One2many'>
<tree>
<!-- Your Fields in the view -->
</tree>
</field>
</xpath>
</data>
</field>
</record>
and done

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.

How can I call a template from an inherited form view in Odoo 8

I am a beginner to Odoo 8.
I want to use the template (template id = "Variants") that is in the website_sale module in the form view of "Order lines" that has an external_id (ref="sale.view_order_form").
so I made inheritance like this:
<record id="multiple_variante_sale_order_form" model="ir.ui.view">
<field name="name">sale.order.form</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<xpath expr="//notebook/page/field/form/group/group/field[#name='product_id']" position="after">
-- here I want to call the template of the wesite_sale <template id="Variants" > --
</xpath>
</field>
Can I do this? If yes, how?