You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
1.1 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright (C) 2004-Today Odoo S.A.
  3. # License LGPLv3 (https://github.com/odoo/odoo/blob/9.0/LICENSE).
  4. from openerp import models, fields, api
  5. class BarcodeEventsMixin(models.AbstractModel):
  6. """ Mixin class for objects reacting when a barcode is scanned in their form views
  7. which contains `<field name="_barcode_scanned" widget="barcode_handler"/>`.
  8. Models using this mixin must implement the method on_barcode_scanned. It works
  9. like an onchange and receives the scanned barcode in parameter.
  10. """
  11. _name = 'barcodes.barcode_events_mixin'
  12. _barcode_scanned = fields.Char("Barcode Scanned", help="Value of the last barcode scanned.", store=False)
  13. @api.onchange('_barcode_scanned')
  14. def _on_barcode_scanned(self):
  15. barcode = self._barcode_scanned
  16. if barcode:
  17. self._barcode_scanned = ""
  18. return self.on_barcode_scanned(barcode)
  19. def on_barcode_scanned(self, barcode):
  20. raise NotImplementedError("In order to use barcodes.barcode_events_mixin, method on_barcode_scanned must be implemented")