跳至内容
菜单
此问题已终结

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

形象
丢弃
编写者

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

编写者

On Confirming Sale Order Button Prevent the delivery challan creation.

最佳答案

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

形象
丢弃
相关帖文 回复 查看 活动
3
3月 24
3514
2
8月 23
2512
2
5月 23
2698
1
4月 23
2902
0
6月 22
1713