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/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 + + + +
+ +
+
+
+
+
+
+