Se rendre au contenu
Menu
Cette question a été signalée

Hello everyone,


To explain the context, I created a custom module with a model that inherits from stock.scrap. This model automatically creates a barcode for scrap when it is created. Here's the code:

from odoo import models, fields, api

class StockScrapInherit(models.Model):
_inherit = ['stock.scrap']
barcode = fields.Char(string='Code-barres')

@api.model
def create(self, vals):
# Get the last barcode. If null, create the default one
last_scrap = self.env['stock.scrap'].search([], order='barcode desc', limit=1)
last_barcode = last_scrap.barcode if last_scrap else 'SCRAP-A0000'

if not isinstance(last_barcode, str):
last_barcode = 'SCRAP-A0000'

last_letter = last_barcode[6]
last_number = int(last_barcode[7:])

if last_number new_number = last_number + 1
new_barcode = 'SCRAP-' + last_letter + str(new_number).zfill(4)
else:
new_letter = chr(ord(last_letter) + 1)
new_barcode = 'SCRAP-' + new_letter + '0001'

vals['barcode'] = new_barcode

record = super(StockScrapInherit, self).create(vals)
return record

However, I can't manage to inherit the Barcode module that would allow me to redirect to the scrap page when its barcode is scanned. 


Do you have any idea how to do this?


Thanks in advance!

Avatar
Ignorer
Publications associées Réponses Vues Activité
0
mars 24
1689
0
nov. 23
1758
2
sept. 23
4062
0
avr. 18
3646
2
mars 15
6068