From 96cb8924bf5516c4125627a47bbca9fc8d4c6640 Mon Sep 17 00:00:00 2001 From: SoSylwe Date: Mon, 24 Feb 2025 14:23:43 +0100 Subject: [PATCH] [IMP] sale_input_barcode: add settings for sol management --- sale_input_barcode/README.rst | 9 +++++++-- sale_input_barcode/__manifest__.py | 4 +--- sale_input_barcode/models/__init__.py | 1 + .../models/product_barcode_line_mixin.py | 2 ++ .../models/res_config_settings.py | 12 +++++++++++ sale_input_barcode/models/sale_order.py | 10 +++++++++- sale_input_barcode/readme/USAGE.rst | 9 +++++++-- .../static/description/index.html | 20 +++++++++++++------ .../views/sale_input_settings_view.xml | 20 +++++++++++++++++++ 9 files changed, 73 insertions(+), 14 deletions(-) create mode 100644 sale_input_barcode/models/res_config_settings.py create mode 100644 sale_input_barcode/views/sale_input_settings_view.xml diff --git a/sale_input_barcode/README.rst b/sale_input_barcode/README.rst index 7044126d151f..cc371e8525f9 100644 --- a/sale_input_barcode/README.rst +++ b/sale_input_barcode/README.rst @@ -55,8 +55,13 @@ Alternatively, If a product is found using the barcode, a new line with that product will be added to the Sales Order. -If a product is already inside the sale order lines, -the quantity will be updated. +By default, each product scan adds a new line to the sales order. +However, you can change this behavior in the sales settings. +To have the system increase the quantity of an existing product line +instead of creating a new one, follow these steps: +#. Go to the Sales Settings section. +#. Locate the option labeled "Increase quantity instead of creating a new line". +#. Check the box to activate this option and save to apply the changes. Bug Tracker =========== diff --git a/sale_input_barcode/__manifest__.py b/sale_input_barcode/__manifest__.py index 7e19210b2bbc..b1fec52c9842 100644 --- a/sale_input_barcode/__manifest__.py +++ b/sale_input_barcode/__manifest__.py @@ -15,8 +15,6 @@ "sale_management", "barcode_action", ], - "data": [ - "views/sale.xml", - ], + "data": ["views/sale.xml", "views/sale_input_settings_view.xml"], "demo": [], } diff --git a/sale_input_barcode/models/__init__.py b/sale_input_barcode/models/__init__.py index 8e4dc36757b1..3215559ddf4c 100644 --- a/sale_input_barcode/models/__init__.py +++ b/sale_input_barcode/models/__init__.py @@ -1,2 +1,3 @@ from . import product_barcode_line_mixin +from . import res_config_settings from . import sale_order diff --git a/sale_input_barcode/models/product_barcode_line_mixin.py b/sale_input_barcode/models/product_barcode_line_mixin.py index e8a3b9a60a55..95962f888687 100644 --- a/sale_input_barcode/models/product_barcode_line_mixin.py +++ b/sale_input_barcode/models/product_barcode_line_mixin.py @@ -29,6 +29,8 @@ def _populate_vals(self, product, barcode_dict): vals = { "product_id": product.id, "product_uom_qty": 1, + "name": product.name, + "price_unit": product.list_price, } if "order_id" in self._fields: order_id = self.env.context.get("order_id") diff --git a/sale_input_barcode/models/res_config_settings.py b/sale_input_barcode/models/res_config_settings.py new file mode 100644 index 000000000000..56f529240ca4 --- /dev/null +++ b/sale_input_barcode/models/res_config_settings.py @@ -0,0 +1,12 @@ +from odoo import fields, models + + +class ResConfigSettings(models.TransientModel): + + _inherit = "res.config.settings" + + sale_barcode_update_existing_line = fields.Boolean( + string="Increase quantity instead of creating a new line", + config_parameter="sale_input_barcode.sale_barcode_update_existing_line", + default=False, + ) diff --git a/sale_input_barcode/models/sale_order.py b/sale_input_barcode/models/sale_order.py index 6806790171f0..73f983307da5 100644 --- a/sale_input_barcode/models/sale_order.py +++ b/sale_input_barcode/models/sale_order.py @@ -31,7 +31,15 @@ def process_barcode(self, barcode): product_order_line = self.order_line.filtered( lambda x: x.product_id.id == line_vals.get("product_id") )[:1] - if product_order_line: + sale_barcode_update_existing_line = ( + self.env["ir.config_parameter"] + .sudo() + .get_param( + "sale_input_barcode.sale_barcode_update_existing_line", + ) + ) + + if product_order_line and sale_barcode_update_existing_line: product_order_line.product_uom_qty += 1 else: product_order_line = self.env["sale.order.line"].new(line_vals) diff --git a/sale_input_barcode/readme/USAGE.rst b/sale_input_barcode/readme/USAGE.rst index 614338b0e13a..23ef21570add 100644 --- a/sale_input_barcode/readme/USAGE.rst +++ b/sale_input_barcode/readme/USAGE.rst @@ -10,5 +10,10 @@ Alternatively, If a product is found using the barcode, a new line with that product will be added to the Sales Order. -If a product is already inside the sale order lines, -the quantity will be updated. +By default, each product scan adds a new line to the sales order. +However, you can change this behavior in the sales settings. +To have the system increase the quantity of an existing product line +instead of creating a new one, follow these steps: +#. Go to the Sales Settings section. +#. Locate the option labeled "Increase quantity instead of creating a new line". +#. Check the box to activate this option and save to apply the changes. diff --git a/sale_input_barcode/static/description/index.html b/sale_input_barcode/static/description/index.html index 9e300637687a..119a6010571c 100644 --- a/sale_input_barcode/static/description/index.html +++ b/sale_input_barcode/static/description/index.html @@ -8,10 +8,11 @@ /* :Author: David Goodger (goodger@python.org) -:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $ +:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $ :Copyright: This stylesheet has been placed in the public domain. Default cascading style sheet for the HTML output of Docutils. +Despite the name, some widely supported CSS2 features are used. See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to customize this style sheet. @@ -274,7 +275,7 @@ margin-left: 2em ; margin-right: 2em } -pre.code .ln { color: grey; } /* line numbers */ +pre.code .ln { color: gray; } /* line numbers */ pre.code, code { background-color: #eeeeee } pre.code .comment, code .comment { color: #5C6576 } pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold } @@ -300,7 +301,7 @@ span.pre { white-space: pre } -span.problematic { +span.problematic, pre.problematic { color: red } span.section-subtitle { @@ -400,8 +401,13 @@

Usage

#. Use a barcode scanner to scan a barcode.

If a product is found using the barcode, a new line with that product will be added to the Sales Order.

-

If a product is already inside the sale order lines, -the quantity will be updated.

+

By default, each product scan adds a new line to the sales order. +However, you can change this behavior in the sales settings. +To have the system increase the quantity of an existing product line +instead of creating a new one, follow these steps: +#. Go to the Sales Settings section. +#. Locate the option labeled “Increase quantity instead of creating a new line”. +#. Check the box to activate this option and save to apply the changes.

Bug Tracker

@@ -422,7 +428,9 @@

Authors

Maintainers

This module is maintained by the OCA.

-Odoo Community Association + +Odoo Community Association +

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.

diff --git a/sale_input_barcode/views/sale_input_settings_view.xml b/sale_input_barcode/views/sale_input_settings_view.xml new file mode 100644 index 000000000000..0979201b9f33 --- /dev/null +++ b/sale_input_barcode/views/sale_input_settings_view.xml @@ -0,0 +1,20 @@ + + + res.config.settings.sale.input.barcode + res.config.settings + + + +
+ +
+
+
+
+
+
+