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

how to create a custom field at delivery order (stock.picking) which gets its value from sales order in odoo

By
Susi
on 10/21/16, 4:17 AM 310 views

I have add field in sales_order and stock_picking 'cabang_id' :many2one

and i want get value cabang from sales order to stock.picking (delivery order )when confirm sale. i have try with method action_button confirm but its doesnt work. anyone can help me how should i do with my code ? thanks before


i'm using odoo v8

1
Dasadiya Chaitanya
On 10/22/16, 12:37 AM

The following way you can solve your issue.

1. Set custom field on sale.order and stock.pirking in py as well as view side.

2. Inherit the stock.move in your custom module and use the _prepare_picking_assign() over ridding method.

3. Using super and set your custom field value.

4. View that changes After confirming of Sale Order document.


For example :

from openerp import models, fields, api, _

class sale_order(models.Model):

    _inherit='sale.order' customer_field=fields.Char(string='Customer Field')

class stock_picking(models.Model):

    _inherit='stock.picking' customer_field=fields.Char(string='Customer Field')    

class stock_move(models.Model):

    _inherit='stock.move'

def _prepare_picking_assign(self,cr, uid, move, context=None):

    res=super(stock_move,self)._prepare_picking_assign(cr, uid, move, context) if move.procurement_id and move.procurement_id.sale_line_id and move.procurement_id.sale_line_id.order_id:

        sale_obj = move.procurement_id.sale_line_id.order_id if sale_obj.dif_pick_address:

            res.update({ 'customer_field':sale_obj.customer_field, }) return res


Above code is working fine in Odoo 8.0 version

Also, You should set in the view part so that you can check the sale order values come into stock picking after confirming your sale order.

I hope my answer may helpful for you :)


Source :

http://stackoverflow.com/questions/39953729/add-shipping-address-field-in-stock-picking-in-odoo/39956194#39956194


thanks dasadiya, i have try your code but its getting erorr like this line 11, in _prepare_picking_assign

if sale_obj.dif_pick_address:

ValueError: "'sale.order' object has no attribute 'dif_pick_address'" while evaluating

u'action_ship_create()'

Susi
on 10/23/16, 10:05 PM

sorry dasadiya,, ignore my comment in above. i already succes with your code. but the value only appear in stock.picking but in stock move its still empty. Can you explain how that work? thanks before

Susi
on 10/23/16, 10:15 PM
0
Arunagiri
On 10/21/16, 5:12 AM

Please write this code in your stock.picking 

@api.multi

 @api.depends('sale_id')

 def update_sale_delivery(self):

         for record in self:

             for rec in record.sale_id:

                 if rec.cabang_id:

                        record.cabang_id=rec.cabang_id.id

it will help you i hope 

dear arunagiri thanks before but i'am still use os.osv may you translate your code to osv os ? thanks before

Susi
on 10/21/16, 5:16 AM

use onchange method for 8

def onchange_field1(self, cr, uid, ids, field1, context=None):

vals = {}

if field1 > 0:

vals['field2'] = field1

return {'value': vals}

<field name="field1" on_change="onchange_field1(field1)"/>

Arunagiri
on 10/21/16, 5:32 AM

if field:

only

Arunagiri
on 10/21/16, 7:02 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

2 follower(s)

Stats

Asked: 10/21/16, 4:17 AM
Seen: 310 times
Last updated: 10/23/16, 10:15 PM