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

Related

How to edit invoice template on Odoo15

I created custom fields in Odoo v15.
PROBLEM
Now I would like to add them to invoice template.
How I could do it?
You need to inherit the form view (account.invoice.form) and add your custom fields to the view. Or if you want to test the view you can enable debug mode and click "Edit FormView" at the top right of your form view to (temporarily) edit the form view directly.
See my example below:
<record id="account_invoice_form_custom" model="ir.ui.view">
<field name="name">account.invoice.form.custom</field>
<field name="model">account.invoice</field>
<field name="inherit_id" ref="account.invoice_form" />
<field name="arch" type="xml">
<field name="partner_id" position="after">
<field name="custom_field"/>
</field>
</field>
</record>

How can I show custom field only on stock internal transfer or delivery order move line in odoo 10

I have created a custom field in stock.move and now I need to show it only on Delivery Order or Internal Transfer move lines.
I am trying following code but its giving me an error.
Code is:
<record id="view_move_picking_tree_inherit1" model="ir.ui.view">
<field name="name">stock.move.tree</field>
<field name="model">stock.move</field>
<field name="inherit_id" ref="stock.view_move_picking_tree"/>
<field name="arch" type="xml">
<field name="product_id" position="after">
<field name="finish_item" nolabel="1" attrs="{'invisible':[('picking_id.picking_type_code', '=', 'outgoing')]}"/>
</field>
</field>
</record>
Error is:
Uncaught Error: Unknown field picking_id.picking_type_code in domain [["picking_id.picking_type_code","=","outgoing"]]
Anyone please help me about it.
Please replace your code with given below
<field name="finish_item" nolabel="1" attrs="{'invisible':[('picking_type_id.code', '=', 'outgoing')]}"/>

proper way to replace view form

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.

How to hide fields based on condition in odoo?

I have created few custom fields for products.Products appear in sales,purchase,warehouse and manufacturing module.I want to make my custom fields appear only in manufacturing module and hide everywhere else.So how to put condition on invisible attribute.I tried like this and got error as Unknown field _name in domain
attrs="{'invisible': [('_name', '!=', 'mrp.bom')]}"
Python file,
from openerp import fields,models, api
class product_template(models.Model):
_inherit = "product.template"
rim_weight = fields.Float(string='Rim Weight(KG)', readonly=True, compute='_compute_one_rim_weight')
width = fields.Float(string='Width(cm)',default='50')
length = fields.Float(string='Length(cm)',default='63')
gsm = fields.Float(string='Gram per square meter(gsm)',default='230')
Xml file,
<record id="product_template_form_view_dis_inherit" model="ir.ui.view">
<field name="name">product.template.common.form.dis.inherit</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_form_view"/>
<field name="arch" type="xml">
<xpath expr="//page[#string='Accounting']" position='after'>
<page string='Cover Page Paper'>
<group>
<field name="width"/>
<field name="length"/>
<field name="gsm"/>
<field name="rim_weight"/>
</group>
</page>
</xpath>
</field>
</record>
There are many ways to do this, however I suggest following options to you.
Modify an existing action and set context inside that and based on that context just write condition in view. (Remember here you need to override an action, and if you want to create another then you need to redefine menu to assign new action to that menu).
Create new view and set this view reference in an action of that model in which you want to show these fields. In new view you need to visible those fields, no need to extend product template existing view.
However the 1st solution is easy to achieve and 2nd one is lengthy.
Example of 1st solution:
<record id="action_name" model="ir.actions.act_window">
<field name="name">Name</field>
<field name="res_model">product.template</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="context" eval="{'is_manufacturing_model':True}" />
</record>
And then in view just write like this
<page string='Cover Page Paper'>
<group invisible="context.get('is_manufacturing_model',False)">
<field name="width"/>
<field name="length"/>
<field name="gsm"/>
<field name="rim_weight"/>
<group>
</page>

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?