Skip to content

Commit

Permalink
[IMP] sale_input_barcode: add settings for sol management
Browse files Browse the repository at this point in the history
  • Loading branch information
SylweKra committed Feb 24, 2025
1 parent 8938809 commit 9680ac5
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 6 deletions.
4 changes: 1 addition & 3 deletions sale_input_barcode/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
"sale_management",
"barcode_action",
],
"data": [
"views/sale.xml",
],
"data": ["views/sale.xml", "views/sale_input_settings_view.xml"],
"demo": [],
}
1 change: 1 addition & 0 deletions sale_input_barcode/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from . import product_barcode_line_mixin
from . import res_config_settings
from . import sale_order
2 changes: 2 additions & 0 deletions sale_input_barcode/models/product_barcode_line_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
12 changes: 12 additions & 0 deletions sale_input_barcode/models/res_config_settings.py
Original file line number Diff line number Diff line change
@@ -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,
)
10 changes: 9 additions & 1 deletion sale_input_barcode/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Check warning on line 43 in sale_input_barcode/models/sale_order.py

View check run for this annotation

Codecov / codecov/patch

sale_input_barcode/models/sale_order.py#L43

Added line #L43 was not covered by tests
else:
product_order_line = self.env["sale.order.line"].new(line_vals)
Expand Down
9 changes: 7 additions & 2 deletions sale_input_barcode/readme/USAGE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
20 changes: 20 additions & 0 deletions sale_input_barcode/views/sale_input_settings_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<odoo>
<record id="view_res_config_settings_sale_input_barcode" model="ir.ui.view">
<field name="name">res.config.settings.sale.input.barcode</field>
<field name="model">res.config.settings</field>
<field name="inherit_id" ref="sale.res_config_settings_view_form" />
<field name="arch" type="xml">
<xpath expr="//div[@id='no_edit_order']" position="inside">
<div class="o_setting_left_pane">
<field name="sale_barcode_update_existing_line" />
</div>
<div class="o_setting_right_pane">
<label for="sale_barcode_update_existing_line" />
<div class="text-muted">
Instead of creating a new sale order line it increases the quantity for each barcode scan
</div>
</div>
</xpath>
</field>
</record>
</odoo>

0 comments on commit 9680ac5

Please sign in to comment.