Browse Source

pull/178/head
jbeficent 9 years ago
committed by Denis Roussel
parent
commit
39be72b75d
  1. 66
      pos_sequence_ref_number/README.rst
  2. 8
      pos_sequence_ref_number/__init__.py
  3. 27
      pos_sequence_ref_number/__openerp__.py
  4. 7
      pos_sequence_ref_number/models/__init__.py
  5. 34
      pos_sequence_ref_number/models/pos_order.py
  6. 82
      pos_sequence_ref_number/static/src/js/main.js
  7. 19
      pos_sequence_ref_number/static/src/xml/pos.xml
  8. 16
      pos_sequence_ref_number/views/pos_template.xml

66
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 <https://github.com/OCA/pos/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 <https://github.com/OCA/pos/issues/new?body=module
:%20pos_sequence_ref_number
%0Aversion:%208.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Credits
=======
Contributors
------------
* Jordi Ballester <jordi.ballester@eficent.com>
* Rafael Blasco <rblasco@rbnpro.com>
* Ivan Yelizariev
* Antonio Espinosa <antonioea@antiun.com>
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.

8
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

27
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,
}

7
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

34
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

82
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);

19
pos_sequence_ref_number/static/src/xml/pos.xml

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates id="template" xml:space="preserve">
<t t-extend="PosTicket">
<t t-jquery=".pos-center-align t:first" t-operation="after">
<br/>
<t t-esc="order.get('sequence_ref')"/>
<br/>
</t>
</t>
<t t-extend="XmlReceipt">
<t t-jquery="[t-if='!receipt.company.logo']" t-operation="after">
<br/>
<t t-esc="receipt.sequence_ref"/>
<br/>
</t>
</t>
</templates>

16
pos_sequence_ref_number/views/pos_template.xml

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<template id="pos_sequence_ref_number_assets_backend"
name="pos_sequence_ref_number_assets_backend"
inherit_id="point_of_sale.assets_backend">
<xpath expr="." position="inside">
<script src="/pos_sequence_ref_number/static/src/js/main.js"
type="text/javascript"/>
<script type="text/javascript"
src="/pos_sequence_ref_number/static/lib/moment.js"/>
</xpath>
</template>
</data>
</openerp>
Loading…
Cancel
Save