Skip to content

Commit

Permalink
TA#57380 [ADD] stock_picking_barcode
Browse files Browse the repository at this point in the history
  • Loading branch information
majouda committed Apr 22, 2024
1 parent edad9ac commit 5661cff
Show file tree
Hide file tree
Showing 13 changed files with 328 additions and 0 deletions.
1 change: 1 addition & 0 deletions .docker_files/main/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"stock_move_valuation_adjustment",
"stock_orderpoint_scheduled_date",
"stock_orderpoint_secondary_unit",
"stock_picking_barcode",
"stock_picking_groupby_parent_affiliate",
"stock_picking_responsible_editable",
"stock_picking_secondary_unit_demand",
Expand Down
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ COPY stock_move_origin_link /mnt/extra-addons/stock_move_origin_link
COPY stock_move_valuation_adjustment /mnt/extra-addons/stock_move_valuation_adjustment
COPY stock_orderpoint_scheduled_date /mnt/extra-addons/stock_orderpoint_scheduled_date
COPY stock_orderpoint_secondary_unit /mnt/extra-addons/stock_orderpoint_secondary_unit
COPY stock_picking_barcode /mnt/extra-addons/stock_picking_barcode
COPY stock_picking_groupby_parent_affiliate /mnt/extra-addons/stock_picking_groupby_parent_affiliate
COPY stock_picking_responsible_editable /mnt/extra-addons/stock_picking_responsible_editable
COPY stock_picking_secondary_unit_demand /mnt/extra-addons/stock_picking_secondary_unit_demand
Expand Down
98 changes: 98 additions & 0 deletions stock_picking_barcode/I18n/fr.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * stock_picking_barcode
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 14.0+e\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-04-22 04:07+0000\n"
"PO-Revision-Date: 2024-04-22 04:07+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: stock_picking_barcode
#: model_terms:ir.ui.view,arch_db:stock_picking_barcode.stock_picking_type_view_form_inherit
msgid "Barcode"
msgstr "Code-barres"

#. module: stock_picking_barcode
#: model:ir.model.fields,field_description:stock_picking_barcode.field_stock_picking___barcode_scanned
msgid "Barcode Scanned"
msgstr "Code-barres numérisé"

#. module: stock_picking_barcode
#: model:ir.model.fields,field_description:stock_picking_barcode.field_stock_picking__display_name
#: model:ir.model.fields,field_description:stock_picking_barcode.field_stock_picking_type__display_name
msgid "Display Name"
msgstr "Nom d'affichage"

#. module: stock_picking_barcode
#: model:ir.model.fields,field_description:stock_picking_barcode.field_stock_picking__id
#: model:ir.model.fields,field_description:stock_picking_barcode.field_stock_picking_type__id
msgid "ID"
msgstr ""

#. module: stock_picking_barcode
#: model:ir.model.fields,field_description:stock_picking_barcode.field_stock_picking____last_update
#: model:ir.model.fields,field_description:stock_picking_barcode.field_stock_picking_type____last_update
msgid "Last Modified on"
msgstr "Dernière modification le"

#. module: stock_picking_barcode
#: model:ir.model.fields,field_description:stock_picking_barcode.field_stock_picking_type__nomenclature_id
msgid "Nomenclature"
msgstr "Nomenclature"

#. module: stock_picking_barcode
#: model:ir.model,name:stock_picking_barcode.model_stock_picking_type
msgid "Picking Type"
msgstr "Type de préparation"

#. module: stock_picking_barcode
#: model:ir.model.fields,field_description:stock_picking_barcode.field_stock_picking__scan_barcode
#: model:ir.model.fields,field_description:stock_picking_barcode.field_stock_picking_type__scan_barcode
msgid "Scan from this Operation Type"
msgstr "Numériser depuis ce type d'opération"

#. module: stock_picking_barcode
#: code:addons/stock_picking_barcode/models/stock_picking.py:0
#, python-format
msgid "The barcode \"%(barcode)s\" doesn't correspond to a proper product."
msgstr ""

#. module: stock_picking_barcode
#: model:ir.model.fields,help:stock_picking_barcode.field_stock_picking_type__nomenclature_id
msgid ""
"This field allows you to choose the Barcodes Nomenclature\n"
" to apply when scanning."
msgstr ""
"Ce champ vous permet de choisir la nomenclature des code-barres à appliquer lors de la numérisation."

#. module: stock_picking_barcode
#: model:ir.model,name:stock_picking_barcode.model_stock_picking
msgid "Transfer"
msgstr "Transfert"

#. module: stock_picking_barcode
#: model:ir.model.fields,help:stock_picking_barcode.field_stock_picking___barcode_scanned
msgid "Value of the last barcode scanned."
msgstr "Valeur du dernier code-barres scanné."

#. module: stock_picking_barcode
#: model:ir.model.fields,help:stock_picking_barcode.field_stock_picking__scan_barcode
#: model:ir.model.fields,help:stock_picking_barcode.field_stock_picking_type__scan_barcode
msgid ""
"When this box is checked, a new “Scan” field is displayed on\n"
" transfers of this type of operation to allow scanning of a barcode."
msgstr "Lorsque cette case est cochée, un nouveau champ “Numériser” est affiché sur les transferts de ce type d’opération afin de permettre de numériser un code-barres."

#. module: stock_picking_barcode
#: code:addons/stock_picking_barcode/models/stock_picking.py:0
#, python-format
msgid "Wrong barcode"
msgstr "Mauvais code-barres."
18 changes: 18 additions & 0 deletions stock_picking_barcode/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Stock Picking Barcode
=====================

Context
-------
The module allows scanning a barcode by type of operation.

Description
-----------

This module allows, when the user scans a product, to find a candidate movement line (or create one if necessary)
and process it by incrementing its 'Done' field.
In this case, we will use a nomenclature with a rule of type 'Weighed Item'
and the barcode model should look like this: `.......{NNDDD}`

Contributors
------------
* Numigi (tm) and all its contributors (https://bit.ly/numigiens)
4 changes: 4 additions & 0 deletions stock_picking_barcode/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# © 2024 Numigi (tm) and all its contributors (https://bit.ly/numigiens)
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

from . import models

Check notice on line 4 in stock_picking_barcode/__init__.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

stock_picking_barcode/__init__.py#L4

'.models' imported but unused (F401)
21 changes: 21 additions & 0 deletions stock_picking_barcode/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# © 2024 Numigi (tm) and all its contributors (https://bit.ly/numigiens)
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

{

Check warning on line 4 in stock_picking_barcode/__manifest__.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

stock_picking_barcode/__manifest__.py#L4

Statement seems to have no effect
"name": "Stock Picking Barcode",
"version": "14.0.1.0.0",
"author": "Numigi",
"maintainer": "Numigi",
"website": "https://bit.ly/numigi-com",
"license": "LGPL-3",
"category": "Product",
"summary": "Scan a barcode by picking",
"depends": ["stock", "barcodes"],
"data": [
"data/picking_barcodes_data.xml",
"views/stock_picking_view.xml",
"views/stock_picking_type_view.xml",
],
"installable": True,
"application": False,
}
15 changes: 15 additions & 0 deletions stock_picking_barcode/data/picking_barcodes_data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo noupdate="1">
<record id="picking_barcode_nomenclature" model="barcode.nomenclature">
<field name="name">Operations/ Detailed Operations</field>
</record>

<record id="barcode_rule_picking_product_weight" model="barcode.rule">
<field name="name">Product Weight</field>
<field name="barcode_nomenclature_id" ref="picking_barcode_nomenclature"/>
<field name="sequence">10</field>
<field name="type">weight</field>
<field name="encoding">any</field>
<field name="pattern">.....{NNNDD}</field>
</record>
</odoo>
5 changes: 5 additions & 0 deletions stock_picking_barcode/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# © 2024 Numigi (tm) and all its contributors (https://bit.ly/numigiens)
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

from . import stock_picking

Check notice on line 4 in stock_picking_barcode/models/__init__.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

stock_picking_barcode/models/__init__.py#L4

'.stock_picking' imported but unused (F401)
from . import stock_picking_type

Check notice on line 5 in stock_picking_barcode/models/__init__.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

stock_picking_barcode/models/__init__.py#L5

'.stock_picking_type' imported but unused (F401)
96 changes: 96 additions & 0 deletions stock_picking_barcode/models/stock_picking.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# © 2024 Numigi (tm) and all its contributors (https://bit.ly/numigiens)
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
from odoo import models, fields, _


class StockPicking(models.Model):
_name = "stock.picking"
_inherit = ["stock.picking", "barcodes.barcode_events_mixin"]

scan_barcode = fields.Boolean(
string="Scan from this Operation Type",
related="picking_type_id.scan_barcode"
)

def on_barcode_scanned(self, barcode):
if not self.scan_barcode or not self.picking_type_id.nomenclature_id:
return
else:
parsed_result = self.picking_type_id.nomenclature_id.parse_barcode(barcode)
if parsed_result["type"] in ["weight", "product"]:
if parsed_result["type"] == "weight":
product_barcode = parsed_result["base_code"]
qty = parsed_result["value"]
else: # product
product_barcode = parsed_result["code"]
qty = 1.0
product = self.env["product.product"].search(
[
"|",
("barcode", "=", product_barcode),
("default_code", "=", product_barcode),
],
limit=1,
)
if product:
if self._check_product(product, qty):
return
return {
"warning": {
"title": _("Wrong barcode"),
"message": _(
'The barcode "%(barcode)s" doesn\'t correspond to a proper product.'
)
% {"barcode": barcode},
}
}

def _check_product(self, product, qty=1.0):
""" This method is called when the user scans a product. Its goal
is to find a candidate move line (or create one, if necessary)
and process it by incrementing its `qty_done` field with the
`qty` parameter.
"""
# Get back the move line to increase. If multiple are found, chose
# arbitrary the first one that doesn't have qty_done set.
# Filter out the ones processed by `_check_location` and the ones already
# having a # destination package.
picking_move_lines = self.move_line_ids_without_package
if not self.show_reserved:
picking_move_lines = self.move_line_nosuggest_ids

corresponding_ml = picking_move_lines.filtered(
lambda ml: ml.product_id.id == product.id
and not ml.result_package_id
and not ml.lots_visible
and not ml.qty_done
)[:1]
if corresponding_ml:
corresponding_ml.qty_done += qty
else:
# If a candidate is not found, we create one here. If the move
# line we add here is linked to a tracked product, we don't
# set a `qty_done`: a next scan of this product will open the
# lots wizard.
picking_type_lots = (
self.picking_type_id.use_create_lots
or self.picking_type_id.use_existing_lots
)
new_move_line = self.move_line_ids.new(
{
"product_id": product.id,
"product_uom_id": product.uom_id.id,
"location_id": self.location_id.id,
"location_dest_id": self.location_dest_id.id,
"qty_done": (product.tracking == "none" and picking_type_lots)
and qty
or 0.0,
"product_uom_qty": 0.0,
"date": fields.datetime.now(),
}
)
if self.show_reserved:
self.move_line_ids_without_package += new_move_line
else:
self.move_line_nosuggest_ids += new_move_line
return True
26 changes: 26 additions & 0 deletions stock_picking_barcode/models/stock_picking_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# © 2024 Numigi (tm) and all its contributors (https://bit.ly/numigiens)
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
from odoo import models, fields


class StockPickingType(models.Model):
_inherit = "stock.picking.type"

def _get_default_nomenclature(self):
return self.env.ref(
"stock_picking_barcode.picking_barcode_nomenclature",
raise_if_not_found=False
)

scan_barcode = fields.Boolean(
string="Scan from this Operation Type",
help="""When this box is checked, a new “Scan” field is displayed on
transfers of this type of operation to allow scanning of a barcode.""",
)
nomenclature_id = fields.Many2one(
"barcode.nomenclature",
string="Nomenclature",
default=_get_default_nomenclature,
help="""This field allows you to choose the Barcodes Nomenclature
to apply when scanning.""",
)
Binary file added stock_picking_barcode/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions stock_picking_barcode/views/stock_picking_type_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>

<record id="stock_picking_type_view_form_inherit" model="ir.ui.view">
<field name="name">Stock Picking Type Form: Scan Barcode</field>
<field name="model">stock.picking.type</field>
<field name="inherit_id" ref="stock.view_picking_type_form"/>
<field name="arch" type="xml">
<sheet position="inside">
<group>
<group name="barcode" string="Barcode">
<field name="scan_barcode"/>
<field
name="nomenclature_id"
attrs="{'invisible': [('scan_barcode', '!=', True)], 'required': [('scan_barcode', '=', True)]}"
/>
</group>
</group>
</sheet>
</field>
</record>

</odoo>
20 changes: 20 additions & 0 deletions stock_picking_barcode/views/stock_picking_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>

<record id="stock_picking_view_form_inherit_stock_barcode" model="ir.ui.view">
<field name="name">Stock Picking Form: Barcode</field>
<field name="model">stock.picking</field>
<field name="inherit_id" ref="stock.view_picking_form"/>
<field name="arch" type="xml">
<field name="owner_id" position="after">
<field name="scan_barcode" invisible="1"/>
<field
name="_barcode_scanned"
widget="picking_barcode_handler"
attrs="{'invisible': [('scan_barcode', '!=', True)]}"
/>
</field>
</field>
</record>

</odoo>

0 comments on commit 5661cff

Please sign in to comment.