Zum Inhalt springen
Menü
Sie müssen registriert sein, um mit der Community zu interagieren.
Diese Frage wurde gekennzeichnet
1 Antworten
2731 Ansichten

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
Verwerfen
Autor

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

Autor

On Confirming Sale Order Button Prevent the delivery challan creation.

Beste Antwort

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
Verwerfen
Verknüpfte Beiträge Antworten Ansichten Aktivität
3
März 24
3706
2
Aug. 23
2597
2
Mai 23
2810
1
Apr. 23
2994
0
Juni 22
1821