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

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
Annuleer
Gerelateerde posts Antwoorden Weergaven Activiteit
0
mrt. 24
1663
0
nov. 23
1736
2
sep. 23
4012
0
apr. 18
3592
2
mrt. 15
6020