diff --git a/beesdoo_product/__openerp__.py b/beesdoo_product/__openerp__.py
index dfee764..ac8eb60 100644
--- a/beesdoo_product/__openerp__.py
+++ b/beesdoo_product/__openerp__.py
@@ -20,12 +20,13 @@
'version': '0.1',
# any module necessary for this one to work correctly
- 'depends': ['beesdoo_base', 'product', 'point_of_sale'],
+ 'depends': ['beesdoo_base', 'product', 'point_of_sale','pos_price_to_weight'],
# always loaded
'data': [
'data/product_label.xml',
'data/barcode_rule.xml',
+ 'data/product_sequence.xml',
'views/beesdoo_product.xml',
'wizard/views/label_printing_utils.xml',
'security/ir.model.access.csv',
diff --git a/beesdoo_product/data/product_sequence.xml b/beesdoo_product/data/product_sequence.xml
new file mode 100644
index 0000000..59ce1be
--- /dev/null
+++ b/beesdoo_product/data/product_sequence.xml
@@ -0,0 +1,14 @@
+
+
+
+
+ Internal reference
+ product.internal.code
+
+ 5
+
+ 1
+
+
+
+
\ No newline at end of file
diff --git a/beesdoo_product/models/beesdoo_product.py b/beesdoo_product/models/beesdoo_product.py
index a9397ed..858ac32 100644
--- a/beesdoo_product/models/beesdoo_product.py
+++ b/beesdoo_product/models/beesdoo_product.py
@@ -26,7 +26,7 @@ class BeesdooProduct(models.Model):
label_last_printed = fields.Datetime('Label last printed on')
note = fields.Text('Comments')
-
+
# S0023 : List_price = Price HTVA, so add a suggested price
list_price = fields.Float(string='exVAT Price')
suggested_price = fields.Float(string='Suggested exVAT Price', compute='_compute_cost', readOnly=True)
@@ -36,15 +36,28 @@ class BeesdooProduct(models.Model):
@api.one
def generate_barcode(self):
- print 'generate barcode', self.barcode, self.barcode == ''
- rule = self.env['barcode.rule'].search([('name', '=', 'Beescoop Product Barcodes')])[0]
- size = 13 - len(rule.pattern)
- ean = rule.pattern + str(uuid.uuid4().fields[-1])[:size]
- bc = ean[0:12] + str(self.env['barcode.nomenclature'].ean_checksum(ean))
- # Make sure there is no other active member with the same barcode
- while(self.search_count([('barcode', '=', bc)]) > 1):
+ if self.to_weight:
+ print 'generate to weight barcode', self.barcode, self.barcode == ''
+ seq_internal_code = self.env.ref('beesdoo_product.seq_ean_product_internal_ref')
+ bc = ''
+ if not self.default_code:
+ rule = self.env['barcode.rule'].search([('name', '=', 'Price Barcodes (Computed Weight) 2 Decimals')])[0]
+ default_code = seq_internal_code.next_by_id()
+ while(self.search_count([('default_code', '=', default_code)]) > 1):
+ default_code = seq_internal_code.next_by_id()
+ self.default_code = default_code
+ ean = '02' + self.default_code[0:5] + '000000'
+ bc = ean[0:12] + str(self.env['barcode.nomenclature'].ean_checksum(ean))
+ else:
+ print 'generate barcode', self.barcode, self.barcode == ''
+ rule = self.env['barcode.rule'].search([('name', '=', 'Beescoop Product Barcodes')])[0]
+ size = 13 - len(rule.pattern)
ean = rule.pattern + str(uuid.uuid4().fields[-1])[:size]
bc = ean[0:12] + str(self.env['barcode.nomenclature'].ean_checksum(ean))
+ # Make sure there is no other active member with the same barcode
+ while(self.search_count([('barcode', '=', bc)]) > 1):
+ ean = rule.pattern + str(uuid.uuid4().fields[-1])[:size]
+ bc = ean[0:12] + str(self.env['barcode.nomenclature'].ean_checksum(ean))
print 'barcode :', bc
self.barcode = bc
diff --git a/pos_price_to_weight/README.rst b/pos_price_to_weight/README.rst
new file mode 100644
index 0000000..82f9a45
--- /dev/null
+++ b/pos_price_to_weight/README.rst
@@ -0,0 +1,105 @@
+.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
+ :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
+ :alt: License: AGPL-3
+
+===============================
+Point of Sale - Price to Weight
+===============================
+
+This module extends Odoo Point Of Sale features, to allow to scan barcode
+with price and to compute according quantity.
+
+In Odoo by default, there are three types of barcode rules for products.
+
+* 'Unit Product' (type='product'). Scanning a product will add a unit of this
+ product to the current order.
+* 'Priced product' (type='price'). A price is extracted from the barcode, and
+ a new line with the given price and a quantity = 1 is added to the current
+ order.
+* 'Weighted product' (type='weight). A weight is extracted from the barcode,
+ and a new line with the given weight, and a computed price
+ (quantity * Unit price) is added to the current order.
+
+This module add a new option:
+
+* 'Priced Product (Computed Weight)' (type='price_to_weight'). A price is
+ extracted from the barcode, and a new line with the given price, and a
+ computed quantity (Price / Unit Price) is added to the current order.
+
+.. image:: /pos_price_to_weight/static/description/barcode_rule.png
+ :width: 800 px
+
+This module is usefull in shops with products scaled, to manage correctly
+stock quantities.
+
+Samples
+
+* Given a product with a unit price of 1,50€ / kg
+* The barcode is 0212345{NNNDD}x where:
+ * 02 is the prefix of the barcode rule
+ * 12345 is the product number
+ * {NNNDD} is the price of the scaled product
+ * x is the control digit
+
+if {NNNDD} is 00265, the price is so 2,65€ and the according quantity is
+2,65€ / 1,5 €/kg = 1,767 kg
+
+.. image:: /pos_price_to_weight/static/description/pos_test_1.png
+ :width: 800 px
+
+if {NNNDD} is 00810, the price is so 8,10€ and the according quantity is
+8,10€ / 1,5 €/kg = 5,400 kg
+
+.. image:: /pos_price_to_weight/static/description/pos_test_2.png
+ :width: 800 px
+
+
+Configuration
+=============
+
+* Go to 'Point of Sale' / 'Configuration' / 'Barcode Nomenclatures'
+* Edit your barcode rules, according to your barcodes settings
+
+Usage
+=====
+
+.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
+ :alt: Try me on Runbot
+ :target: https://runbot.odoo-community.org/runbot/184/9.0
+
+Bug Tracker
+===========
+
+Bugs are tracked on `GitHub Issues
+`_. In case of trouble, please
+check there if your issue has already been reported. If you spotted it first,
+help us smash it by providing detailed and welcomed feedback.
+
+Credits
+=======
+
+Images
+------
+
+Icon parts come from http://icons8.com
+
+Contributors
+------------
+
+* Sylvain LE GAL
+
+
+Maintainer
+----------
+
+.. image:: https://odoo-community.org/logo.png
+ :alt: Odoo Community Association
+ :target: https://odoo-community.org
+
+This module is maintained by the OCA.
+
+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.
+
+To contribute to this module, please visit https://odoo-community.org.
diff --git a/pos_price_to_weight/__init__.py b/pos_price_to_weight/__init__.py
new file mode 100644
index 0000000..a0fdc10
--- /dev/null
+++ b/pos_price_to_weight/__init__.py
@@ -0,0 +1,2 @@
+# -*- coding: utf-8 -*-
+from . import models
diff --git a/pos_price_to_weight/__openerp__.py b/pos_price_to_weight/__openerp__.py
new file mode 100644
index 0000000..1ae0f7b
--- /dev/null
+++ b/pos_price_to_weight/__openerp__.py
@@ -0,0 +1,25 @@
+# -*- coding: utf-8 -*-
+# Copyright (C) 2017-Today: La Louve ()
+# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
+# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
+
+{
+ 'name': 'Point of Sale - Price to Weight',
+ 'version': '9.0.1.0.0',
+ 'category': 'Point Of Sale',
+ 'summary': 'Compute weight based on barcodes with prices',
+ 'author': 'La Louve, GRAP, Odoo Community Association (OCA)',
+ 'website': 'http://www.lalouve.net/',
+ 'license': 'AGPL-3',
+ 'depends': [
+ 'point_of_sale',
+ ],
+ 'data': [
+ 'data/barcode_rule.xml',
+ 'static/src/xml/templates.xml',
+ ],
+ 'demo': [
+ 'demo/product_product.xml',
+ ],
+ 'installable': True,
+}
diff --git a/pos_price_to_weight/data/barcode_rule.xml b/pos_price_to_weight/data/barcode_rule.xml
new file mode 100644
index 0000000..29db2ac
--- /dev/null
+++ b/pos_price_to_weight/data/barcode_rule.xml
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+ Price Barcodes (Computed Weight) 2 Decimals
+
+ price_to_weight
+ 02.....{NNNDD}
+ 15
+ ean13
+
+
+
diff --git a/pos_price_to_weight/demo/product_product.xml b/pos_price_to_weight/demo/product_product.xml
new file mode 100644
index 0000000..e1d6204
--- /dev/null
+++ b/pos_price_to_weight/demo/product_product.xml
@@ -0,0 +1,18 @@
+
+
+
+
+
+
+ Apples (with Price To Weight Barcode)
+ 0212345000007
+ 1.50
+
+
+
+
+
diff --git a/pos_price_to_weight/i18n/ca.po b/pos_price_to_weight/i18n/ca.po
new file mode 100644
index 0000000..00ca1b8
--- /dev/null
+++ b/pos_price_to_weight/i18n/ca.po
@@ -0,0 +1,36 @@
+# Translation of Odoo Server.
+# This file contains the translation of the following modules:
+# * pos_price_to_weight
+#
+# Translators:
+# Marc Tormo i Bochaca , 2017
+msgid ""
+msgstr ""
+"Project-Id-Version: Odoo Server 9.0c\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2017-06-09 03:08+0000\n"
+"PO-Revision-Date: 2017-06-09 03:08+0000\n"
+"Last-Translator: Marc Tormo i Bochaca , 2017\n"
+"Language-Team: Catalan (https://www.transifex.com/oca/teams/23907/ca/)\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: \n"
+"Language: ca\n"
+"Plural-Forms: nplurals=2; plural=(n != 1);\n"
+
+#. module: pos_price_to_weight
+#: model:product.product,name:pos_price_to_weight.product_price_to_weight_barcode
+#: model:product.template,name:pos_price_to_weight.product_price_to_weight_barcode_product_template
+msgid "Apples (with Price To Weight Barcode)"
+msgstr "Pomes (amb preu per pes de codi de barres)"
+
+#. module: pos_price_to_weight
+#: code:addons/pos_price_to_weight/models/barcode_rule.py:16
+#, python-format
+msgid "Priced Product (Computed Weight)"
+msgstr "Producte amb preu (pes automatitzat)"
+
+#. module: pos_price_to_weight
+#: model:ir.model,name:pos_price_to_weight.model_barcode_rule
+msgid "barcode.rule"
+msgstr "barcode.rule"
diff --git a/pos_price_to_weight/i18n/fr.po b/pos_price_to_weight/i18n/fr.po
new file mode 100644
index 0000000..51169c2
--- /dev/null
+++ b/pos_price_to_weight/i18n/fr.po
@@ -0,0 +1,36 @@
+# Translation of Odoo Server.
+# This file contains the translation of the following modules:
+# * pos_price_to_weight
+#
+# Translators:
+# OCA Transbot , 2017
+msgid ""
+msgstr ""
+"Project-Id-Version: Odoo Server 9.0c\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2017-06-09 03:08+0000\n"
+"PO-Revision-Date: 2017-06-09 03:08+0000\n"
+"Last-Translator: OCA Transbot , 2017\n"
+"Language-Team: French (https://www.transifex.com/oca/teams/23907/fr/)\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: \n"
+"Language: fr\n"
+"Plural-Forms: nplurals=2; plural=(n > 1);\n"
+
+#. module: pos_price_to_weight
+#: model:product.product,name:pos_price_to_weight.product_price_to_weight_barcode
+#: model:product.template,name:pos_price_to_weight.product_price_to_weight_barcode_product_template
+msgid "Apples (with Price To Weight Barcode)"
+msgstr "Pommes (Avec un code barre Prix vers Pois)"
+
+#. module: pos_price_to_weight
+#: code:addons/pos_price_to_weight/models/barcode_rule.py:16
+#, python-format
+msgid "Priced Product (Computed Weight)"
+msgstr "Code Barre Prix (Poid calculé)"
+
+#. module: pos_price_to_weight
+#: model:ir.model,name:pos_price_to_weight.model_barcode_rule
+msgid "barcode.rule"
+msgstr ""
diff --git a/pos_price_to_weight/models/__init__.py b/pos_price_to_weight/models/__init__.py
new file mode 100644
index 0000000..7173a15
--- /dev/null
+++ b/pos_price_to_weight/models/__init__.py
@@ -0,0 +1,2 @@
+# -*- coding: utf-8 -*-
+from . import barcode_rule
diff --git a/pos_price_to_weight/models/barcode_rule.py b/pos_price_to_weight/models/barcode_rule.py
new file mode 100644
index 0000000..52f6e36
--- /dev/null
+++ b/pos_price_to_weight/models/barcode_rule.py
@@ -0,0 +1,17 @@
+# -*- coding: utf-8 -*-
+# Copyright (C) 2017-Today: La Louve ()
+# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
+# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
+
+from openerp import _, api, models
+
+
+class BarcodeRule(models.Model):
+ _inherit = 'barcode.rule'
+
+ @api.model
+ def _get_type_selection(self):
+ res = super(BarcodeRule, self)._get_type_selection()
+ res.append(
+ ('price_to_weight', _('Priced Product (Computed Weight)')))
+ return res
diff --git a/pos_price_to_weight/static/description/barcode_rule.png b/pos_price_to_weight/static/description/barcode_rule.png
new file mode 100644
index 0000000..e4aba69
Binary files /dev/null and b/pos_price_to_weight/static/description/barcode_rule.png differ
diff --git a/pos_price_to_weight/static/description/icon.png b/pos_price_to_weight/static/description/icon.png
new file mode 100644
index 0000000..e45fc5c
Binary files /dev/null and b/pos_price_to_weight/static/description/icon.png differ
diff --git a/pos_price_to_weight/static/description/pos_test_1.png b/pos_price_to_weight/static/description/pos_test_1.png
new file mode 100644
index 0000000..40022e5
Binary files /dev/null and b/pos_price_to_weight/static/description/pos_test_1.png differ
diff --git a/pos_price_to_weight/static/description/pos_test_2.png b/pos_price_to_weight/static/description/pos_test_2.png
new file mode 100644
index 0000000..773401d
Binary files /dev/null and b/pos_price_to_weight/static/description/pos_test_2.png differ
diff --git a/pos_price_to_weight/static/src/js/models.js b/pos_price_to_weight/static/src/js/models.js
new file mode 100644
index 0000000..5c0777b
--- /dev/null
+++ b/pos_price_to_weight/static/src/js/models.js
@@ -0,0 +1,38 @@
+///*
+// Copyright (C) 2017-Today: La Louve ()
+// @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
+// License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
+//*/
+
+
+odoo.define('pos_price_to_weight.models', function (require) {
+ "use strict";
+
+ var models = require('point_of_sale.models');
+
+ var _super_PosModel = models.PosModel.prototype;
+
+ models.PosModel = models.PosModel.extend({
+
+ scan_product: function(parsed_code) {
+ if (! (parsed_code.type === 'price_to_weight')){
+ // Normal behaviour
+ return _super_PosModel.scan_product.apply(this, [parsed_code]);
+ }
+ // Compute quantity, based on price and unit price
+ var selectedOrder = this.get_order();
+ var product = this.db.get_product_by_barcode(parsed_code.base_code);
+ if(!product){
+ return false;
+ }
+ var quantity = 0;
+ var price = parseFloat(parsed_code.value) || 0;
+ 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/static/src/js/screens.js b/pos_price_to_weight/static/src/js/screens.js
new file mode 100644
index 0000000..74ad0ce
--- /dev/null
+++ b/pos_price_to_weight/static/src/js/screens.js
@@ -0,0 +1,22 @@
+/*
+ Copyright (C) 2017-Today: La Louve ()
+ @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
+ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
+*/
+
+
+odoo.define('pos_price_to_weight.screens', function (require) {
+ "use strict";
+
+ var screens = require('point_of_sale.screens');
+
+ screens.ScreenWidget.include({
+ show: function(){
+ this._super();
+ var self = this;
+ this.pos.barcode_reader.set_action_callback({
+ 'price_to_weight': _.bind(self.barcode_product_action, self),
+ });
+ },
+ });
+});
diff --git a/pos_price_to_weight/static/src/xml/templates.xml b/pos_price_to_weight/static/src/xml/templates.xml
new file mode 100644
index 0000000..98da0a7
--- /dev/null
+++ b/pos_price_to_weight/static/src/xml/templates.xml
@@ -0,0 +1,17 @@
+
+
+
+
+
+
+
+
+
+
+
+
+