show product category in stock move tree in openerp7 - openerp-7

How can I show Category in stock move tree.
This is my coding.
My view file.
<record id="royalfood_stock_move_tree_view" 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_tree" />
<field name="arch" type="xml">
<xpath expr="//field[#name='product_id']" position="before">
<field name="categ_id" groups="base.group_user"/>
</xpath>
</field>
</record>
My .py File
class custom_stock_move_tree(osv.osv_memory):
_columns = {
'categ_id': fields.related('product_id', 'categ_id', type='many2one' ,relation='product.category', store=True),
}
custom_stock_move_tree()
Any Help is Appreciated.

try this files.
your .py file
class custom_stock_move_tree(osv.Model): #their is different b/w osv.Model and osv.osv_memory before to use it read it's usage
_inherit = 'stock.move' # if you want to add data in existing module use inherit
_columns =
{
'categ_id': fields.related('product_id', 'categ_id', type='many2one' ,relation='product.category', store=True, string='Product Category'),
}
Your view.xml file
<record id="royalfood_stock_move_tree_view" 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_tree" />
<field name="arch" type="xml">
<xpath expr="//field[#name='product_id']" position="before">
<field name="categ_id" groups="base.group_user"/>
</xpath>
</field>
After this see your Stock Move Tree view.

Related

Odoo 10 - Extend view to include related model field

I am trying to extend the view which displays packages in Odoo 10 so it display also the product_id:
<record id="stock_view_picking_form_enhanced" model="ir.ui.view">
<field name="name">stock_view_picking_form_enhanced</field>
<field name="model">stock.picking</field>
<field name="inherit_id" ref="stock.view_picking_form"/>
<field name="priority">20</field>
<field name="arch" type="xml">
<xpath expr="//field[#name='pack_operation_product_ids']/tree/field[#name='package_id']" position="after">
<field name="package_id.product_id"/>
</xpath>
</field>
</record>
So basically I am looking to display related field product_id from pack_operation_product_id.
Which is the right approach to implement this?
First you must include the related field in your inherited python class.
class StockPicking(models.Model):
_inherit = "stock.picking"
product_id = fields.Many2one('product.product', related='package_id.product_id', string='Product', store=True)
Then in XML you can write like the following:
<record id="stock_view_picking_form_enhanced" model="ir.ui.view">
<field name="name">stock_view_picking_form_enhanced</field>
<field name="model">stock.picking</field>
<field name="inherit_id" ref="stock.view_picking_form"/>
<field name="priority">20</field>
<field name="arch" type="xml">
<xpath expr="//field[#name='pack_operation_product_ids']/tree/field[#name='package_id']" position="after">
<field name="product_id"/>
</xpath>
</field>
</record>

Odoo. How to create a view to extended model

I am very new in odoo and i really need your help.
I've extended res.partner :
class extendedPartner(models.Model):
_name = 'extended.partner'
_inherit = 'res.partner'
auto = fields.One2Many('partner.car', 'auto_name', 'Car', required=False)
class partnerCar(models.Model):
_name = 'partner.car'
auto_model = fields.Char('Model auto', size=20, required=True)
release = fields.Integer('Year of release', required=True)
auto_name = fields.Many2One('extended.partner', 'Car Name', required=True)
But I don't know how to write xml so that I could see all partner's cars and information about them
<record model="ir.ui.view" id="view_partner_form">
<field name="name">res.partner.form.inherit</field>
<field name="model">extended.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="arch" type="xml">
<notebook position="inside">
<page string="Cars">
<!-- what should I write here? -->
</page>
</notebook>
</field>
</record>
Could you please help me? Thank you in advance.
UPD:
Is it right solution?
<record model="ir.ui.view" id="view_partner_form">
<field name="name">res.partner.form.inherit</field>
<field name="model">extended.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="arch" type="xml">
<field name="auto">
<tree>
<field name="auto_name"/>
<field name="auto_model"/>
<field name="release"/>
</tree>
</field>
</field>
</record>
You are almost there, since you inherit from another view and you injecting your view into the view you inherit from, you need to give your new view a "hook" in the parent view which it can use to attach its contents. So you use an xpath expression, and then you insert your field.
When you insert a relational field you can create so called embedded views. Here you have defined a tree view for your field. That means whenever your field will be rendered as a tree that is the tree that will be used, in your case the form.
You could also create a <form> after <tree> to be shown when clicked.
<record model="ir.ui.view" id="view_partner_form">
<field name="name">res.partner.form.inherit</field>
<field name="model">extended.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="arch" type="xml">
<xpath expr="insert_x_path_xpression here" position="after, before etc"
<field name="auto">
<tree>
<field name="auto_name"/>
<field name="auto_model"/>
<field name="release"/>
</tree>
</field>
</xpath>
</field>
</record>

Get tasks from a selected project

I'm trying to implement a many2one selection field where you select a project from. If you've selected a project then there's another many2one field where you can select the task from. These task all need to be from the selected project.
Currently I got this (note that I couldn't test it because I kept getting an XML error):
class purchase_order(osv.osv):
_inherit = 'purchase.order'
def get_task(self, cr, uid, ids, project_id, context=None):
task_obj = self.pool.get('project.task')
for task in task_obj.browse(cr, uid, ids, context):
task_ids = task_obj.search(cr, uid, [(task.project_id.id, '=', project_id)])
ids_cus = []
for cus in task_obj.browse(cr, uid, task_ids, context):
if cus.project.id.id not in ids_cus:
ids_cus.append(cus.project_id.id)
self.write(cr, uid, ids, {'state_readonly': 'listed', 'task_ids': [(6, 0, ids_cus)]})
return True
_columns = {
'project_id': fields.many2one('project.project', 'Project'),
'task_id': fields.selection(get_task, 'Select task'),
}
And my XML looks like this:
<record id="purchase_order_form" model="ir.ui.view">
<field name="name">purchase.order.form</field>
<field name="model">purchase.order</field>
<field name="inherit_id" ref="purchase.purchase_order_form"/>
<field name="arch" type="xml">
<field name="origin" position="after">
<field name="project_id" on_change="_get_task(project_id)"/>
<field name="task_id" selection="widget"/>
</field>
</field>
</record>
What am I doing wrong with the XML here? And might there be another way?
No need to write method to filter tasks according to project in your case just change few things as follow.
class purchase_order(osv.osv):
_inherit = 'purchase.order'
_columns = {
'project_id': fields.many2one('project.project', 'Project'),
'task_id': fields.many2one('project.task', 'Tasks'),
}
and change your xml,
<record id="purchase_order_form" model="ir.ui.view">
<field name="name">purchase.order.form</field>
<field name="model">purchase.order</field>
<field name="inherit_id" ref="purchase.purchase_order_form"/>
<field name="arch" type="xml">
<field name="origin" position="after">
<field name="project_id" />
<field name="task_id" domain="[('project_id','=',project_id.id)]" widget="selection" />
</field>
</field>
</record>
In your existing code you have made small mistake,
selection="widget" is not valid in xml you should write widget="selection"
This solved my problem, I've added a fields.related for chained fields:
_columns = {
'task_id': fields.related('project_id', 'tasks', type='many2one', relation='project.task', store=True,
string='Task')
}
And then adjust my XML (Like #Empiro Technologies said):
<record id="purchase_order_form" model="ir.ui.view">
<field name="name">purchase.order.form</field>
<field name="model">purchase.order</field>
<field name="inherit_id" ref="purchase.purchase_order_form"/>
<field name="arch" type="xml">
<field name="origin" position="after">
<field name="project_id"/>
<field name="task_id" domain="[('project_id','=', project_id)]"/>
</field>
</field>
</record>

openerp add custom field in BOM but always error

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>

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