跳至內容
選單
此問題已被標幟

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!

頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
0
3月 24
1670
0
11月 23
1744
2
9月 23
4034
0
4月 18
3619
2
3月 15
6040