openerp add custom field in BOM but always error - openerp-7

I want to few custom field in mrp.bom table in order to calculate the real row material consumption starting from drawing dimensions.
here is my .py code
from osv import osv, fields
class mrp_bom(osv.osv):
_inerhit = 'mrp.bom'
#_name = 'mrp.bom'
_columns = {
'Residuo_barra': fields.float(string='Residuo Barra', required=False),
'Sfrido': fields.float(string='Sfrido mm', required=False),
'L_barra': fields.float(string='lunghezza barra mm', required=False),
'L_pezzo_a_disegno': fields.float(string='L a disegno in mm', required=False),
'L_pezzo_calcolata': fields.float(string='Lunghezza calcolata', required=False),
}
_defaults = {
'Residuo_barra': 300.0,
'Sfrido': 4.0,
'L_barra': 3000.0,
}
def button_Calcola(self, cr, uid, ids, L_pezzo_a_disegno, Residuo_barra, Sfrido, L_barra, conext=None):
#calcola il consumo effettivo della barra
barra_utile = L_barra - Residuo_barra
numero_pezzi = int(barra_utile / (L_pezzo_a_disegno + Sfrido))
res = {
'L_pezzo_calcolata': (L_barra / numero_pezzi)
}
return {'value': res}
mrp_bom()
and here is the .xml
<record id="mrp_bom_tree_view" model="ir.ui.view">
<field name="name">mrp.bom.tree</field>
<field name="model">mrp.bom</field>
<field name="inherit_id" ref="mrp.mrp_bom_tree_view"/>
<field name="arch" type="xml">
<field name="product_id" position="after">
<field name="L_pezzo_calcolata" />
</field>
</field>
</record>
<record id="mrp_bom_component_tree_view" model="ir.ui.view">
<field name="name">mrp.bom.component.tree</field>
<field name="model">mrp.bom</field>
<field name="inherit_id" ref="mrp.mrp_bom_component_tree_view"/>
<field name="arch" type="xml">
<field name="product_id" position="after">
<field name="L_pezzo_calcolata" />
</field>
</field>
</record>
<record id="mrp_bom_form_view" model="ir.ui.view">
<field name="name">mrp.bom.form</field>
<field name="model">mrp.bom</field>
<field name="inherit_id" ref="mrp.mrp_bom_form_view"/>
<field name="arch" type="xml">
<xpath expr="//field[#name='bom_lines']/tree" position="inside" >
<field name="Residuo_barra" />
<field name="Sfrido" />
<field name="L_barra" />
<field name="L_pezzo_a_disegno" />
<field name="L_pezzo_calcolata" />
</xpath>
</field>
</record>
</data>
during the installation process I get :
ValidateError
Error occurred while validating the field(s) arch: Invalid XML for View Architecture!
If I check into the module structure Setting\Database structure\models\mrp_bom
the field have been added, But If I menage view in bom view the fields are not available!

Change the record id of inherited views so they are not the same.
For example:
<record id="mrp_bom_tree_view_add_field_L_pezzo_calcolata" model="ir.ui.view">
<field name="name">mrp_bom_tree_view_add_field_L_pezzo_calcolata</field>
<field name="model">mrp.bom</field>
<field name="inherit_id" ref="mrp.mrp_bom_tree_view"/>
<field name="arch" type="xml">
<field name="product_id" position="after">
<field name="L_pezzo_calcolata" />
</field>
</field>
</record>

Related

Group by field name

I want to do Group by by City but this possibility doesn't shows up. where is my mistake? there is field city in python file and it's showing up in tree view but not really in Group by
<openerp>
<data>
<record id="vpicktree" model="ir.ui.view">
<field name="name">Picking tree city</field>
<field name="model">stock.picking</field>
<field name="inherit_id" ref="stock.vpicktree"/>
<field name="arch" type="xml">
<field name="location_dest_id" position="after">
<field name="city"/>
</field>
</field>
</record>
<record model="ir.ui.view" id="stock_picking_filter_city_search">
<field name="name">stock.picking.tree.filter_search</field>
<field name="model">stock.picking</field>
<field name="arch" type="xml">
<search string="City">
<filter name="city" string="City" context="{'group_by':'city'}"/>
</search>
</field>
</record>
<record id="action_picking_tree_city" model="ir.actions.act_window">
<field name="name">City</field>
<field name="res_model">stock.picking</field>
<field name="type">ir.actions.act_window</field>
<field name="view_type">form</field>
<field name="view_mode">tree,kanban,calendar</field>
<field name="domain"></field>
<field name="context">{ 'group_by':'city' }</field>
<field name="search_view_id" ref="stock.view_picking_internal_search"/>
</record>
</data>
</openerp>
The group by must be in search view not on the action setion as you did, so you have to edit your search view:
<record model="ir.ui.view" id="stock_picking_filter_city_search">
<field name="name">stock.picking.tree.filter_search</field>
<field name="model">stock.picking</field>
<field name="arch" type="xml">
<search string="City">
<filter name="city" string="City" context="{'group_by':'city'}"/>
<group expand="0" string="Grouper par">
<filter string="City" icon="terp-personal" domain="[]" context="{'group_by':'city'}"/>
</group>
</search>
</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>

I need to show Tree view instead of Form view after i inherit CRM Module to my Custom Module in Openerp

I had successfully inherited the CRM module into my custom module.I'm able to view the Form view but i need to show Tree view first.When i click Lead button in the main menu i'm able to show the form view (like in img1), but i need to show the tree view(like in img 2)
img 1
img 2
lead_view.xml
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="view_lead_tree" model="ir.ui.view">
<field name="name">bala.lead</field>
<field name="model">bala.lead</field>
<field name="arch" type="xml">
<tree string="Leads">
<field name="contact_name"/>
<field name="lead_source"/>
<field name="lead_status"/>
</tree>
</field>
</record>
<!-- ========================This is Form layout===============================-->
<record id="crm_case_form_view_leads_extended" model="ir.ui.view">
<field name="name">CRM - Leads Form</field>
<field name="model">bala.lead</field>
<field name="inherit_id" ref="crm.crm_case_form_view_leads" />
<field name="arch" type="xml">
<field name="email_from" postion="replace"/>
<field name="contact_name" position="replace"/>
<label for="contact_name" position="replace">
<br/>
</label>
<xpath expr="//label[#for='street']" position="before">
<field name="contact_name"/>
</xpath>
<xpath expr="//label[#for='section_id']" position="before">
<field name="lead_source"/>
<field name="lead_status"/>
</xpath>
<field name="function" position="replace"/>
<field name="partner_name" position="replace"/>
<field name="priority" position="replace"/>
<field name="categ_ids" position="replace"/>
<field name="partner_id" position="replace"/>
</field>
</record>
<!-- ===========================Action layout=========================== -->
<record id="new_lead" model="ir.actions.act_window">
<field name="name">Leads</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">bala.lead</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="view_id" ref="view_lead_tree"/>
</record>
<!-- ===========================Menu Settings=========================== -->
<menuitem name ="Lead" id = "menu_lis_lab" />
<menuitem name="Leads" id="sub_lead" parent="menu_lis_lab" />
<menuitem name="Create Lead" id="create_lead" parent="sub_lead" action="new_lead"/>
</data>
</openerp>
then on click of any lead i'm getting img 3 (invalid view)and on click on Create button img 4 is being displyed , but i need to get img1
img 3
img 4
Add tree view to your xml file, and you can add more fields in this according to requirement,
<record id="view_lead_tree" model="ir.ui.view">
<field name="name">bala.lead</field>
<field name="model">bala.lead</field>
<field name="arch" type="xml">
<tree string="Leads">
<field name="contact_name"/>
<field name="lead_source"/>
<field name="lead_status"/>
</tree>
</field>
</record>
update your act_window
<record id="new_lead" model="ir.actions.act_window">
<field name="name">Lead</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">bala.lead</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="view_id" ref="view_lead_tree"/>
</record>
Hope this will help you.

openerp v7 save and new button to keep and show previously (old) fields value in view form

I have a form with a lot of fields and with two button (Save and Close and Save and New)
when Save and New button is clicked I want those previously entered fields value to be displayed.
Thank You!
OK, my first solution (using context) didn't work out :-( but i tried another way, i dont like it very much, but it could help you out.
following my example .py:
from openerp.osv import orm, fields
class object_one(orm.Model):
_name = "object.one"
_columns = {
'name':fields.char('Name', size=128, required=True),
'many_ids':fields.many2many('object.many',string="Many Objects")
}
class object_many(orm.Model):
_name = "object.many"
_columns = {
'name':fields.char('Name', size=128, required=True),
'sel':fields.selection([('1','One'),
('2','Two'),
('3','Three')],
string="Selection", required=True),
}
def _get_sel(self, cr, uid, context={}):
many_id = self.search(cr, uid, [('create_uid','=',uid)], context=context, order="create_date desc", limit=1)
if many_id:
many = self.browse(cr, uid, many_id[0], context)
return many.sel
return False
_defaults = {
'sel':_get_sel
}
following my example .xml:
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<record id="one_form" model="ir.ui.view">
<field name="name">one form view</field>
<field name="model">object.one</field>
<field name="arch" type="xml">
<form version="7.0" string="">
<group>
<field name="name" />
<field name="many_ids" />
</group>
</form>
</field>
</record>
<record id="one_tree" model="ir.ui.view">
<field name="name">one tree view</field>
<field name="model">object.one</field>
<field name="arch" type="xml">
<tree version="7.0" string="">
<field name="name" />
</tree>
</field>
</record>
<record id="many_form" model="ir.ui.view">
<field name="name">many form view</field>
<field name="model">object.many</field>
<field name="arch" type="xml">
<form version="7.0" string="">
<group>
<field name="name" />
<field name="sel" />
</group>
</form>
</field>
</record>
<record id="many_tree" model="ir.ui.view">
<field name="name">many tree view</field>
<field name="model">object.many</field>
<field name="arch" type="xml">
<tree version="7.0" string="">
<field name="name" />
<field name="sel" />
</tree>
</field>
</record>
<record model="ir.actions.act_window" id="one_tree_action">
<field name="name">One Objects</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">object.one</field>
<field name="view_type">form</field>
<field name="view_mode">form,tree</field>
<field name="view_id" ref="one_tree" />
</record>
<record model="ir.actions.act_window" id="many_tree_action">
<field name="name">Many Objects</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">object.many</field>
<field name="view_type">form</field>
<field name="view_mode">form,tree</field>
<field name="view_id" ref="many_tree" />
</record>
<menuitem name="Testing Menu" id="testing_menu" />
<menuitem name="Sub Menu" parent="testing_menu" id="sub_menu" />
<menuitem action="one_tree_action" name="One Menu" parent="sub_menu" id="one_menu" />
<menuitem action="many_tree_action" name="Many Menu" parent="sub_menu" id="many_menu" />
</data>
</openerp>
you will see, every many-object created by an user, will have the last selection (sel) get from db. so its more of a workaround for your problem.
hope this will help you.

Openerp 6.1 put product category in sale order line

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