From 39be72b75d03def50ddc79c0fa0cf908007b755c Mon Sep 17 00:00:00 2001 From: jbeficent Date: Mon, 21 Mar 2016 20:50:44 +0100 Subject: [PATCH 1/8] --- pos_sequence_ref_number/README.rst | 66 +++++++++++++++ pos_sequence_ref_number/__init__.py | 8 ++ pos_sequence_ref_number/__openerp__.py | 27 ++++++ pos_sequence_ref_number/models/__init__.py | 7 ++ pos_sequence_ref_number/models/pos_order.py | 34 ++++++++ pos_sequence_ref_number/static/src/js/main.js | 82 +++++++++++++++++++ .../static/src/xml/pos.xml | 19 +++++ .../views/pos_template.xml | 16 ++++ 8 files changed, 259 insertions(+) create mode 100644 pos_sequence_ref_number/README.rst create mode 100644 pos_sequence_ref_number/__init__.py create mode 100644 pos_sequence_ref_number/__openerp__.py create mode 100644 pos_sequence_ref_number/models/__init__.py create mode 100644 pos_sequence_ref_number/models/pos_order.py create mode 100644 pos_sequence_ref_number/static/src/js/main.js create mode 100644 pos_sequence_ref_number/static/src/xml/pos.xml create mode 100644 pos_sequence_ref_number/views/pos_template.xml diff --git a/pos_sequence_ref_number/README.rst b/pos_sequence_ref_number/README.rst new file mode 100644 index 00000000..83e20870 --- /dev/null +++ b/pos_sequence_ref_number/README.rst @@ -0,0 +1,66 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :alt: License: AGPL-3 + +POS Sequence Ref Number +======================= + +This module loads the Order Number in the POS, so as to produce and print +a sequential POS order number in the POS Ticket. + + +Installation +============ + +Nothing special is needed to install this module. + + + +Usage +===== + +The POS number is generated and shown in the printed POS Ticket. + + +Known issues / Roadmap +====================== + +* If the same user loads two sessions of the same POS session using separate + browsers, duplicate POS numbers can be created. + +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 +`here `_. + + +Credits +======= + +Contributors +------------ + +* Jordi Ballester +* Rafael Blasco +* Ivan Yelizariev +* Antonio Espinosa + + +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 http://odoo-community.org. diff --git a/pos_sequence_ref_number/__init__.py b/pos_sequence_ref_number/__init__.py new file mode 100644 index 00000000..65846b46 --- /dev/null +++ b/pos_sequence_ref_number/__init__.py @@ -0,0 +1,8 @@ +# -*- coding: utf-8 -*- +# © 2016 Acsone SA/NV (http://www.acsone.eu) +# © 2016 Eficent Business and IT Consulting Services S.L. +# (http://www.eficent.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from . import models + diff --git a/pos_sequence_ref_number/__openerp__.py b/pos_sequence_ref_number/__openerp__.py new file mode 100644 index 00000000..d1a1908d --- /dev/null +++ b/pos_sequence_ref_number/__openerp__.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- +# © 2016 Acsone SA/NV (http://www.acsone.eu) +# © 2016 Eficent Business and IT Consulting Services S.L. +# (http://www.eficent.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +{ + 'name': 'POS Sequence Ref Number', + 'version': '8.0.1.0.0', + 'category': 'Point Of Sale', + 'sequence': 1, + 'author': "Eficent Business and IT Consulting Services," + "Acsone SA/NV," + "Odoo Community Association (OCA)", + 'summary': 'Sequential Order numbers for Point of sale', + 'depends': [ + "point_of_sale", + ], + 'data': [ + 'views/pos_template.xml' + ], + 'qweb': [ + 'static/src/xml/pos.xml' + ], + 'installable': True, + 'application': False, + 'auto_install': False, +} diff --git a/pos_sequence_ref_number/models/__init__.py b/pos_sequence_ref_number/models/__init__.py new file mode 100644 index 00000000..4033b4a6 --- /dev/null +++ b/pos_sequence_ref_number/models/__init__.py @@ -0,0 +1,7 @@ +# -*- coding: utf-8 -*- +# © 2016 Acsone SA/NV (http://www.acsone.eu) +# © 2016 Eficent Business and IT Consulting Services S.L. +# (http://www.eficent.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from . import pos_order diff --git a/pos_sequence_ref_number/models/pos_order.py b/pos_sequence_ref_number/models/pos_order.py new file mode 100644 index 00000000..bf199cfc --- /dev/null +++ b/pos_sequence_ref_number/models/pos_order.py @@ -0,0 +1,34 @@ +# -*- coding: utf-8 -*- +# © 2016 Acsone SA/NV (http://www.acsone.eu) +# © 2016 Eficent Business and IT Consulting Services S.L. +# (http://www.eficent.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from openerp import api, models + + +class PosOrder(models.Model): + _inherit = "pos.order" + + @api.model + def sequence_number_sync(self, vals): + next = vals.get('_sequence_ref_number', False) + next = int(next) if next else False + if vals.get('session_id') and next is not False: + session = self.env['pos.session'].browse(vals['session_id']) + if next != session.config_id.sequence_id.number_next_actual: + session.config_id.sequence_id.number_next_actual = next + if vals.get('_sequence_ref_number') is not None: + del vals['_sequence_ref_number'] + + @api.model + def _order_fields(self, ui_order): + vals = super(PosOrder, self)._order_fields(ui_order) + vals['_sequence_ref_number'] = ui_order.get('sequence_ref_number') + return vals + + @api.model + def create(self, vals): + self.sequence_number_sync(vals) + order = super(PosOrder, self).create(vals) + return order diff --git a/pos_sequence_ref_number/static/src/js/main.js b/pos_sequence_ref_number/static/src/js/main.js new file mode 100644 index 00000000..208cfaba --- /dev/null +++ b/pos_sequence_ref_number/static/src/js/main.js @@ -0,0 +1,82 @@ +/** + * # -*- coding: utf-8 -*- + * # See README.rst file on addon root folder for license details + */ + ++function ($) { + 'use strict'; + + openerp.pos_sequence_ref_number = function (instance) { + var _t = instance.web._t, + _lt = instance.web._lt; + var QWeb = instance.web.qweb; + var module = instance.point_of_sale; + var _sequence_next = function(seq){ + var idict = { + 'year': moment().format('YYYY'), + 'month': moment().format('MM'), + 'day': moment().format('DD'), + 'y': moment().format('YY') + }; + var format = function(s, dict){ + s = s || ''; + $.each(dict, function(k, v){ + s = s.replace('%(' + k + ')s', v); + }); + return s; + }; + function pad(n, width, z) { + z = z || '0'; + n = n + ''; + if (n.length < width) { + n = new Array(width - n.length + 1).join(z) + n; + } + return n; + } + var num = seq.number_next_actual; + var prefix = format(seq.prefix, idict); + var suffix = format(seq.suffix, idict); + seq.number_next_actual += seq.number_increment; + + return prefix + pad(num, seq.padding) + suffix; + }; + + var PosModelParent = module.PosModel; + module.PosModel = module.PosModel.extend({ + load_server_data: function(){ + var self = this; + // Load POS sequence object + self.models.push({ + model: 'ir.sequence', + fields: [], + ids: function(self){ return [self.config.sequence_id[0]]; }, + loaded: function(self, sequence){ self.pos_order_sequence = sequence[0]; }, + }); + return PosModelParent.prototype.load_server_data.apply(this, arguments); + }, + push_order: function(order) { + if (order !== undefined) { + order.set({'sequence_ref_number': this.pos_order_sequence.number_next_actual}); + order.set({'sequence_ref': _sequence_next(this.pos_order_sequence)}); + } + return PosModelParent.prototype.push_order.call(this, order); + } + }); + + var OrderParent = module.Order; + module.Order = module.Order.extend({ + export_for_printing: function(attributes){ + var order = OrderParent.prototype.export_for_printing.apply(this, arguments); + order['sequence_ref_number'] = this.get('sequence_ref_number'); + return order; + }, + export_as_JSON: function() { + var order = OrderParent.prototype.export_as_JSON.apply(this, arguments); + order['sequence_ref'] = this.get('sequence_ref'); + order['sequence_ref_number'] = this.get('sequence_ref_number'); + return order; + }, + }); + }; + +}(jQuery); \ No newline at end of file diff --git a/pos_sequence_ref_number/static/src/xml/pos.xml b/pos_sequence_ref_number/static/src/xml/pos.xml new file mode 100644 index 00000000..327a2989 --- /dev/null +++ b/pos_sequence_ref_number/static/src/xml/pos.xml @@ -0,0 +1,19 @@ + + + + +
+ +
+
+
+ + + +
+ +
+
+
+ +
\ No newline at end of file diff --git a/pos_sequence_ref_number/views/pos_template.xml b/pos_sequence_ref_number/views/pos_template.xml new file mode 100644 index 00000000..334161da --- /dev/null +++ b/pos_sequence_ref_number/views/pos_template.xml @@ -0,0 +1,16 @@ + + + +