Odoo Help
Odoo is the world's easiest all-in-one management software. It includes hundreds of business apps:
CRM
|
e-Commerce
|
Accounting
|
Inventory
|
PoS
|
Project management
|
MRP
|
etc.
How to add a Column in Sale Order? Gives ValidateError
I'm trying to add a new field 'Shipping' to Sale Order Line. Here's my code {v7]:
sales_quote.py:
from datetime import datetime, timedelta
from dateutil.relativedelta import relativedelta
import time
from openerp import pooler
from openerp.osv import fields, osv
from openerp.tools.translate import _
from openerp.tools import DEFAULT_SERVER_DATE_FORMAT, DEFAULT_SERVER_DATETIME_FORMAT, DATETIME_FORMATS_MAP, float_compare
import openerp.addons.decimal_precision as dp
from openerp import netsvc
import openerp.addons.sale
class sale_order(osv.Model):
_name='sale.order'
_inherit='sale.order'
_columns={
'shipng':fields.float('Shipping'),
}
sale.order()
sales_quote_view.xml:
<openerp>
<data>
<record model="ir.ui.view" id="moleac_quotation_form_view">
<field name="name">Sale New Quotation</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<data>
<xpath expr="//notebook/page[@string='Order Lines']/field[@name='order_line']/form[@string='Sales Order Lines']/group/group/field[@name='price_unit']" position="after">
<field name="shipng"/>
</xpath>
</data>
</field>
</record>
</data>
</openerp>
UPDATE: The above code installed. But, when I click on 'form view' in 'Sales->Quotations', error:
ERROR ERP_demo openerp.osv.orm: Can't find field 'shipng' in the following view parts composing the view of object model 'sale.order':
* Quotation Inherited View
Either you wrongly customized this view, or some modules bringing those views are not compatible with your current data model
2013-08-05 07:27:57,663 11349 ERROR ERP_demo openerp.netsvc: View error
Can't find field 'shipng' in the following view parts composing the view of object model 'sale.order':
* Quotation Inherited View
Either you wrongly customized this view, or some modules bringing those views are not compatible with your current data model
Traceback (most recent call last):
File "/home/naveen/eclipseworkspace/openerp-7.0-20130623-231037/openerp/netsvc.py", line 292, in dispatch_rpc
result = ExportService.getService(service_name).dispatch(method, params)
File "/home/naveen/eclipseworkspace/openerp-7.0-20130623-231037/openerp/service/web_services.py", line 626, in dispatch
res = fn(db, uid, *params)
File "/home/naveen/eclipseworkspace/openerp-7.0-20130623-231037/openerp/osv/osv.py", line 188, in execute_kw
return self.execute(db, uid, obj, method, *args, **kw or {})
File "/home/naveen/eclipseworkspace/openerp-7.0-20130623-231037/openerp/osv/osv.py", line 144, in wrapper
raise except_osv(inst.name, inst.value)
except_osv: ('View error', u"Can't find field 'shipng' in the following view parts composing the view of object model 'sale.order':\n * Quotation Inherited View\n\nEither you wrongly customized this view, or some modules bringing those views are not compatible with your current data model")
2013-08-05 07:27:57,665 11349 INFO ERP_demo werkzeug: 127.0.0.1 - - [05/Aug/2013 07:27:57] "POST /web/dataset/call_kw HTTP/1.1" 200 -
from openerp.osv import fields, osv
class sale_order(osv.osv): _inherit = 'sale.order' _columns = { 'shiping': fields.float('Shiping'), } sale_order()
<openerp> <data> <record model="ir.ui.view" id="view_order_form2_inherit"> <field name="name">sale.order.inherit2</field> <field name="model">sale.order</field> <field name="inherit_id" ref="sale.view_order_form"/> <field name="arch" type="xml"> <xpath expr="//sheet/group" position="inside"> <field name="shiping"/> </xpath> </field> </record> </data> </openerp>
<openerp> <data> <record id="moleac_quotation_form_view" model="ir.ui.view"> <field name="name">Quotation Inherited View</field> <field name="model">sales.quote</field> <field name="inherit_id" ref="sale.view_order_form" /> <field name="arch" type="xml"> <xpath expr="//field[@name='order_line']/form//field[@name='price_unit']" position="after"> <field name="shipng"/> </xpath> </field> </record> </data> </openerp>
@amp, Thanks for your reply. The edit you suggest didn't work. However the new code(above) installed. Please read the Q again for another error now.
I've linked to 'sale.order' only everywhere, and 'sale.order.line' isn't mentioned anywhere. I'm so sorry; I'm new at it. Please give the code if you can [ <!-- <pre><code></code></pre> --> format]
Amit, it installed just fine; but the new field isn't visible! :-o I want it to be visible in Sales->Quotation->Create New Quotation->the-table-below-where-we-enter-products(guess that's sales.order.lines).
Hello Naveen, If you want to add it on sale order line then inherit the sale order line object and then you can this field on order line.
None of the edits gave reqd results; I'd request that you run the code on your system & then post the one that works as desired. The fields are visible just above the sale.order.line part with this code, not in the lines.
This code will only add a new field on sale.order BUT NOT on the sale.order.line LIST!!!!!
Do something like that :
<openerp>
<data>
<record model="ir.ui.view" id="view_order_form2_inherit">
<field name="name">sale.order.inherit2</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='order_line']/form/group[1]/group[1]/field[@name='price_unit']" position="after">
<field name="shipng"/>
</xpath>
</field>
</record>
</data>
</openerp>
The Upgrade was successful; the field is visible. But, it's above the sales line, i.e above the product list & below the 'Customer Ref' field.
<xpath expr="//field[@name='order_line']/form/group[1]/group[2]/field[@name='price_unit']" position="after"> gives invalid-XML error. Prev line (by Amit) updates, but after kayni's update, no field is displayed.
Upgrade fails. invalid-XML error after edits given by you on 14th Aug [1030H GMT; 1600H IST]. Same issue as before.
None of the edits gave reqd results; I'd request that you run the code on your system & then post the one that works as desired.
Alex, please share your upgrade code, i need add custom column to sales order, tnks
My guess is that your python file is not being processed, so your new field is not created, and then the view fails to find it...
Check that you have your sales_quote.py
file referenced from the __init__.py
files...
Also, be sure to restart the server when you modify any python file (not needed if change is to xml file...)
I'd checked the ref in __init__.py before posting. Checked it again now, nothing wrong there.
try this one:
<record id="moleac_quotation_form_view" model="ir.ui.view">
<field name="name">moleac.quotation.form.view</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<xpath expr="//page[@string='Order Lines']" position="inside">
<page string="Order Lines">
<field name="order_line">
<form string="Sales Order Lines" version="7.0">
<header groups="base.group_user">
<button name="%(sale.action_view_sale_order_line_make_invoice)d" states="confirmed" string="Invoice" type="action" icon="terp-document-new"/>
<field name="state" widget="statusbar" statusbar_visible="draft,confirmed,done" statusbar_colors='{"exception":"red","cancel":"red"}'/>
</header>
<group>
<group>
<field name="state" invisible="1" />
<field name="product_id"
context="{'partner_id':parent.partner_id, 'quantity':product_uom_qty, 'pricelist':parent.pricelist_id, 'shop':parent.shop_id, 'uom':product_uom}"
groups="base.group_user"
on_change="product_id_change(parent.pricelist_id, product_id, product_uom_qty, product_uom, product_uos_qty, product_uos, name, parent.partner_id, False, True, parent.date_order, False, parent.fiscal_position, False, context)"/>
<label for="product_uom_qty"/>
<div>
<field
context="{'partner_id':parent.partner_id, 'quantity':product_uom_qty, 'pricelist':parent.pricelist_id, 'shop':parent.shop_id, 'uom':product_uom}"
name="product_uom_qty" class="oe_inline"
on_change="product_id_change(parent.pricelist_id,product_id,product_uom_qty,product_uom,product_uos_qty,product_uos,name,parent.partner_id, False, False, parent.date_order, False, parent.fiscal_position, True, context)"/>
<field name="product_uom" groups="product.group_uom" class="oe_inline oe_no_button"
on_change="product_uom_change(parent.pricelist_id,product_id,product_uom_qty,product_uom,product_uos_qty,product_uos,name,parent.partner_id, False, False, parent.date_order, context)"/>
</div>
<label for="product_uos_qty" groups="product.group_uos"/>
<div groups="product.group_uos">
<field name="product_uos_qty" class="oe_inline"/>
<field name="product_uos" options='{"no_open": True}' class="oe_inline"/>
</div>
<field name="price_unit"/>
<label for="discount" groups="sale.group_discount_per_so_line"/>
<div name="discount" groups="sale.group_discount_per_so_line">
<field name="discount" class="oe_inline"/> %%
</div>
</group>
<group>
<field name="tax_id" widget="many2many_tags" domain="[('parent_id','=',False),('type_tax_use','<>','purchase')]"/>
<field name="type"/>
<field name="th_weight"/>
<!-- we should put a config wizard for these two fields -->
<field name="address_allotment_id"/>
</group>
</group>
<label for="name"/>
<field name="name"/>
<div groups="base.group_no_one">
<label for="invoice_lines"/>
<field name="invoice_lines"/>
</div>
</form>
<tree string="Sales Order Lines" editable="bottom">
<field name="sequence" widget="handle"/>
<field name="state" invisible="1"/>
<field name="th_weight" invisible="1"/>
<field name="product_id"
context="{'partner_id':parent.partner_id, 'quantity':product_uom_qty, 'pricelist':parent.pricelist_id, 'shop':parent.shop_id, 'uom':product_uom}"
groups="base.group_user"
on_change="product_id_change(parent.pricelist_id, product_id, product_uom_qty, product_uom, product_uos_qty, product_uos, name, parent.partner_id, False, True, parent.date_order, False, parent.fiscal_position, False, context)"/>
<field name="name"/>
<field name="product_uom_qty"
context="{'partner_id':parent.partner_id, 'quantity':product_uom_qty, 'pricelist':parent.pricelist_id, 'shop':parent.shop_id, 'uom':product_uom}"
on_change="product_id_change(parent.pricelist_id, product_id, product_uom_qty, product_uom, product_uos_qty, product_uos, name, parent.partner_id, False, False, parent.date_order, False, parent.fiscal_position, True, context)"/>
<field name="shipng"/>
<field name="product_uom"
on_change="product_uom_change(parent.pricelist_id, product_id, product_uom_qty, product_uom, product_uos_qty, product_uos, name, parent.partner_id, False, False, parent.date_order, context)"
groups="product.group_uom" options='{"no_open": True}'/>
<field name="product_uos_qty" groups="product.group_uos" invisible="1"/>
<field name="product_uos" string="UoS" groups="product.group_uos" invisible="1"/>
<field name="tax_id" widget="many2many_tags" domain="[('parent_id','=',False),('type_tax_use','<>','purchase')]"/>
<field name="price_unit"/>
<field name="discount" groups="sale.group_discount_per_so_line"/>
<field name="price_subtotal"/>
</tree>
</field>
<group class="oe_subtotal_footer oe_right" colspan="2" name="sale_total">
<field name="amount_untaxed" widget='monetary' options="{'currency_field': 'currency_id'}"/>
<field name="amount_tax" widget='monetary' options="{'currency_field': 'currency_id'}"/>
<div class="oe_subtotal_footer_separator oe_inline">
<label for="amount_total" />
<button name="button_dummy"
states="draft,sent" string="(update)" type="object" class="oe_edit_only oe_link"/>
</div>
<field name="amount_total" nolabel="1" class="oe_subtotal_footer_separator" widget='monetary' options="{'currency_field': 'currency_id'}"/>
</group>
<div class="oe_clear"/>
<field name="note" class="oe_inline" placeholder="Terms and conditions..."/>
</page>
</xpath>
</field>
</record>
this code work on my module hope this will help you on your problem..
Just change your "xpath" code with the following ..
<xpath expr="//field[@name='order_line']/tree/field[@name='price_unit']" position="after">
<field name="shipng"/>
</xpath>
None of the edits gave reqd results; I'd request that you run the code on your system & then post the one that works as desired.
If you are trying to add to the order line use
<field name="model">sale.order.line</field>
<field name="inherit_id" ref="sale.view_order_line_form2"/>
not
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
the later is for Sale Order while the former is for sale order line. That may have some effects on where your field ends up displayed
Plus the class might also be better as
_inherit = 'sale.order.line' rather than _inherit = 'sale.order'
class sale_order(osv.Model):
_name='sale.order'
_inherit='sale.order.line'
_columns={
'shipng':fields.float('Shipping'),
}
sale.order()
class sale2_order(osv.Model):
_name='sale.order'
_inherit='sale.order'
_columns={
'shipng':fields.float('Shipping'),
}
sale2.order()
<openerp>
<data>
<record model="ir.ui.view" id="moleac_quotation_form_view">
<field name="name">Sale New Quotation</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<!--this will display field in tree view-->
<xpath expr="//page[@string='Sales Order']/field[@name='order_line']/tree[@string='Sales Order Lines']/field[@name='product_uom_qty']" position="before">
<field name="shipng"/>
</xpath>
<!--this will display field in form view-->
<xpath expr="//field[@name='order_line']/form/notebook/page[@string='Order Line']//field[@name='product_uom_qty' ]" position="before">
<field name="shipng" />
</xpath>
</field>
</record>
</data>
</openerp>
Made some changes You can try that if it works now
Thanks. But, the field isn't visible. Upgrade was successful. The update fails when I make the change suggested by Sven.
you want to display in the tree view not form view thus you should use <field name="inherit_id" ref="sale.view_order_line_tree"/> see my update above sale.view_order_line_form2 is for the form view of the order line.
None of the edits gave reqd results; I'd request that you run the code on your system & then post the one that works as desired.
Try my new updated code above i think that should help solve this problem if you still need it
About This Community
This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.
RegisterOdoo Training Center
Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.
Test it nowQuestion tools
Stats
Asked: 8/5/13, 4:59 AM |
Seen: 8681 times |
Last updated: 3/16/15, 8:10 AM |