I created a field of type Boolean 'check_barcode' in the stock.config.settings object. The intent of this field is as follows if it is marked as true it would have entered a method that is in another inherited object. The problem is that my self.env is not bringing the check_barcode field (I think it's not making the stay).
How to call the check_barcode field in the def calculate_checksum method?
field.py
class StockSettings(models.TransientModel):
_inherit = 'stock.config.settings'
check_barcode = fields.Boolean(string='check_barcode')
product.py
class ProductTemplate(models.Model):
_inherit = "product.template"
@api.onchange('barcode')
def calculate_checksum(self):
#if self.env.user.company_id.product_ids.compute(self.company_id.check_barcode, self.product_ids):
#if self.env['res.config.settings'].check_barcode: #.company_id.product_ids.compute(self.company_id.check_barcode, self.product_ids):
if self.check_barcode == 'True':
if self.barcode:
barcode = self.barcode[:12]
if len(barcode) < 12:
barcode = barcode.ljust(12, '0')
sum_ = lambda x, y: int(x) + int(y)
evensum = reduce(sum_, barcode[::2])
oddsum = reduce(sum_, barcode[1::2])
digit = (10 - ((evensum + oddsum * 3) % 10)) % 10
self.write(
{
'barcode': barcode + str(digit)
}
)
else:
return False