Odoo Help

Welcome!

This community 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.

0

Stock move line customization in 7

By
Stan Goldbraithe
on 9/15/13, 11:42 AM 1,644 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"/>
         </field>
    </field>
</record>

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,
        ...
    }
0
le_dilem
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]
      res['value'].update({'supplier_code':product.seller_id.prod_id})
      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:                                                  
        result['value'].update({'supplier_code':product.seller_info_id.product_code})
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

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

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