Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
1 Odpovědět
2502 Zobrazení

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
Zrušit
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.

Nejlepší odpověď

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
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
3
bře 24
3373
2
srp 23
2438
2
kvě 23
2653
1
dub 23
2834
0
čvn 22
1683