gilles
8 years ago
committed by
Denis Roussel
20 changed files with 290 additions and 136 deletions
-
11pos_sequence_ref_number/README.rst
-
5pos_sequence_ref_number/__init__.py
-
13pos_sequence_ref_number/__manifest__.py
-
2pos_sequence_ref_number/i18n/ca.po
-
2pos_sequence_ref_number/i18n/de.po
-
2pos_sequence_ref_number/i18n/es.po
-
2pos_sequence_ref_number/i18n/fr.po
-
2pos_sequence_ref_number/i18n/gl.po
-
2pos_sequence_ref_number/i18n/it.po
-
2pos_sequence_ref_number/i18n/nl_NL.po
-
2pos_sequence_ref_number/i18n/sl.po
-
2pos_sequence_ref_number/i18n/zh_CN.po
-
5pos_sequence_ref_number/models/__init__.py
-
26pos_sequence_ref_number/models/pos_order.py
-
7pos_sequence_ref_number/static/lib/moment.js
-
138pos_sequence_ref_number/static/src/js/main.js
-
9pos_sequence_ref_number/static/src/xml/pos.xml
-
2pos_sequence_ref_number/tests/__init__.py
-
161pos_sequence_ref_number/tests/test_pos_order.py
-
31pos_sequence_ref_number/views/pos_template.xml
@ -1,7 +1,4 @@ |
|||
# -*- 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). |
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
|||
|
|||
from . import models |
@ -1,7 +1,4 @@ |
|||
# -*- 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). |
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
|||
|
|||
from . import pos_order |
@ -1,82 +1,76 @@ |
|||
/** |
|||
* # -*- coding: utf-8 -*- |
|||
* # See README.rst file on addon root folder for license details |
|||
*/ |
|||
odoo.define('pos_sequence_ref_number.pos_sequence_ref_number_assets_backend', function(require) { |
|||
"use strict"; |
|||
|
|||
+function ($) { |
|||
'use strict'; |
|||
var models = require('point_of_sale.models'); |
|||
|
|||
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 PosModelSuper = models.PosModel; |
|||
var posmodel_super = models.PosModel.prototype; |
|||
var _super_order = models.Order.prototype; |
|||
|
|||
|
|||
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; |
|||
} |
|||
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 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; |
|||
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) { |
|||
models.PosModel = models.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 posmodel_super.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)}); |
|||
order.set({'sequence_ref': sequence_next(this.pos_order_sequence)}); |
|||
} |
|||
return PosModelParent.prototype.push_order.call(this, order); |
|||
} |
|||
}); |
|||
return PosModelSuper.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; |
|||
}, |
|||
}); |
|||
}; |
|||
models.Order = models.Order.extend({ |
|||
export_as_JSON: function() { |
|||
var json = _super_order.export_as_JSON.apply(this,arguments); |
|||
json['sequence_ref'] = this.get('sequence_number'); |
|||
json['sequence_ref_number'] = this.get('sequence_ref_number'); |
|||
return json; |
|||
}, |
|||
export_for_printing: function() { |
|||
var json = _super_order.export_for_printing.apply(this,arguments); |
|||
json['sequence_ref_number'] = this.get('sequence_number'); |
|||
return json; |
|||
}, |
|||
}); |
|||
|
|||
}(jQuery); |
|||
}); |
@ -1,19 +1,22 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<!-- Copyright 2017 Jordi Ballester, Rafael Blasco, Ivan Yelizariev, Antonio Espinosa, Meyomesse Gilles |
|||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). --> |
|||
<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')"/> |
|||
<!-- sequence_number --> |
|||
<br/> |
|||
</t> |
|||
</t> |
|||
|
|||
<t t-extend="XmlReceipt"> |
|||
<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> |
|||
</t> |
|||
|
|||
</templates> |
|||
</templates> |
@ -0,0 +1,2 @@ |
|||
# -*- coding: utf-8 -*- |
|||
from . import test_pos_order |
@ -0,0 +1,161 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# Copyright 2017 ACSONE SA/NV |
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
|||
|
|||
from odoo import fields |
|||
|
|||
from odoo.tests.common import SavepointCase |
|||
|
|||
|
|||
class TestSequenceNumberSync(SavepointCase): |
|||
|
|||
@classmethod |
|||
def setUpClass(cls): |
|||
""" |
|||
Simulation of sales coming from the interface |
|||
""" |
|||
super(TestSequenceNumberSync, cls).setUpClass() |
|||
|
|||
# ENVIRONEMENTS |
|||
cls.pos_obj = cls.env['pos.order'] |
|||
cls.partner_obj = cls.env['res.partner'] |
|||
|
|||
# INSTANCES |
|||
cls.partner = cls.partner_obj.create({'name': 'test_partner_A'}) |
|||
cls.product = cls.env.ref( |
|||
'product.product_order_01') |
|||
cls.pos_config = cls.env.ref('point_of_sale.pos_config_main') |
|||
|
|||
# USING VARIABLE |
|||
cls.sequence_ref_number = 10 |
|||
cls.sequence_number = 2 |
|||
|
|||
# USER PARTNER |
|||
cls.user_partner = cls.env.user.partner_id |
|||
|
|||
def get_data(self, session, sequence_number): |
|||
return '000' + str(session.id) + '-001-000' + str(sequence_number) |
|||
|
|||
def ui_order_data(self, sequence_ref_number, sequence_number, |
|||
current_session): |
|||
values = { |
|||
'data': { |
|||
'creation_date': fields.Datetime.now(), |
|||
'fiscal_position_id': False, |
|||
'amount_return': 0, |
|||
'sequence_ref_number': sequence_ref_number, |
|||
'lines': [[0, 0, {'product_id': self.product.id, |
|||
'qty': 1}]], |
|||
'name': 'Order ' + self.get_data( |
|||
current_session, sequence_number), |
|||
'partner_id': False, |
|||
'pos_session_id': current_session.id, |
|||
'sequence_number': sequence_number, |
|||
'statement_ids': [[0, 0, { |
|||
'account_id': |
|||
self.user_partner.property_account_receivable_id.id, |
|||
'amount': 0.9, |
|||
'journal_id': self.pos_config.journal_ids[0].id, |
|||
'name': fields.Datetime.now(), |
|||
'statement_id':current_session.statement_ids[0].id}]], |
|||
'user_id': self.env.uid |
|||
}, |
|||
'to_invoice': False |
|||
} |
|||
|
|||
# because travis install (pos_loyalty) |
|||
# may be an edge effect |
|||
if 'loyalty_points' in self.pos_obj._fields: |
|||
values['data']['loyalty_points'] = 0 |
|||
|
|||
return values |
|||
|
|||
def test_check_sequence_number_sync_00(self): |
|||
""" |
|||
case 1 : |
|||
1 - create order from ui |
|||
2 - close session |
|||
3 - create new order from ui, |
|||
4 - close session |
|||
5 - validate closing & post entries |
|||
sequence result : 000session_id-001-000sequence_number |
|||
and 000new_session_id+1-001-000sequence_number |
|||
order name result : Main/00sequence_ref_number |
|||
""" |
|||
|
|||
# click on create a new session button |
|||
self.pos_config.open_session_cb() |
|||
|
|||
# session |
|||
current_session = self.pos_config.current_session_id |
|||
|
|||
# data |
|||
ui_order = self.ui_order_data(self.sequence_ref_number, |
|||
self.sequence_number, current_session) |
|||
|
|||
# I create an order on an open session |
|||
pos_order_id = self.pos_obj.create_from_ui([ui_order]) |
|||
pos_order = self.env['pos.order'].browse(pos_order_id) |
|||
self.assertEqual(pos_order.name, |
|||
'Main/00' + str(self.sequence_ref_number)) |
|||
self.assertEqual(pos_order.pos_reference, |
|||
'Order 000' + str(current_session.id)+'-001-0002') |
|||
|
|||
# close the session |
|||
self.pos_config.current_session_id.action_pos_session_closing_control() |
|||
|
|||
# create an open new session |
|||
self.pos_config.open_session_cb() |
|||
new_current_session = self.pos_config.current_session_id |
|||
ui_order['data']['pos_session_id'] = new_current_session.id |
|||
ui_order['data']['name'] = self.get_data( |
|||
new_current_session, self.sequence_number) |
|||
|
|||
# create an order on an open session |
|||
pos_order_id = self.pos_obj.create_from_ui([ui_order]) |
|||
pos_order = self.env['pos.order'].browse(pos_order_id) |
|||
self.assertEqual(pos_order.name, |
|||
'Main/00' + str(self.sequence_ref_number)) |
|||
self.assertEqual(pos_order.pos_reference, |
|||
'000' + str(new_current_session.id)+'-001-0002') |
|||
|
|||
def test_check_sequence_number_sync_01(self): |
|||
""" |
|||
case 2 : |
|||
1 - create order from ui, |
|||
2 - create new order from ui |
|||
3 - validate closing & post entries |
|||
sequence result : 000session_id-001-000sequence_number |
|||
and 000session_id-001-000new_sequence_number |
|||
order name result : Main/00sequence_ref_number |
|||
""" |
|||
|
|||
# create a new session button |
|||
self.pos_config.open_session_cb() |
|||
|
|||
# session |
|||
current_session = self.pos_config.current_session_id |
|||
|
|||
# data |
|||
ui_order = self.ui_order_data(self.sequence_ref_number, |
|||
self.sequence_number, current_session) |
|||
|
|||
# create an order on an open session |
|||
pos_order_id = self.pos_obj.create_from_ui([ui_order]) |
|||
pos_order = self.env['pos.order'].browse(pos_order_id) |
|||
self.assertEqual(pos_order.name, |
|||
'Main/00' + str(self.sequence_ref_number)) |
|||
self.assertEqual(pos_order.pos_reference, |
|||
'Order 000' + str(current_session.id) + '-001-0002') |
|||
|
|||
self.sequence_number = self.sequence_number+1 |
|||
ui_order = self.ui_order_data(self.sequence_ref_number, |
|||
self.sequence_number, current_session) |
|||
pos_order_id = self.pos_obj.create_from_ui([ui_order]) |
|||
pos_order = self.env['pos.order'].browse(pos_order_id) |
|||
self.assertEqual(pos_order.name, |
|||
'Main/00' + str(self.sequence_ref_number)) |
|||
self.assertEqual(pos_order.pos_reference, |
|||
'Order 000' + str(current_session.id) + '-001-0003') |
|||
# close the session |
|||
self.pos_config.current_session_id.action_pos_session_closing_control() |
@ -1,16 +1,17 @@ |
|||
<?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> |
|||
<!-- Copyright 2017 Jordi Ballester, Rafael Blasco, Ivan Yelizariev, Antonio Espinosa, Meyomesse Gilles |
|||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). --> |
|||
<odoo> |
|||
<data> |
|||
<template id="pos_sequence_ref_number_assets_backend" |
|||
name="pos_sequence_ref_number_assets_backend" |
|||
inherit_id="point_of_sale.assets"> |
|||
<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> |
|||
</odoo> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue