Skip to content

SMNDVC/scanner_view

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Odoo Scanner View Module

This Odoo module provides a generic wizard to scan QR codes and barcodes using a webcam. The scanned value can then be saved to a specified field on any Odoo model. It is designed to be easily integrated into existing forms with minimal configuration.

Features

  • Webcam-based scanning: Utilizes the browser's built-in camera for scanning QR codes and barcodes.
  • Easy integration: Add a scanner button to any form view with a few lines of XML.
  • Flexible configuration: Specify the target model, record, and field to save the scanned value.
  • User-friendly interface: A simple wizard guides the user through the scanning process.

Example of Use

The module works by launching a wizard from a button placed on a form view. Here is an example of how to integrate it with the Maintenance Equipment form to scan a serial number.

  1. Scanner Button: A "Scan!" button is added next to the 'Serial Number' field on the Maintenance Equipment form.

    Maintenance Equipment

  2. Scanner Wizard: Clicking the "Scan!" button opens the scanner wizard. The user can initiate the scan by clicking the barcode icon.

    Scanner Wizard

  3. Scanning: The browser will activate the webcam. Once a barcode or QR code is successfully scanned, the window closes, and the scanned value is displayed in the wizard.

    Scanned Value

  4. Saving the Value: The user clicks "Continue" to save the scanned value to the designated field on the original form.

    Stored Value

Configuration

To add a scanner button to a form view, you need to extend the view and add a button with the correct action and context. The context attribute on the button is crucial for the scanner to work correctly.

Here is an example of how to add the button to the maintenance.equipment form to populate the serial_no field.

  1. Inherit the view: Create a new view that inherits from the target form view.

    <record id="rdo_equipment_scanner.equipment_form_inherit" model="ir.ui.view">
        <field name="name">maintenance.equipment.form.inherit</field>
        <field name="model">maintenance.equipment</field>
        <field name="inherit_id" ref="maintenance.hr_equipment_view_form"/>
        <field name="arch" type="xml">
            <!-- Xpath expression will be added here -->
        </field>
    </record>
  2. Locate the target field: Use an xpath expression to find the position where you want to add the button. In this case, we are replacing the existing serial_no field to add the button next to it.

    <xpath expr="//field[@name='serial_no']" position="replace">
        <!-- Button and field will be added here -->
    </xpath>
  3. Add the button and field: Add the original field and the new button. The button needs a specific action and context.

    <record id="rdo_equipment_scanner.equipment_form_inherit" model="ir.ui.view">
        <field name="name">maintenance.equipment.form.inherit</field>
        <field name="model">maintenance.equipment</field>
        <field name="inherit_id" ref="maintenance.hr_equipment_view_form"/>
        <field name="arch" type="xml">
            <xpath expr="//field[@name='serial_no']" position="replace">
                <label for="serial_no"/>
                <div class="o_row">
                    <field name="serial_no" nolabel="1" class="oe_inline" style="width: 170%;"/>
                    <button name="%(rdo_scanner_view.action_scanner_wizard_view)d"
                            type="action"
                            context="{'default_res_model': 'maintenance.equipment',
                                      'default_res_id': active_id,
                                      'default_res_field': 'serial_no'}"
                            class="btn btn-primary">
                        Scan!
                    </button>
                </div>
            </xpath>
        </field>
    </record>

The context attribute on the button must contain the following keys:

  • default_res_model: The name of the model where the target field is located (e.g., 'maintenance.equipment').
  • default_res_id: The ID of the record being edited. You should always use the active_id variable for this value.
  • default_res_field: The name of the field where the scanned value will be saved (e.g., 'serial_no').

Installation

To use this module, simply install it in your Odoo instance. The rdo_equipment_scanner module provides a working example for the maintenance.equipment model.


Developed by Šimon Dovičovič, rimedo s.r.o.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors