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.

131 lines
7.0 KiB

  1. ==============================
  2. Barcodes module documentation
  3. ==============================
  4. This module brings barcode encoding logic and client-side barcode scanning utilities.
  5. Barcodes encoding
  6. ==============================
  7. The Barcodes module defines barcode nomenclatures whose rules identify specific type
  8. of items e.g. products, locations. It contains the following features:
  9. - Barcode patterns to identify barcodes containing a numerical value (e.g. weight, price)
  10. - Definitin of barcode aliases that allow to identify the same product with different barcodes
  11. - Unlimited barcode patterns and definitions,
  12. - Barcode EAN13 encoding supported.
  13. Barcode encodings
  14. -----------------
  15. A barcode is an arbitrary long sequence of ASCII characters. An EAN-13 barcode is a 13 digit
  16. barcode, whose 13th digit is the checksum.
  17. Simple barcodes and rules
  18. -------------------------
  19. The default nomenclature assumes an EAN-13 encoding for product barcodes. It defines a rule
  20. for Unit Products whose encoding is EAN-13, and whose pattern is '.', i.e. any barcode
  21. matches this pattern. Scanning the barcode of a product, say '5410013101703', matches this rule.
  22. The scanned item is thus identified as a Unit Product, and is retrieved from the product table.
  23. Note: the special character '.' in patterns is matched by any character. To explicitely specify
  24. the '.' character in a pattern, escape it with '\'. The '\' character has to be escaped as well
  25. ('\\') to be explicitely specified.
  26. Let us now suppose that we identify other items with barcodes, say stock locations. We define a
  27. new rule in the nomenclature with the corresponding type (in our example, the type is 'Location'),
  28. and whose pattern is e.g. '414.', that is, any location barcode starts with '414'. Scanning a barcode
  29. location, say '41401', matches this Location rule, and the corresponding location is retrieved from
  30. the location table.
  31. Note: Rules have a sequence field which indicates the order the rules are evaluated (ASC). In our
  32. previous examples, the Unit Product rule should have a larger sequence that then Location rule,
  33. because we want the latter one to be evaluated first.
  34. Barcodes with numerical content
  35. --------------------------------
  36. Barcodes may encode numerical content, which is decoded by the barcodes module. To that purpose,
  37. one have to define a new rule for barcodes with numerical content (e.g. barcodes for Weighted
  38. Products). The numerical content in a pattern is specified between braces (special characters '{' and
  39. '}'). The content of the braces must be a sequence of 'N's (representing the whole part of the numerical
  40. content) followed by a sequence of 'D's (representing the decimal part of the numerical content).
  41. For instance, let us define a new rule for Weighted Products whose pattern is '21.....{NNDDD}.'. Since
  42. we assume EAN-13 encoding for product barcodes, the encoding of this rule should be EAN-13 as well.
  43. Let us now assume that we want to write a barcode for a given Weighted Product, say oranges. We first
  44. have to define in product oranges a barcode that will match the Weighted Product rule. This barcode
  45. must start with '21' and be a correct EAN-13 barcode (i.e. the 13th digit must be a correct checksum).
  46. Moreover, all the numerical content must be set to a '0'. For instance, let us set the barcode to
  47. '2100001000004'.
  48. We now want to write a barcode for 2.75kg of oranges. This barcode should be '2100001027506' (the
  49. numerical content of this barcode is '02750', and the correct checksum is '6'). When scanned, this
  50. barcode matches the Weighted Product rule (since is starts with '21'). The numerical content is extracted,
  51. and replaced by a sequence of '0's. The correct checksum is then computed for the obtained barcode
  52. ('2100001000004') and the corresponding product (oranges) qgit is retrieved from product table.
  53. Note: the special characters '{' and '}' in patterns are used to identify numerical content. To
  54. explicitely specify '{' or '}' in a pattern, they must be escaped.
  55. Strict EAN-13 field of barcode nomenclatures
  56. --------------------------------------------
  57. Many barcode scanners strip the leading zero when scanning EAN-13 barcodes. Barcode nomenclatures
  58. have a boolean field "Use strict EAN13". If False, when trying to match a scanned barcode with
  59. a rule whose encoding is EAN-13, if the barcode is of length 12 and, by prepending it by a 0,
  60. the last digit is the correct checksum, we automatically prepend the barcode by 0 and try to
  61. find a match with this new barcode. If "Use strict EAN13" is set to True, we look for a pattern
  62. matching the original, 12-digit long, barcode.
  63. Barcodes scanning
  64. ==============================
  65. Barcode events
  66. ------------------------------
  67. When the module barcodes is installed, it instanciate a singleton of the javascript class BarcodeEvents.
  68. The purpose of this component is to listen to keypresses to detect barcodes, then dispatch those barcodes
  69. on core.bus inside a 'barcode_event'.
  70. All keypress events are buffered until there is no more keypress during 50ms or a carriage return / tab is
  71. inputted (because most barcode scanners use this as a suffix).
  72. If the buffered keys looks like a barcode (match the the regexp /.{3,}[\n\r\t]*), an event is triggered :
  73. core.bus.trigger('barcode_scanned', barcode);
  74. Otherwise, the keypresses are 'resent'. However, for security reasons, a keypress event programmatically
  75. crafted doesn't trigger native browser behaviors. For this reason, BarcodeEvents doesn't intercept keypresses
  76. whose target is an editable element (eg. input) or when ctrl/cmd/alt is pushed.
  77. To catch keypresses targetting an editable element, it must have the attribute barcode_events="true".
  78. Barcode handlers
  79. ------------------------------
  80. To keep the web client consistent, components that want to listen to barcode events should include BarcodeHandlerMixin.
  81. It requires method on_barcode_scanned(barcode) to be implemented and exposes methods start_listening and stop_listening
  82. As long as it is the descendant of a View managed by a ViewManager is only listens while the view is attached.
  83. Form view barcode handler
  84. ------------------------------
  85. It is possible for a form view to listen to barcode events, handle them client side and/or server-side.
  86. When the barcode is handled server-side, it works like an onchange. The relevant model must include the
  87. BarcodeEventsMixin and redefine method on_barcode_scanned. This method receives the barcode scanned and
  88. the `self` is a pseudo-record representing the content of the form view, just like in @api.onchange methods.
  89. Barcodes prefixed with 'O-CMD' or 'O-BTN' are reserved for special features and are never passed to on_barcode_scanned.
  90. The form view barcode handler can be extended to add client-side handling. Please refer to the (hopefully
  91. well enough) documented file for more informations.
  92. Button barcode handler
  93. ------------------------------
  94. Add an attribute 'barcode_trigger' to a button to be able to trigger it by scanning a barcode. Example :
  95. <button name="validate" type="object" barcode_trigger="validate"/> will be triggered when a barcode containing
  96. "O-BTN.validate" is scanned.