Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
2 Antwoorden
5664 Weergaven

I'm trying to generate a Lot/Serial number automatically when someone adds a new item to stock_move_line. The Value is not getting updated though. Could someone point me to the right way to work with that field? I'm quite new with Odoo.

class x_c_template(models.Model):
_inherit = "stock.move.line"

@api.onchange('product_id', 'product_uom_id')
def onchange_generate_lot(self):
res = {}
if self.product_id.tracking == 'serial':
self.lot_name = lambda self: self.env['ir.sequence'].next_by_code('stock.lot.serial')
res = {'domain': {'stock_move_line': [('lot_name', '=', self.lot_name)]}}
return res
Avatar
Annuleer

Zendo, Do you mean, you want to set serial number automatically When the record of stock_move_line created?

Beste antwoord
@api.multi
@api.onchange('product_id', 'product_uom_id')
    def onchange_generate_lot(self):
    res = {}
    if self.product_id.tracking == 'serial':self.lot_name = lambda self: self.env['ir.sequence'].next_by_code('stock.lot.serial')
    res = {'domain': {'stock_move_line': [('lot_name', '=', self.lot_name)]}}
    return res

Use @api.multi

hope this will helps you.


Avatar
Annuleer
Auteur

@api.multi

@api.onchange('product_id', 'product_uom_id')

def onchange_generate_lot(self):

res = {}

if self.product_id.tracking == 'serial':self.lot_name = self.env['ir.sequence'].next_by_code('stock.lot.serial')

res = {'domain': {'stock_move_line': [('lot_name', '=', self.lot_name)]}}

return res

This works. lambda somehow screws things up and instead of giving back the sequence number I get a weird string. Also using this code, the sequence advances by 2 not 1. I think its because another lot gets created automatically as well and this creates one more on top?

Hello Sehrish! Could you please help me to generate different sequence for products in mrp. By default, lot seq generated commonly for all products.

Gerelateerde posts Antwoorden Weergaven Activiteit
1
sep. 18
4525
1
jul. 24
2137
6
mei 24
21637
1
dec. 22
5885
3
mrt. 16
6648