Repository navigation
[18.0][ADD] barcode_stock_unexpected_product #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 18.0
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| .. image:: https://odoo-community.org/readme-banner-image | ||
| :target: https://odoo-community.org/get-involved?utm_source=readme | ||
| :alt: Odoo Community Association | ||
|
|
||
| ================================ | ||
| Barcode Stock Unexpected Product | ||
| ================================ | ||
|
|
||
| .. | ||
| !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
| !! This file is generated by oca-gen-addon-readme !! | ||
| !! changes will be overwritten. !! | ||
| !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
| !! source digest: sha256:6b894cd33153bc988046a1ec6bcea502d79953332a015b109155e94f7657b5df | ||
| !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
|
|
||
| .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png | ||
| :target: https://odoo-community.org/page/development-status | ||
| :alt: Beta | ||
| .. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png | ||
| :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html | ||
| :alt: License: AGPL-3 | ||
| .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fbarcode--interface-lightgray.png?logo=github | ||
| :target: https://github.com/OCA/barcode-interface/tree/18.0/barcode_stock_unexpected_product | ||
| :alt: OCA/barcode-interface | ||
| .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png | ||
| :target: https://translation.odoo-community.org/projects/barcode-interface-18-0/barcode-interface-18-0-barcode_stock_unexpected_product | ||
| :alt: Translate me on Weblate | ||
| .. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png | ||
| :target: https://runboat.odoo-community.org/builds?repo=OCA/barcode-interface&target_branch=18.0 | ||
| :alt: Try me on Runboat | ||
|
|
||
| |badge1| |badge2| |badge3| |badge4| |badge5| | ||
|
|
||
| Let the warehouse app add a product to a transfer by scanning it, even | ||
| when that product is not one of the transfer's planned move lines. | ||
|
|
||
| By default the scanner only accepts products already expected on the | ||
| operation. This module lifts that limit — per operation type — so an | ||
| operator scanning an unlisted product adds a new line for it on the | ||
| spot, instead of being told the barcode is not part of the operation. | ||
|
|
||
| This is a feature module on top of ``barcode_stock``: it patches the | ||
| warehouse scan screens to allow the extra line and gates the behaviour | ||
| behind a setting on the operation type, so you enable it only where you | ||
| want it. | ||
|
|
||
| The setting only applies to transfers that already have planned lines. | ||
| Creating an internal transfer from scratch with the scanner is | ||
| unchanged: in that screen every line is new by design. | ||
|
|
||
| **Table of contents** | ||
|
|
||
| .. contents:: | ||
| :local: | ||
|
|
||
| Usage | ||
| ===== | ||
|
|
||
| Enable it per operation type: | ||
|
|
||
| 1. Go to **Inventory ▸ Configuration ▸ Operations Types** and open the | ||
| type you want (receipts, internal transfers, …). | ||
| 2. On the **Barcode** tab, tick **Allow Adding New Product Lines from | ||
| the Scanner**. | ||
|
|
||
| From then on, scanning a product that is not among the operation's | ||
| planned lines adds a new line for it, instead of rejecting the scan. | ||
| Where the setting is left off, the scanner keeps refusing products that | ||
| are not part of the operation, exactly as before. | ||
|
|
||
| The setting only gates adding unexpected products to a transfer that | ||
| already has planned lines. Creating an internal transfer from scratch | ||
| with the scanner keeps working exactly as before, whichever value the | ||
| setting has. | ||
|
|
||
| Bug Tracker | ||
| =========== | ||
|
|
||
| Bugs are tracked on `GitHub Issues <https://github.com/OCA/barcode-interface/issues>`_. | ||
| In case of trouble, please check there if your issue has already been reported. | ||
| If you spotted it first, help us to smash it by providing a detailed and welcomed | ||
| `feedback <https://github.com/OCA/barcode-interface/issues/new?body=module:%20barcode_stock_unexpected_product%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. | ||
|
|
||
| Do not contact contributors directly about support or help with technical issues. | ||
|
|
||
| Credits | ||
| ======= | ||
|
|
||
| Authors | ||
| ------- | ||
|
|
||
| * Binhex | ||
|
|
||
| Contributors | ||
| ------------ | ||
|
|
||
| - `Antonio David <https://github.com/antoniodavid>`__ | ||
|
|
||
| Maintainers | ||
| ----------- | ||
|
|
||
| This module is maintained by the OCA. | ||
|
|
||
| .. image:: https://odoo-community.org/logo.png | ||
| :alt: Odoo Community Association | ||
| :target: https://odoo-community.org | ||
|
|
||
| OCA, or the Odoo Community Association, is a nonprofit organization whose | ||
| mission is to support the collaborative development of Odoo features and | ||
| promote its widespread use. | ||
|
|
||
| .. |maintainer-antoniodavid| image:: https://github.com/antoniodavid.png?size=40px | ||
| :target: https://github.com/antoniodavid | ||
| :alt: antoniodavid | ||
|
|
||
| Current `maintainer <https://odoo-community.org/page/maintainer-role>`__: | ||
|
|
||
| |maintainer-antoniodavid| | ||
|
|
||
| This module is part of the `OCA/barcode-interface <https://github.com/OCA/barcode-interface/tree/18.0/barcode_stock_unexpected_product>`_ project on GitHub. | ||
|
|
||
| You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| from . import models |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| { | ||
| "name": "Barcode Stock Unexpected Product", | ||
| "version": "18.0.1.1.0", | ||
| "category": "Inventory/Logistics", | ||
| "summary": "Allow adding unexpected products to transfers via scanner", | ||
| "author": "Binhex, Odoo Community Association (OCA)", | ||
| "website": "https://github.com/OCA/barcode-interface", | ||
| "maintainers": ["antoniodavid"], | ||
| "license": "AGPL-3", | ||
| "depends": ["barcode_stock"], | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| "data": ["views/stock_picking_type_views.xml"], | ||
| "assets": { | ||
| "web.assets_backend": [ | ||
| "barcode_stock_unexpected_product/static/src/scss/barcode_stock_unexpected_product.scss", | ||
| "barcode_stock_unexpected_product/static/src/js/services/barcode_scanner_state_patch.esm.js", | ||
| "barcode_stock_unexpected_product/static/src/js/components/picking_move_list_patch.esm.js", | ||
| "barcode_stock_unexpected_product/static/src/js/screens/picking_screen_patch.esm.js", | ||
| "barcode_stock_unexpected_product/static/src/js/screens/product_selector_screen_patch.esm.js", | ||
| "barcode_stock_unexpected_product/static/src/xml/barcode_stock_unexpected_product_templates.xml", | ||
| ], | ||
| "web.assets_unit_tests": [ | ||
| "barcode_stock_unexpected_product/static/tests/manual_line.test.js", | ||
| ], | ||
| }, | ||
| "installable": True, | ||
| "auto_install": False, | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| from . import stock_picking_type | ||
| from . import stock_move | ||
| from . import stock_move_line | ||
| from . import stock_picking |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # Copyright 2026 Binhex | ||
| # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
|
||
| from odoo import fields, models | ||
|
|
||
|
|
||
| class StockMove(models.Model): | ||
| _inherit = "stock.move" | ||
|
|
||
| is_manually = fields.Boolean( | ||
| string="Manually Added", | ||
| help="Technical flag for moves added via scanner.", | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| # Copyright 2026 Binhex | ||
| # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
|
||
| from odoo import api, fields, models | ||
|
|
||
|
|
||
| class StockMoveLine(models.Model): | ||
| _inherit = "stock.move.line" | ||
|
|
||
| is_manually = fields.Boolean( | ||
| related="move_id.is_manually", store=False, readonly=True | ||
| ) | ||
|
|
||
| @api.model_create_multi | ||
| def create(self, vals_list): | ||
| lines = super().create(vals_list) | ||
| lines._barcode_scanner_sync_manual_move_quantity() | ||
| return lines | ||
|
|
||
| def write(self, vals): | ||
| res = super().write(vals) | ||
| if "quantity" in vals or "qty_picked" in vals: | ||
| self._barcode_scanner_sync_manual_move_quantity() | ||
| return res | ||
|
|
||
| def _barcode_scanner_sync_manual_move_quantity(self): | ||
| for line in self: | ||
| move = line.move_id | ||
| if not move.is_manually: | ||
| continue | ||
| total = sum(move.move_line_ids.mapped("quantity")) or sum( | ||
| move.move_line_ids.mapped("qty_picked") | ||
| ) | ||
| if total and move.product_uom_qty != total: | ||
| move.product_uom_qty = total |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,174 @@ | ||
| # Copyright 2026 Binhex | ||
| # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
|
||
| from odoo import api, models | ||
| from odoo.exceptions import UserError | ||
|
|
||
|
|
||
| class StockPicking(models.Model): | ||
| _inherit = "stock.picking" | ||
|
|
||
| @api.model | ||
| def _barcode_scanner_resolve_manual_line_lot(self, lot_id): | ||
| if not lot_id: | ||
| return False | ||
| try: | ||
| lot_id = int(lot_id) | ||
| except (TypeError, ValueError): | ||
| raise UserError(self.env._("The selected lot is not valid.")) from None | ||
| lot = self.env["stock.lot"].browse(lot_id).exists() | ||
| if not lot: | ||
| raise UserError(self.env._("The selected lot is not valid.")) | ||
| return lot | ||
|
|
||
| @api.model | ||
| def barcode_scanner_add_manual_line_to_picking( | ||
| self, picking_id, product_id, quantity, lot_id=False, auto_pick=False | ||
| ): | ||
| """Create or reserve pending demand from the PickingScreen.""" | ||
| picking = self.browse(picking_id).exists() | ||
| if not picking: | ||
| raise UserError(self.env._("The picking no longer exists.")) | ||
| if picking.state in ("done", "cancel"): | ||
| raise UserError(self.env._("This picking can no longer be changed.")) | ||
| picking_type = picking.picking_type_id | ||
| if picking_type.code != "internal" or not picking_type.allow_insert_new_line: | ||
| raise UserError( | ||
| self.env._( | ||
| "Adding a new product line from the scanner is not allowed " | ||
| "for this operation type." | ||
| ) | ||
| ) | ||
|
|
||
| product = self.env["product.product"].browse(product_id).exists() | ||
| if not product: | ||
| raise UserError( | ||
| self.env._("One of the selected products no longer exists.") | ||
| ) | ||
| qty = float(quantity or 0) | ||
| if qty <= 0: | ||
| raise UserError( | ||
| self.env._( | ||
| "Quantity must be greater than zero for product %(name)s.", | ||
| name=product.display_name, | ||
| ) | ||
| ) | ||
|
|
||
| source = picking.location_id or picking.move_ids[:1].location_id | ||
| destination = picking.location_dest_id or picking.move_ids[:1].location_dest_id | ||
| source = source or picking_type.default_location_src_id | ||
| destination = destination or picking_type.default_location_dest_id | ||
|
|
||
| # Serialize additions to this picking so the manual-move lookup and | ||
| # subsequent create-or-merge of a move cannot race. | ||
| self.env.cr.execute( | ||
| "SELECT id FROM stock_picking WHERE id = %s FOR UPDATE", (picking.id,) | ||
| ) | ||
|
|
||
| lot = self._barcode_scanner_resolve_manual_line_lot(lot_id) | ||
| if product.tracking != "none" and not lot: | ||
| raise UserError( | ||
| self.env._("A valid lot or serial number is required for this product.") | ||
| ) | ||
| if lot and lot.product_id != product: | ||
| raise UserError( | ||
| self.env._("The selected lot is not valid for this product.") | ||
| ) | ||
| if lot and lot.company_id and lot.company_id != picking.company_id: | ||
| raise UserError( | ||
| self.env._("The selected lot is not valid for this company.") | ||
| ) | ||
| if product.tracking == "serial" and qty != 1: | ||
| raise UserError( | ||
| self.env._("A serial-tracked product must be added one unit per line.") | ||
| ) | ||
| if product.tracking == "none": | ||
| lot = False | ||
|
|
||
| available = self.env["stock.quant"]._get_available_quantity( | ||
| product, source, lot_id=lot or None, strict=False | ||
| ) | ||
| if available < qty: | ||
| raise UserError( | ||
| self.env._( | ||
| "There is not enough available stock for product %(name)s.", | ||
| name=product.display_name, | ||
| ) | ||
| ) | ||
|
|
||
| Move = self.env["stock.move"] | ||
| move = Move.search( | ||
| [ | ||
| ("picking_id", "=", picking.id), | ||
| ("product_id", "=", product.id), | ||
| ("is_manually", "=", True), | ||
| ("picked", "=", False), | ||
| ], | ||
| limit=1, | ||
| ) | ||
| if move: | ||
| move.product_uom_qty += qty | ||
| else: | ||
| move = Move.create( | ||
| { | ||
| "name": product.display_name, | ||
| "product_id": product.id, | ||
| "product_uom_qty": qty, | ||
| "product_uom": product.uom_id.id, | ||
| "state": "confirmed", | ||
| "picking_id": picking.id, | ||
| "location_id": source.id, | ||
| "location_dest_id": destination.id, | ||
| "company_id": picking.company_id.id, | ||
| "is_manually": True, | ||
| } | ||
| ) | ||
|
|
||
| taken = move._update_reserved_quantity( | ||
| qty, source, lot_id=lot or None, strict=False | ||
| ) | ||
| if taken < qty: | ||
| raise UserError( | ||
| self.env._( | ||
| "There is not enough available stock for product %(name)s.", | ||
| name=product.display_name, | ||
| ) | ||
| ) | ||
| if auto_pick: | ||
| self._barcode_scanner_auto_pick_manual_line(move, product, lot) | ||
| return { | ||
| "move_id": move.id, | ||
| "product_id": product.id, | ||
| "quantity": qty, | ||
| "name": product.name, | ||
| "picked": bool(auto_pick), | ||
| } | ||
|
|
||
| def _barcode_scanner_auto_pick_manual_line(self, move, product, lot): | ||
| lines = move.move_line_ids.filtered( | ||
| lambda line: line.product_id == product and (not lot or line.lot_id == lot) | ||
| ) | ||
| for line in lines: | ||
| line.qty_picked = line.quantity | ||
|
|
||
| @api.model | ||
| def barcode_scanner_delete_manual_line(self, move_id): | ||
| """Delete a manually added line (is_manually) from the PickingScreen.""" | ||
| move = self.env["stock.move"].browse(move_id).exists() | ||
| if not move: | ||
| raise UserError(self.env._("The move no longer exists.")) | ||
| if not move.is_manually: | ||
| raise UserError(self.env._("Only manually added lines can be deleted.")) | ||
| picking = move.picking_id | ||
| if picking.state in ("done", "cancel"): | ||
| raise UserError(self.env._("This picking can no longer be changed.")) | ||
| if move.state == "done": | ||
| raise UserError(self.env._("A completed move cannot be deleted.")) | ||
| if move.quantity: | ||
| move._do_unreserve() | ||
| # Barcode operators have stock.group_stock_user: they may create and | ||
| # write moves but cannot unlink them. The checks above already ensured | ||
| # this is a manual line on a changeable picking, so elevate only the | ||
| # deletion itself. | ||
| move.sudo().unlink() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reproduced on 18.0 as a |
||
| return {"deleted": True, "move_id": move_id} | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The 18.0 guide starts a new module at
18.0.1.0.0, andbarcode_stock_qualityhere does; 1.1.0 reads as a module that already shipped a minor.