Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
1 Balas
2494 Tampilan

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
Buang
Penulis

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

Penulis

On Confirming Sale Order Button Prevent the delivery challan creation.

Jawaban Terbai

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
Buang
Post Terkait Replies Tampilan Aktivitas
3
Mar 24
3368
2
Agu 23
2437
2
Mei 23
2650
1
Apr 23
2834
0
Jun 22
1679