Skip to Content
Menu
This question has been flagged
1 Reply
3625 Views

Hi All, 

I was trying to save the tracking number in stock.picking model by updating the field, 'carrier_tracking_ref'. So according to the documentation, it should be a straight forward process. I have tried, 

from odoo import api, fields, models, _

from odoo.exceptions import Warning


class StockPicking(models.Model): 

     _inherit = 'stock.picking'
     @api.multi    

     def button_book_shipment(self): 

           for rec in self:
              # self.book_shipment(rec)            

             rec.carrier_tracking_ref = 'TRACKING_NUMBER'   

# I also tried using write method  

             pick = self.env['stock.picking'].browse(46)            

             pick.write({  'carrier_tracking_ref': 'TRACKING_NUMBER' }) 

              raise Warning(_('Booking shipment DONE'))

But neither of these works and the value does not get updated. I wonder if I have missed anything here or how I can update this field? 

If I edit the picking record from the Odoo UI and manually it enter the tracking number, it saves the value properly. How do I do it in code? 


Thanks.


Avatar
Discard
Best Answer

The raise exception will rollback all of your changes done. That is the reason you are not able to see your changes done from the code.

Please remove the raise exception "raise Warning(_('Booking shipment DONE'))" and try your code.

Avatar
Discard
Author

Thanks Sudhir. That works for me after I remove the exception statement.