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.

141 lines
4.9 KiB

  1. =======================
  2. Barcode action launcher
  3. =======================
  4. .. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  5. !! This file is generated by oca-gen-addon-readme !!
  6. !! changes will be overwritten. !!
  7. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  8. .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
  9. :target: https://odoo-community.org/page/development-status
  10. :alt: Beta
  11. .. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
  12. :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
  13. :alt: License: AGPL-3
  14. .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--ux-lightgray.png?logo=github
  15. :target: https://github.com/OCA/server-ux/tree/12.0/barcode_action
  16. :alt: OCA/server-ux
  17. .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
  18. :target: https://translation.odoo-community.org/projects/server-ux-12-0/server-ux-12-0-barcode_action
  19. :alt: Translate me on Weblate
  20. .. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
  21. :target: https://runbot.odoo-community.org/runbot/250/12.0
  22. :alt: Try me on Runbot
  23. |badge1| |badge2| |badge3| |badge4| |badge5|
  24. This module allows to use barcodes as launchers of actions.
  25. The action will launch a function that uses the barcode in order to return an action.
  26. **Table of contents**
  27. .. contents::
  28. :local:
  29. Usage
  30. =====
  31. Actions must be configured with the following data in the context:
  32. * model: Model where we can find the method (required)
  33. * method: Method to execute (required)
  34. * res_id: Id as base (optional)
  35. The method must return an action. Installing this module with demo data will
  36. install a demo application that allows the system administrator to find a
  37. partner by the external reference encoded in a barcode.
  38. Go to *Settings / Find partners* and scan a barcode that contains the
  39. internal reference of an existing partner. As soon as you read the barcode
  40. the system will redirect you to that partner's form view.
  41. Technical implementation of this example:
  42. Action::
  43. <act_window id="res_partner_find"
  44. name="Find Partner"
  45. res_model="barcode.action"
  46. view_mode="form"
  47. view_type="form"
  48. context="{'default_model': 'res.partner', 'default_method': 'find_res_partner_by_ref_using_barcode'}"
  49. target="new"/>
  50. <menuitem id="menu_orders_customers" name="Find partners"
  51. action="res_partner_find"
  52. parent="base.menu_administration"/>
  53. Python code::
  54. import json
  55. from odoo import api, models, _
  56. from odoo.tools.safe_eval import safe_eval
  57. class ResPartner(models.Model):
  58. _inherit = 'res.partner'
  59. @api.multi
  60. def find_res_partner_by_ref_using_barcode(self, barcode):
  61. partner = self.search([('ref', '=', barcode)], limit=1)
  62. if not partner:
  63. action = self.env.ref('res_partner_find')
  64. result = action.read()[0]
  65. context = safe_eval(result['context'])
  66. context.update({
  67. 'default_state': 'warning',
  68. 'default_status': _('Partner with Internal Reference '
  69. '%s cannot be found') % barcode
  70. })
  71. result['context'] = json.dumps(context)
  72. return result
  73. action = self.env.ref('base.action_partner_form')
  74. result = action.read()[0]
  75. res = self.env.ref('base.view_partner_form', False)
  76. result['views'] = [(res and res.id or False, 'form')]
  77. result['res_id'] = partner.id
  78. return result
  79. Bug Tracker
  80. ===========
  81. Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-ux/issues>`_.
  82. In case of trouble, please check there if your issue has already been reported.
  83. If you spotted it first, help us smashing it by providing a detailed and welcomed
  84. `feedback <https://github.com/OCA/server-ux/issues/new?body=module:%20barcode_action%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
  85. Do not contact contributors directly about support or help with technical issues.
  86. Credits
  87. =======
  88. Authors
  89. ~~~~~~~
  90. * Creu Blanca
  91. * Eficent
  92. Contributors
  93. ~~~~~~~~~~~~
  94. * Enric Tobella <etobella@creublanca.es>
  95. * Jordi Ballester <jordi.ballester@eficent.com>
  96. Maintainers
  97. ~~~~~~~~~~~
  98. This module is maintained by the OCA.
  99. .. image:: https://odoo-community.org/logo.png
  100. :alt: Odoo Community Association
  101. :target: https://odoo-community.org
  102. OCA, or the Odoo Community Association, is a nonprofit organization whose
  103. mission is to support the collaborative development of Odoo features and
  104. promote its widespread use.
  105. This module is part of the `OCA/server-ux <https://github.com/OCA/server-ux/tree/12.0/barcode_action>`_ project on GitHub.
  106. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.