From 6cb05bcbe3ecf57e5f6c709303ddc778fff0cf87 Mon Sep 17 00:00:00 2001 From: "robin.keunen" Date: Wed, 27 Feb 2019 15:17:09 +0100 Subject: [PATCH 01/23] [ADD] pos_default_quantity: sets default orderline quantity fixup! [ADD] pos_default_quantity: sets default orderline quantity Signed-off-by: Carmen Bianca BAKKER --- pos_default_quantity/__init__.py | 1 + pos_default_quantity/__openerp__.py | 25 +++++++++++ pos_default_quantity/models/__init__.py | 2 + pos_default_quantity/models/pos_config.py | 15 +++++++ pos_default_quantity/models/product.py | 15 +++++++ pos_default_quantity/static/src/js/pos.js | 43 +++++++++++++++++++ .../static/src/xml/templates.xml | 12 ++++++ pos_default_quantity/views/pos_config.xml | 15 +++++++ pos_default_quantity/views/product_view.xml | 15 +++++++ 9 files changed, 143 insertions(+) create mode 100644 pos_default_quantity/__init__.py create mode 100644 pos_default_quantity/__openerp__.py create mode 100644 pos_default_quantity/models/__init__.py create mode 100644 pos_default_quantity/models/pos_config.py create mode 100644 pos_default_quantity/models/product.py create mode 100644 pos_default_quantity/static/src/js/pos.js create mode 100644 pos_default_quantity/static/src/xml/templates.xml create mode 100644 pos_default_quantity/views/pos_config.xml create mode 100644 pos_default_quantity/views/product_view.xml diff --git a/pos_default_quantity/__init__.py b/pos_default_quantity/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/pos_default_quantity/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/pos_default_quantity/__openerp__.py b/pos_default_quantity/__openerp__.py new file mode 100644 index 0000000000..8c0b3fa376 --- /dev/null +++ b/pos_default_quantity/__openerp__.py @@ -0,0 +1,25 @@ +# coding: utf-8 +# Copyright 2019 Coop IT Easy SCRLfs +# Robin Keunen +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +{ + "name": "Set Default Product Quantity in POS", + "version": "9.0.1.0.0", + "author": "Coop IT Easy SCRLfs, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/pos", + "license": "AGPL-3", + "category": "Point of Sale", + "summary": """ + When adding an to order line, this module sets the quantity to + the default quantity set on the product unit category. + """, + "depends": [ + 'point_of_sale', + ], + 'data': [ + 'views/pos_config.xml', + 'views/product_view.xml', + 'static/src/xml/templates.xml', + ], + 'installable': True, +} diff --git a/pos_default_quantity/models/__init__.py b/pos_default_quantity/models/__init__.py new file mode 100644 index 0000000000..ee0ac33178 --- /dev/null +++ b/pos_default_quantity/models/__init__.py @@ -0,0 +1,2 @@ +from . import pos_config +from . import product diff --git a/pos_default_quantity/models/pos_config.py b/pos_default_quantity/models/pos_config.py new file mode 100644 index 0000000000..e544671363 --- /dev/null +++ b/pos_default_quantity/models/pos_config.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +# © 2016 Robin Keunen, Coop IT Easy SCRL fs +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + + +from openerp import models, fields + + +class PosConfig(models.Model): + _inherit = 'pos.config' + + set_default_product_quantity = fields.Boolean( + string='Sets default product quantity in POS', + default=False, + ) diff --git a/pos_default_quantity/models/product.py b/pos_default_quantity/models/product.py new file mode 100644 index 0000000000..0d9fdfa0b8 --- /dev/null +++ b/pos_default_quantity/models/product.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +# © 2016 Robin Keunen, Coop IT Easy SCRL fs +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + + +from openerp import models, fields + + +class ProductUomCategory(models.Model): + _inherit = 'product.uom.categ' + + pos_default_qty = fields.Float( + string='POS Default Quantity', + default=0, + ) diff --git a/pos_default_quantity/static/src/js/pos.js b/pos_default_quantity/static/src/js/pos.js new file mode 100644 index 0000000000..9dcfa2e283 --- /dev/null +++ b/pos_default_quantity/static/src/js/pos.js @@ -0,0 +1,43 @@ +/* + Copyright 2019 Coop IT Easy SCRLfs + Robin Keunen + License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +*/ + +odoo.define( + 'pos_default_quantity.pos_default_quantity', + + function (require) { + "use strict"; + + var models = require('point_of_sale.models'); + + models.load_models({ + model: 'product.uom.categ', + fields: ['name','pos_default_qty'], + loaded: function (self, unit_categories) { + self.unit_categories = unit_categories; + var unit_categories_by_id = {}; + for (var i = 0, len = unit_categories.length; i < len; i++) { + unit_categories_by_id[unit_categories[i].id] = unit_categories[i]; // eslint-disable-line + } + self.unit_categories_by_id = unit_categories_by_id; + }, + }); + + var orderline_prototype = models.Orderline.prototype; + models.Orderline = models.Orderline.extend({ + initialize: function (attr, options) { + orderline_prototype.initialize.call(this, attr, options); + + var unit = this.get_unit(); + var category = ( + this.pos + .unit_categories_by_id[unit.category_id[0]]); + if (this.pos.config.set_default_product_quantity) { + this.set_quantity(category.pos_default_qty); + } + }, + }); + } +); diff --git a/pos_default_quantity/static/src/xml/templates.xml b/pos_default_quantity/static/src/xml/templates.xml new file mode 100644 index 0000000000..50634d9958 --- /dev/null +++ b/pos_default_quantity/static/src/xml/templates.xml @@ -0,0 +1,12 @@ + + + + + + diff --git a/pos_default_quantity/views/pos_config.xml b/pos_default_quantity/views/pos_config.xml new file mode 100644 index 0000000000..d665245622 --- /dev/null +++ b/pos_default_quantity/views/pos_config.xml @@ -0,0 +1,15 @@ + + + + + pos.config.form.view.inherit + pos.config + + + + + + + + + diff --git a/pos_default_quantity/views/product_view.xml b/pos_default_quantity/views/product_view.xml new file mode 100644 index 0000000000..937921ab9d --- /dev/null +++ b/pos_default_quantity/views/product_view.xml @@ -0,0 +1,15 @@ + + + + + product.uom.categ.form + product.uom.categ + + + + + + + + + From e7ac5cda888d676c31900eeab61b95ba906c195e Mon Sep 17 00:00:00 2001 From: "robin.keunen" Date: Mon, 11 Mar 2019 16:43:33 +0100 Subject: [PATCH 02/23] [ADD] pos_default_quantity: readme Signed-off-by: Carmen Bianca BAKKER --- pos_default_quantity/README.rst | 76 ++++ pos_default_quantity/readme/CONTRIBUTORS.rst | 2 + pos_default_quantity/readme/DESCRIPTION.rst | 3 + .../static/description/index.html | 421 ++++++++++++++++++ 4 files changed, 502 insertions(+) create mode 100644 pos_default_quantity/README.rst create mode 100644 pos_default_quantity/readme/CONTRIBUTORS.rst create mode 100644 pos_default_quantity/readme/DESCRIPTION.rst create mode 100644 pos_default_quantity/static/description/index.html diff --git a/pos_default_quantity/README.rst b/pos_default_quantity/README.rst new file mode 100644 index 0000000000..ab3f3c7faf --- /dev/null +++ b/pos_default_quantity/README.rst @@ -0,0 +1,76 @@ +=================================== +Set Default Product Quantity in POS +=================================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fpos-lightgray.png?logo=github + :target: https://github.com/OCA/pos/tree/9.0-pos-default-quantity/pos_default_quantity + :alt: OCA/pos +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/pos-9-0-pos-default-quantity/pos-9-0-pos-default-quantity-pos_default_quantity + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/184/9.0-pos-default-quantity + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This modules adds a default pos quantity field on the product categories. +When adding a product to a pos order, this module sets the quantity to that +value. + +**Table of contents** + +.. contents:: + :local: + +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 smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Coop IT Easy SCRLfs + +Contributors +~~~~~~~~~~~~ + +* Robin Keunen + + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +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. + +This module is part of the `OCA/pos `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/pos_default_quantity/readme/CONTRIBUTORS.rst b/pos_default_quantity/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000000..64a12c5e2e --- /dev/null +++ b/pos_default_quantity/readme/CONTRIBUTORS.rst @@ -0,0 +1,2 @@ +* Robin Keunen + diff --git a/pos_default_quantity/readme/DESCRIPTION.rst b/pos_default_quantity/readme/DESCRIPTION.rst new file mode 100644 index 0000000000..9b6a0f7085 --- /dev/null +++ b/pos_default_quantity/readme/DESCRIPTION.rst @@ -0,0 +1,3 @@ +This modules adds a default pos quantity field on the product categories. +When adding a product to a pos order, this module sets the quantity to that +value. diff --git a/pos_default_quantity/static/description/index.html b/pos_default_quantity/static/description/index.html new file mode 100644 index 0000000000..0a4e6686a7 --- /dev/null +++ b/pos_default_quantity/static/description/index.html @@ -0,0 +1,421 @@ + + + + + + +Set Default Product Quantity in POS + + + +
+

Set Default Product Quantity in POS

+ + +

Beta License: AGPL-3 OCA/pos Translate me on Weblate Try me on Runbot

+

This modules adds a default pos quantity field on the product categories. +When adding a product to a pos order, this module sets the quantity to that +value.

+

Table of contents

+ +
+

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 smashing it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Coop IT Easy SCRLfs
  • +
+
+ +
+

Maintainers

+

This module is maintained by the OCA.

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

+

This module is part of the OCA/pos project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + From f4c74472d93d666346723a3796cd618db4e3c15e Mon Sep 17 00:00:00 2001 From: "robin.keunen" Date: Mon, 23 Dec 2019 13:26:22 +0100 Subject: [PATCH 03/23] [FIX] pos_default_quantity: don't set default quantity on restored lines When restoring the order from a json, previous code overwrote quantity with default quantity Signed-off-by: Carmen Bianca BAKKER --- pos_default_quantity/static/src/js/pos.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pos_default_quantity/static/src/js/pos.js b/pos_default_quantity/static/src/js/pos.js index 9dcfa2e283..cb66b0b935 100644 --- a/pos_default_quantity/static/src/js/pos.js +++ b/pos_default_quantity/static/src/js/pos.js @@ -30,10 +30,16 @@ odoo.define( initialize: function (attr, options) { orderline_prototype.initialize.call(this, attr, options); + // don't set default quantity on restored lines + if (options.json) { + return; + } + var unit = this.get_unit(); var category = ( this.pos .unit_categories_by_id[unit.category_id[0]]); + if (this.pos.config.set_default_product_quantity) { this.set_quantity(category.pos_default_qty); } From e920da67bbfdc61e37d8b12b7465b76fc624524d Mon Sep 17 00:00:00 2001 From: Vincent Van Rossem Date: Wed, 15 Apr 2020 15:57:46 +0200 Subject: [PATCH 04/23] [MIG] pos_default_quantity: migration to 10.0 - followed oca guidelines - not tested on odoo 10.0 Signed-off-by: Carmen Bianca BAKKER --- pos_default_quantity/{__openerp__.py => __manifest__.py} | 2 +- pos_default_quantity/models/pos_config.py | 2 +- pos_default_quantity/models/product.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) rename pos_default_quantity/{__openerp__.py => __manifest__.py} (96%) diff --git a/pos_default_quantity/__openerp__.py b/pos_default_quantity/__manifest__.py similarity index 96% rename from pos_default_quantity/__openerp__.py rename to pos_default_quantity/__manifest__.py index 8c0b3fa376..073d974f50 100644 --- a/pos_default_quantity/__openerp__.py +++ b/pos_default_quantity/__manifest__.py @@ -4,7 +4,7 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). { "name": "Set Default Product Quantity in POS", - "version": "9.0.1.0.0", + "version": "10.0.1.0.0", "author": "Coop IT Easy SCRLfs, Odoo Community Association (OCA)", "website": "https://github.com/OCA/pos", "license": "AGPL-3", diff --git a/pos_default_quantity/models/pos_config.py b/pos_default_quantity/models/pos_config.py index e544671363..f5577242bf 100644 --- a/pos_default_quantity/models/pos_config.py +++ b/pos_default_quantity/models/pos_config.py @@ -3,7 +3,7 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from openerp import models, fields +from odoo import models, fields class PosConfig(models.Model): diff --git a/pos_default_quantity/models/product.py b/pos_default_quantity/models/product.py index 0d9fdfa0b8..08ffbde2a1 100644 --- a/pos_default_quantity/models/product.py +++ b/pos_default_quantity/models/product.py @@ -3,7 +3,7 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from openerp import models, fields +from odoo import models, fields class ProductUomCategory(models.Model): From 6aebfb76cbd530b67e2a14c6e6b3171bea79ca8c Mon Sep 17 00:00:00 2001 From: Vincent Van Rossem Date: Wed, 15 Apr 2020 16:02:41 +0200 Subject: [PATCH 05/23] [MIG] pos_default_quantity: migration to 11.0 - followed oca guidelines - not tested on odoo 11.0 Signed-off-by: Carmen Bianca BAKKER --- pos_default_quantity/__manifest__.py | 3 +-- pos_default_quantity/models/pos_config.py | 1 - pos_default_quantity/models/product.py | 1 - 3 files changed, 1 insertion(+), 4 deletions(-) diff --git a/pos_default_quantity/__manifest__.py b/pos_default_quantity/__manifest__.py index 073d974f50..6b1271bc65 100644 --- a/pos_default_quantity/__manifest__.py +++ b/pos_default_quantity/__manifest__.py @@ -1,10 +1,9 @@ -# coding: utf-8 # Copyright 2019 Coop IT Easy SCRLfs # Robin Keunen # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). { "name": "Set Default Product Quantity in POS", - "version": "10.0.1.0.0", + "version": "11.0.1.0.0", "author": "Coop IT Easy SCRLfs, Odoo Community Association (OCA)", "website": "https://github.com/OCA/pos", "license": "AGPL-3", diff --git a/pos_default_quantity/models/pos_config.py b/pos_default_quantity/models/pos_config.py index f5577242bf..adc3b742bb 100644 --- a/pos_default_quantity/models/pos_config.py +++ b/pos_default_quantity/models/pos_config.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # © 2016 Robin Keunen, Coop IT Easy SCRL fs # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). diff --git a/pos_default_quantity/models/product.py b/pos_default_quantity/models/product.py index 08ffbde2a1..85b59454f9 100644 --- a/pos_default_quantity/models/product.py +++ b/pos_default_quantity/models/product.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # © 2016 Robin Keunen, Coop IT Easy SCRL fs # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). From ecd706fb5e3cbba090e550f253e994d44060fb8f Mon Sep 17 00:00:00 2001 From: Vincent Van Rossem Date: Wed, 15 Apr 2020 16:06:08 +0200 Subject: [PATCH 06/23] [MIG] pos_default_quantity: migration to 12.0 - followed oca guidelines Signed-off-by: Carmen Bianca BAKKER --- pos_default_quantity/__manifest__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pos_default_quantity/__manifest__.py b/pos_default_quantity/__manifest__.py index 6b1271bc65..3f3044304b 100644 --- a/pos_default_quantity/__manifest__.py +++ b/pos_default_quantity/__manifest__.py @@ -3,7 +3,7 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). { "name": "Set Default Product Quantity in POS", - "version": "11.0.1.0.0", + "version": "12.0.1.0.0", "author": "Coop IT Easy SCRLfs, Odoo Community Association (OCA)", "website": "https://github.com/OCA/pos", "license": "AGPL-3", From 8c84df2a701107d934224e03e10800b61a730e21 Mon Sep 17 00:00:00 2001 From: Vincent Van Rossem Date: Wed, 15 Apr 2020 17:24:14 +0200 Subject: [PATCH 07/23] [FIX] pos_default_quantity: adaptation to 12.0 Signed-off-by: Carmen Bianca BAKKER --- pos_default_quantity/models/product.py | 4 ++-- pos_default_quantity/static/src/js/pos.js | 2 +- .../static/src/xml/templates.xml | 6 ++---- pos_default_quantity/views/pos_config.xml | 18 ++++++++++++++---- pos_default_quantity/views/product_view.xml | 6 +++--- 5 files changed, 22 insertions(+), 14 deletions(-) diff --git a/pos_default_quantity/models/product.py b/pos_default_quantity/models/product.py index 85b59454f9..51a97b1bf5 100644 --- a/pos_default_quantity/models/product.py +++ b/pos_default_quantity/models/product.py @@ -5,8 +5,8 @@ from odoo import models, fields -class ProductUomCategory(models.Model): - _inherit = 'product.uom.categ' +class UoMCategory(models.Model): + _inherit = 'uom.category' pos_default_qty = fields.Float( string='POS Default Quantity', diff --git a/pos_default_quantity/static/src/js/pos.js b/pos_default_quantity/static/src/js/pos.js index cb66b0b935..489d2931c1 100644 --- a/pos_default_quantity/static/src/js/pos.js +++ b/pos_default_quantity/static/src/js/pos.js @@ -13,7 +13,7 @@ odoo.define( var models = require('point_of_sale.models'); models.load_models({ - model: 'product.uom.categ', + model: 'uom.category', fields: ['name','pos_default_qty'], loaded: function (self, unit_categories) { self.unit_categories = unit_categories; diff --git a/pos_default_quantity/static/src/xml/templates.xml b/pos_default_quantity/static/src/xml/templates.xml index 50634d9958..02e9e39132 100644 --- a/pos_default_quantity/static/src/xml/templates.xml +++ b/pos_default_quantity/static/src/xml/templates.xml @@ -1,11 +1,9 @@ -