diff --git a/pos_price_to_weight/__manifest__.py b/pos_price_to_weight/__manifest__.py index 869f9e82..d3a58bdd 100644 --- a/pos_price_to_weight/__manifest__.py +++ b/pos_price_to_weight/__manifest__.py @@ -17,6 +17,7 @@ 'data': [ 'data/barcode_rule.xml', 'views/assets.xml', + 'views/view_pos_config.xml', ], 'demo': [ 'demo/product_product.xml', diff --git a/pos_price_to_weight/demo/product_product.xml b/pos_price_to_weight/demo/product_product.xml index 14d56719..856bd676 100644 --- a/pos_price_to_weight/demo/product_product.xml +++ b/pos_price_to_weight/demo/product_product.xml @@ -11,6 +11,8 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). Apples (with Price To Weight Barcode) 0212345000007 1.50 + True + True diff --git a/pos_price_to_weight/models/__init__.py b/pos_price_to_weight/models/__init__.py index ba6651a1..d050eeca 100644 --- a/pos_price_to_weight/models/__init__.py +++ b/pos_price_to_weight/models/__init__.py @@ -1 +1,2 @@ from . import barcode_rule +from . import pos_config diff --git a/pos_price_to_weight/models/pos_config.py b/pos_price_to_weight/models/pos_config.py new file mode 100644 index 00000000..3c5fc938 --- /dev/null +++ b/pos_price_to_weight/models/pos_config.py @@ -0,0 +1,22 @@ +# Copyright 2020 Coop IT Easy - Manuel Claeys Bouuaert +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import fields, models + + +class PosConfig(models.Model): + _inherit = 'pos.config' + + pos_price_to_weight_price_field_id = fields.Many2one( + string="Price To Weight Field", + comodel_name="ir.model.fields", + domain=[("model", "=", "product.product"), ("ttype", "=", "float")], + required=True, + default=lambda x: x._default_pos_price_to_weight_price_field_id(), + ) + + pos_price_to_weight_price_field_name = fields.Char( + related="pos_price_to_weight_price_field_id.name") + + def _default_pos_price_to_weight_price_field_id(self): + return self.env.ref("product.field_product_product__list_price") diff --git a/pos_price_to_weight/readme/CONFIGURE.rst b/pos_price_to_weight/readme/CONFIGURE.rst index d1b66752..cfdb4b36 100644 --- a/pos_price_to_weight/readme/CONFIGURE.rst +++ b/pos_price_to_weight/readme/CONFIGURE.rst @@ -1,2 +1,15 @@ -* Go to 'Point of Sale' / 'Configuration' / 'Barcode Nomenclatures' +* Go to Point of Sale > Configuration > Barcode Nomenclatures * Edit your barcode rules, according to your barcodes settings + +* Go to Point of Sale > Configuration > Point of Sale +* Select the 'Unit Price' field that will be used to convert the price to weight. + +.. image:: ../static/description/pos_config_form.png + :width: 800 px + +**Note:** + +By default, this is the field ``list_price`` that will be used. +If you want to use a custom field, it should be loaded in the javascript file calling + +``models.load_fields("product.product", ['my_custom_field']);`` diff --git a/pos_price_to_weight/static/description/pos_config_form.png b/pos_price_to_weight/static/description/pos_config_form.png new file mode 100644 index 00000000..7ab0234a Binary files /dev/null and b/pos_price_to_weight/static/description/pos_config_form.png differ diff --git a/pos_price_to_weight/static/src/js/models.js b/pos_price_to_weight/static/src/js/models.js index 5c0777be..cc2892d4 100644 --- a/pos_price_to_weight/static/src/js/models.js +++ b/pos_price_to_weight/static/src/js/models.js @@ -27,8 +27,11 @@ odoo.define('pos_price_to_weight.models', function (require) { } var quantity = 0; var price = parseFloat(parsed_code.value) || 0; - if (price !== 0 && product.price !== 0){ - quantity = price / product.price; + + var product_price = product[this.config.pos_price_to_weight_price_field_name]; + + if (price !== 0 && product_price !== 0){ + quantity = price / product_price; } selectedOrder.add_product(product, {quantity: quantity, merge: false}); return true; diff --git a/pos_price_to_weight/views/view_pos_config.xml b/pos_price_to_weight/views/view_pos_config.xml new file mode 100644 index 00000000..c3db1ab6 --- /dev/null +++ b/pos_price_to_weight/views/view_pos_config.xml @@ -0,0 +1,27 @@ + + + + + + pos.config + + + + + + + + Unit Price field used when converting scanned weight to price. + + + + + + + + + + +