Skip to Content
Menu
This question has been flagged

inherit stock.picking don't want to on create method generate sequence code want to on state done.
1.my simple requirements when stock  picking state is done only that time sequence code is generated not each create time of stock picking, i inherit the module but base code are created sequence code

defaults = self.default_get(['name', 'picking_type_id'])
picking_type = self.env['stock.picking.type'].browse(vals.get('picking_type_id', defaults.get('picking_type_id')))
if vals.get('name', '/') == '/' and defaults.get('name', '/') == '/' and vals.get('picking_type_id', defaults.get('picking_type_id')):
if picking_type.sequence_id:
vals['name'] = picking_type.sequence_id.next_by_id()

please help thank you

Avatar
Discard
Author

or want to apply sequence code only when stock picking is done state odoo15

Author

On Confirming Sale Order Button Prevent the delivery challan creation.

Best Answer

Hi,To achieve your requirement of generating a sequence code for stock pickings only when their state changes to "done", you can override the button_validate() method of the stock.picking model. This method is called when the picking's state changes to "done". Here's how you can do it:from odoo import models, api

class StockPicking(models.Model):
    _inherit = 'stock.picking'

    def button_validate(self):
        # Call super to perform the default behavior
        res = super(StockPicking, self).button_validate()

        # Loop through the pickings
        for picking in self:
            # Check if the picking is in 'done' state
            if picking.state == 'done':
                # Generate sequence code if it's not already set
                if not picking.name and picking.picking_type_id.sequence_id:
                    picking.name = picking.picking_type_id.sequence_id.next_by_id()

        return res


Hope it helps

Avatar
Discard
Related Posts Replies Views Activity
3
Mar 24
3297
2
Aug 23
2418
2
May 23
2617
1
Apr 23
2804
0
Jun 22
1655