Openerp 6.1 put product category in sale order line - odoo

I want to show the product category in the sale.order.line.tree view of a sales order with the following code which I wrote. It shows the category button under the group by button but on clicking it, I get the following error and I have don't know how to solve the bug:assert groupby_def and groupby_def._classic_write, "Fields in 'groupby' must be regular database-persisted fields (no function or related fields), or function fields with store=True"
AssertionError: Fields in 'groupby' must be regular database-persisted fields (no function or related fields), or function fields with store=True
Here is my code:
from osv import fields, osv<code>
class sales_order_line_category(osv.osv):
_name='sale.order.line'
_inherit='sale.order.line'
_columns={'categ_id': fields.related('product_id', 'categ_id', type='many2one', relation='product.categ_id'),
}
sales_order_line_category()
My view:
`<?xml version="1.0" encoding="utf-8"?>
<record id="view_sale_orderlinecategory" model="ir.ui.view">
<field name="name">sale.order.line.categoryinherit</field>
<field name="model">sale.order.line</field>
<field name="type">tree</field>
<field name="inherit_id" ref="sale.view_order_line_tree"/>
<field name="arch" type="xml">
<field name="name" position="after">
<field name="categ_id" string="Category"/>
</field>
</field>
</record>
<record id="view_sale_orderlinecategory2" model="ir.ui.view">
<field name="name">sale.order.line.categoryinherit2</field>
<field name="model">sale.order.line</field>
<field name="type">search</field>
<field name="inherit_id" ref="sale.view_sales_order_uninvoiced_line_filter"/>
<field name="arch" type="xml">
<group expand="0" string="Group By..." >
<filter string="Category of Product" icon="terp-stock_symbol-selection" name="Category" context="{'group_by':'categ_id'}"/>
</group>
</field>
</record>
<record id="view_sale_orderlinecategory3" model="ir.ui.view">
<field name="name">sale.order.line.categoryinherit3</field>
<field name="model">sale.order,line</field>
<field name="type">search</field>
<field name="inherit_id" ref="sale.view_sales_order_uninvoiced_line_filter"/>
<field name="arch" type="xml">
<field name="name" position="before">
<field name="categ_id" string="Category"/>
</field>
</field>
</record>
</data>
`

WOuld you please try with following code replace?
'categ_id': fields.related('product_id', 'categ_id', type='many2one', relation='product.category', store=True),
Check that your field categ_id must be appear in tree view of sale.order.line where you try to do group by categ_id
Hope this help

Related

How to hide discount field in Invoice form? Odoo

I have try to hide discount field in invoice form by xpath. However it doesn't work.
The following is my code :
<odoo>
<data>
<record model="ir.ui.view" id="hidden_discount">
<field name="name">account.invoice.hidden.discount</field>
<field name="model">account.invoice</field>
<field name="inherit_id" ref="account.invoice_form"/>
<field name="arch" type="xml">
<xpath expr="//field[#name='discount']" position="attributes">
<attribute name="invisible">True</attribute>
</xpath>
</field>
</record>
</data>
</odoo>
Do you have any solution or suggestion?
There is no direct form view design for One2many field. So we need to upgrade account.invoice.line form view directly.
Try with following code.
<record model="ir.ui.view" id="hidden_discount">
<field name="name">account.invoice.line.hidden.discount</field>
<field name="model">account.invoice.line</field>
<field name="inherit_id" ref="account.view_invoice_line_form"/>
<field name="arch" type="xml">
<field name="discount" position="attributes">
<attribute name="invisible">1</attribute>
</field>
</field>
</record>

Odoo not displayed field

I get a problem with displaying custom field in sale order view.
sale_order.py
...
'typeship' : fields.many2one('vips_shop.delivery', string="Type delivery", readonly=False),
'usersess' : fields.many2one('vips_vc.session', string="Session customer", readonly=False),
...
sale_order.xml
<record model="ir.ui.view" id="sale_order_usersess_form_view">
<field name="name">order.usersess</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<field name="client_order_ref" position="after">
<field name="usersess" string="User Session ID"/>
</field>
</field>
</record>
<record model="ir.ui.view" id="sale_order_typeship_form_view">
<field name="name">order.typeship</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<field name="client_order_ref" position="after">
<field name="typeship" string="Type shipping"/>
</field>
</field>
</record>
As result i received this: field usersess displayed fine, typeship - not displayed.
Why is it happening? All fields for usersess and typeship is equal.
Thanks for Hardik Patadia
why are you having two separate views for showing two fields? Why are
you not showing both of them in single inherited view? I think view
priority may help you
When I'm showing in single view all displayed fine:
<record model="ir.ui.view" id="sale_order_usersess_form_view">
<field name="name">order.usersess</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<field name="client_order_ref" position="after">
<field name="usersess" string="User Session ID"/>
<field name="typeship" string="Type shipping"/>
</field>
</field>
</record>

OpenERP - implementing something similar to stock.picking.in

The way stock.picking.in is implemented in openERP is interesting. I am trying to do something similar with purchase orders.
Stock.picking.in inherits from stock.picking, customizes a few columns and defaults and declares the table as stock_picking. On the UI side, a form view is inherited from view_picking_form and the model used is stock.picking.in.
I am trying to do something similar by creating a special purchase order. The problem is that the form for the special PO never gets picked up. It always shows a dynamic view with all fields of the PO dumped in some default manner. The developer mode also does not show the right form view.
When I check Settings -> User Interface -> Views, it does show the view properly but doesn't display it when I create new special PO.
Here is the code:
class my_purchase_order(osv.osv):
_name = "purchase.order"
_inherit = "purchase.order"
_columns={
...
}
my_purchase_order()
class my_purchase_order_special(osv.osv):
_name = 'purchase.order.my_special'
_inherit = "purchase.order"
_table = "purchase_order"
_columns = {...
}
my_purchase_order_special()
<record id="po_my_special_form" model="ir.ui.view">
<field name="name">po_my_special_form</field>
<field name="model">purchase.order.my_special</field>
<field name="type">form</field>
<field name="inherit_id" ref="purchase.purchase_order_form" />
<field name="arch" type="xml">
...
</field>
</record>
<record id="po_my_special_tree" model="ir.ui.view">
<field name="name">po_my_special_tree</field>
<field name="model">purchase.order.my_special</field>
<field name="arch" type="xml">
<tree fonts="bold:message_unread==True" colors="grey:state=='cancel';blue:state in ('wait','confirmed');red:state in ('except_invoice','except_picking')" string="Purchase Order">
<field name="message_unread" invisible="1"/>
<field name="name" string="Reference"/>
<field name="date_order" />
<field name="partner_id"/>
<field name="company_id" groups="base.group_multi_company" widget="selection"/>
<field name="minimum_planned_date" invisible="context.get('quotation_only', False)"/>
<field name="origin"/>
<field name="amount_untaxed" sum="Total Untaxed amount" string="Untaxed"/>
<field name="amount_total" sum="Total amount"/>
<field name="state"/>
</tree>
</field>
</record>
<record id="action_po_my_special_tree" model="ir.actions.act_window">
<field name="name">Special Purchase Orders</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">purchase.order.my_special</field>
<field name="view_mode">tree,form,graph,calendar</field>
<field name="context">{}</field>
<field name="domain">[('state','=','draft')]</field>
<field name="search_view_id" ref="purchase.view_purchase_order_filter"/>
</record>
<record id="action_po_my_special_form" model="ir.actions.act_window.view">
<field eval="2" name="sequence"/>
<field name="view_mode">form</field>
<field name="view_id" ref="po_my_special_form"/>
<field name="act_window_id" ref="action_po_my_special_tree"/>
</record>
Please advise. Thanks in advance.
Turns out I was missing view records:
<record id="action_po_my_special_tree2" model="ir.actions.act_window.view">
<field eval="1" name="sequence"/>
<field name="view_mode">tree</field>
<field name="view_id" ref="po_my_special_tree"/>
<field name="act_window_id" ref="action_po_my_special_tree"/>
</record>
<record id="action_po_my_special_form2" model="ir.actions.act_window.view">
<field eval="2" name="sequence"/>
<field name="view_mode">form</field>
<field name="view_id" ref="po_my_special_form"/>
<field name="act_window_id" ref="action_po_my_special_tree"/>
</record>

readonly in invoice lines based on a value in line

I have a field 'uneditable' in 'account.invoice.line'.
I want to disable editing the line record if uneditable is true but creating enw line should be allowed.
my view code is as follows
<record model="ir.ui.view" id="invoice_supplier_form_ext">
<field name="name">account.invoice.supplier.form</field>
<field name="model">account.invoice</field>
<field name='inherit_id' ref='account.invoice_supplier_form'/>
<field name="type">form</field>
<field name="arch" type="xml">
<data>
<field name="product_id" position="before">
<field name="uneditable" invisible="1"/>
</field>
<field name="quantity" position="attributes">
<attribute name="attrs">{'readonly': [('uneditable','=', True)]}</attribute>
</field>
</data>
</field>
</record>
Please suggest me what i am doing wrong. I am getting error with this code in view and does not make the line readonly.
Actually your view is wrong. You have defined the fields 'quantity' and 'uneditable' in account.invoice.line and you are adding then in the invoice view. Please check the invoice_supplier_form view and add the fields correctly in the view.
<record model="ir.ui.view" id="invoice_line_form_ext">
<field name="name">account.invoice.line.form</field>
<field name="model">account.invoice.line</field>
<field name='inherit_id' ref='account.view_invoice_line_form'/>
<field name="type">form</field>
<field name="arch" type="xml">
<data>
<field name="product_id" position="before">
<field name="uneditable" invisible="1"/>
</field>
<field name="quantity" position="attributes">
<attribute name="attrs">{'readonly': [('uneditable','=', True)]}</attribute>
</field>
</data>
</field>
</record>

How to add a field into an inherited view's tab/page?

How can I inherited a view to add a field into the "Sessions" tab ?
e.g :
<record model="ir.ui.view" id="partner_sessions_form_view">
<field name="name">partner.sessions.name</field>
<field name="model">res.partner</field>
<field name="type">form</field>
<field name="inherit_id" ref="base.view_partner_form" />
<field name="arch" type="xml">
<xpath expr="/form/notebook/page[#string='Notes']" position="after">
<page string="Sessions">
<field name="session_ids" nolabel="1" colspan="4"/>
</page>
</xpath>
</field>
</record>
This adds a page, but how would I add a field in the page Sessions ?
If you want to add a field to page 'Sessions' that you have created above, then you should provide
<record model="ir.ui.view" id="partner_sessions_form_view_again_inherited">
<field name="name">partner.sessions.name.inherited</field>
<field name="model">res.partner</field>
<field name="type">form</field>
<field name="inherit_id" ref="partner_sessions_form_view" />
<field name="arch" type="xml">
<xpath expr="//field[#name='session_ids']" position="before">
<field name="new_field1" nolabel="1" colspan="4"/>
</xpath>
</field>
</record>
if you want to add add a field to the session_ids tree or form view, then
<xpath expr="//field[#name='session_ids']/tree/field[#name='already_existing_field']" position="after">
<field name="new_field1" />
</xpath>
You need to find that field in side you page Session
like this (but that page has to be their in view):
<xpath expr="//page[#string='Sessions']/field[#name='some_field'] position="after">
<field name="session_ids" nolabel="1" colspan="4"/>
</xpath>
Thanks
This is covered pretty well in the documentation. The simplest case is to just add your new field after an existing one. In this example, you're placing the relation_ids field after the lang field.
<record model="ir.ui.view" id="view_partner_form4">
<field name="name">res.partner.form.inherit4</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="arch" type="xml">
<field name="lang" position="after">
<field name="relation_ids"/>
</field>
</field>
</record>
If that field appears in more than one place, you'll have to use an XPath element. For example, if the lang field appears in a subview's tree view and its form view.