Odoo Help


Stock move line customization in 7

Stan Goldbraithe
on 9/15/13, 11:42 AM 2,372 views

Hey everyone, So, recently I have been digging into OpenERP 7.0. I am new to OpenERP (but not python). I came across the move lines inside the stock module and wanted to make a change, namely, pulling in supplier code from product_supplierinfo but was wondering;

Is there a better/cleaner way to do this ?

Currently, I am overloading the stock.move.tree view inside my own view.xml by doing

<record id="stock_view_move_picking_tree" 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="supplier_code"/>

Then, inside my .py file. I am overloading class stock_move

class stock_move(osv.Model): _inherit = "stock.move" _columns = { 'supplier_code': fields.many2one('product.supplierinfo', 'Supplier Code'),

def onchange_product_id(self, cr, uid, ids, prod_id=False, loc_id=False,
                        loc_dest_id=False, partner_id=False):
    _supobj = self.pool.get('product.supplierinfo')
    _supid = _supobj.search(cr, uid,
                            [('product_id','=',prod_id)], context=ctx)
    supplier_code = None

    if len(_supid) > 0:
        _sup = _supobj.browse(cr, uid, _supid, ctx)[0]
        # even though a supplier is found, they may not have a product_code
        if _sup.product_code:
            supplier_code = _sup.id

    result = {
        'supplier_code': supplier_code,
On 9/15/13, 12:01 PM

normally it should work

def onchange_product_id(self, cr, uid, ids, prod_id=False, loc_id=False,
                            loc_dest_id=False, partner_id=False):
       res = super(product_product, self).onchange_product_id(cr, uid, ids, prod_id=prod_id, loc_id=loc_id,loc_dest_id=loc_dest_id,partner_id=partner_id)

      product = self.pool.get('product.product').browse(cr, uid, [prod_id], context=ctx)[0]
      return res

because it's an onchange, I also had to conditionalize the value part (since it could be empy). With this in mind, I had to change it over to;

    product = self.pool.get('product.product').browse(cr, uid, [prod_id])[0]            
    if 'value' in result:                                                  
Stan Goldbraithe
on 9/15/13, 2:06 PM

dankeschoen btw

Stan Goldbraithe
on 9/15/13, 2:08 PM

Did u got the solution its not working for me

Sampath Kumar S
on 1/11/14, 12:48 AM

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.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

0 follower(s)


Asked: 9/15/13, 11:42 AM
Seen: 2372 times
Last updated: 3/16/15, 8:10 AM