Browse Source

[MIG] pos_order_mgmt: Migration to 13.0

pull/397/head
AmmarOfficewala 5 years ago
parent
commit
c40de4fa58
  1. 1
      pos_order_mgmt/README.rst
  2. 2
      pos_order_mgmt/__manifest__.py
  3. 18
      pos_order_mgmt/models/pos_order.py
  4. 1
      pos_order_mgmt/readme/CONTRIBUTORS.rst
  5. 115
      pos_order_mgmt/static/src/js/widgets.js
  6. 14
      pos_order_mgmt/tests/test_module.py

1
pos_order_mgmt/README.rst

@ -115,6 +115,7 @@ Contributors
* Carlos Martínez <carlos@domatix.com> * Carlos Martínez <carlos@domatix.com>
* Pierrick Brun <pierrick.brun@akretion.com> * Pierrick Brun <pierrick.brun@akretion.com>
* Iván Todorovich <ivan.todorovich@druidoo.io> * Iván Todorovich <ivan.todorovich@druidoo.io>
* Ammar Officewala <https://twitter.com/AmmarOfficewala>
Maintainers Maintainers
~~~~~~~~~~~ ~~~~~~~~~~~

2
pos_order_mgmt/__manifest__.py

@ -5,7 +5,7 @@
{ {
'name': 'POS Frontend Orders Management', 'name': 'POS Frontend Orders Management',
'summary': 'Manage old POS Orders from the frontend', 'summary': 'Manage old POS Orders from the frontend',
'version': '12.0.1.0.3',
'version': '13.0.1.0.0',
'category': 'Point of Sale', 'category': 'Point of Sale',
'author': 'GRAP, ' 'author': 'GRAP, '
'Tecnativa, ' 'Tecnativa, '

18
pos_order_mgmt/models/pos_order.py

@ -30,13 +30,11 @@ class PosOrder(models.Model):
string='Refund Orders Quantity', string='Refund Orders Quantity',
) )
@api.multi
@api.depends('refund_order_ids') @api.depends('refund_order_ids')
def _compute_refund_order_qty(self): def _compute_refund_order_qty(self):
for order in self: for order in self:
order.refund_order_qty = len(order.refund_order_ids) order.refund_order_qty = len(order.refund_order_ids)
@api.multi
def action_view_refund_orders(self): def action_view_refund_orders(self):
self.ensure_one() self.ensure_one()
@ -50,12 +48,9 @@ class PosOrder(models.Model):
action['domain'] = [('id', 'in', self.refund_order_ids.ids)] action['domain'] = [('id', 'in', self.refund_order_ids.ids)]
return action return action
@api.multi
def refund(self): def refund(self):
return super(PosOrder, self.with_context(refund=True)).refund() return super(PosOrder, self.with_context(refund=True)).refund()
@api.multi
@api.returns('self', lambda value: value.id)
def copy(self, default=None): def copy(self, default=None):
self.ensure_one() self.ensure_one()
order = super().copy(default=default) order = super().copy(default=default)
@ -101,7 +96,6 @@ class PosOrder(models.Model):
return self.search_read( return self.search_read(
condition, field_names, limit=config.iface_load_done_order_max_qty) condition, field_names, limit=config.iface_load_done_order_max_qty)
@api.multi
def _prepare_done_order_for_pos(self): def _prepare_done_order_for_pos(self):
self.ensure_one() self.ensure_one()
order_lines = [] order_lines = []
@ -109,7 +103,7 @@ class PosOrder(models.Model):
for order_line in self.lines: for order_line in self.lines:
order_line = self._prepare_done_order_line_for_pos(order_line) order_line = self._prepare_done_order_line_for_pos(order_line)
order_lines.append(order_line) order_lines.append(order_line)
for payment_line in self.statement_ids:
for payment_line in self.payment_ids:
payment_line = self._prepare_done_order_payment_for_pos( payment_line = self._prepare_done_order_payment_for_pos(
payment_line) payment_line)
payment_lines.append(payment_line) payment_lines.append(payment_line)
@ -121,14 +115,13 @@ class PosOrder(models.Model):
'partner_id': self.partner_id.id, 'partner_id': self.partner_id.id,
'fiscal_position': self.fiscal_position_id.id, 'fiscal_position': self.fiscal_position_id.id,
'line_ids': order_lines, 'line_ids': order_lines,
'statement_ids': payment_lines,
'to_invoice': bool(self.invoice_id),
'payment_lines': payment_lines,
'to_invoice': bool(self.account_move),
'returned_order_id': self.returned_order_id.id, 'returned_order_id': self.returned_order_id.id,
'returned_order_reference': self.returned_order_reference, 'returned_order_reference': self.returned_order_reference,
} }
return res return res
@api.multi
def _prepare_done_order_line_for_pos(self, order_line): def _prepare_done_order_line_for_pos(self, order_line):
self.ensure_one() self.ensure_one()
return { return {
@ -138,20 +131,17 @@ class PosOrder(models.Model):
'discount': order_line.discount, 'discount': order_line.discount,
} }
@api.multi
def _prepare_done_order_payment_for_pos(self, payment_line): def _prepare_done_order_payment_for_pos(self, payment_line):
self.ensure_one() self.ensure_one()
return { return {
'journal_id': payment_line.journal_id.id,
'payment_method_id': payment_line.payment_method_id.id,
'amount': payment_line.amount, 'amount': payment_line.amount,
} }
@api.multi
def load_done_order_for_pos(self): def load_done_order_for_pos(self):
self.ensure_one() self.ensure_one()
return self._prepare_done_order_for_pos() return self._prepare_done_order_for_pos()
@api.model
def _order_fields(self, ui_order): def _order_fields(self, ui_order):
res = super()._order_fields(ui_order) res = super()._order_fields(ui_order)
res.update({ res.update({

1
pos_order_mgmt/readme/CONTRIBUTORS.rst

@ -3,3 +3,4 @@
* Carlos Martínez <carlos@domatix.com> * Carlos Martínez <carlos@domatix.com>
* Pierrick Brun <pierrick.brun@akretion.com> * Pierrick Brun <pierrick.brun@akretion.com>
* Iván Todorovich <ivan.todorovich@druidoo.io> * Iván Todorovich <ivan.todorovich@druidoo.io>
* Ammar Officewala <https://twitter.com/AmmarOfficewala>

115
pos_order_mgmt/static/src/js/widgets.js

@ -3,7 +3,7 @@
Copyright 2019 Druidoo - Ivan Todorovich Copyright 2019 Druidoo - Ivan Todorovich
License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl). */ License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl). */
odoo.define('pos_order_mgmt.widgets', function (require) {
odoo.define('pos_order_mgmt.widgets', function(require) {
"use strict"; "use strict";
var core = require('web.core'); var core = require('web.core');
@ -19,12 +19,12 @@ odoo.define('pos_order_mgmt.widgets', function (require) {
var DomCache = screens.DomCache; var DomCache = screens.DomCache;
screens.ReceiptScreenWidget.include({ screens.ReceiptScreenWidget.include({
render_receipt: function () {
render_receipt: function() {
if (!this.pos.reloaded_order) { if (!this.pos.reloaded_order) {
return this._super(); return this._super();
} }
var order = this.pos.reloaded_order; var order = this.pos.reloaded_order;
this.$('.pos-receipt-container').html(QWeb.render('PosTicket', {
this.$('.pos-receipt-container').html(QWeb.render('OrderReceipt', {
widget: this, widget: this,
pos: this.pos, pos: this.pos,
order: order, order: order,
@ -34,7 +34,7 @@ odoo.define('pos_order_mgmt.widgets', function (require) {
})); }));
this.pos.from_loaded_order = true; this.pos.from_loaded_order = true;
}, },
click_next: function () {
click_next: function() {
if (!this.pos.from_loaded_order) { if (!this.pos.from_loaded_order) {
return this._super(); return this._super();
} }
@ -53,7 +53,7 @@ odoo.define('pos_order_mgmt.widgets', function (require) {
var OrderListScreenWidget = ScreenWidget.extend({ var OrderListScreenWidget = ScreenWidget.extend({
template: 'OrderListScreenWidget', template: 'OrderListScreenWidget',
init: function (parent, options) {
init: function(parent, options) {
this._super(parent, options); this._super(parent, options);
this.order_cache = new DomCache(); this.order_cache = new DomCache();
this.orders = []; this.orders = [];
@ -64,7 +64,7 @@ odoo.define('pos_order_mgmt.widgets', function (require) {
auto_back: true, auto_back: true,
show: function () {
show: function() {
var self = this; var self = this;
var previous_screen = false; var previous_screen = false;
if (this.pos.get_order()) { if (this.pos.get_order()) {
@ -78,7 +78,7 @@ odoo.define('pos_order_mgmt.widgets', function (require) {
this._super(); this._super();
this.renderElement(); this.renderElement();
this.old_order = this.pos.get_order(); this.old_order = this.pos.get_order();
this.$('.back').click(function () {
this.$('.back').click(function() {
return self.gui.show_screen(self.gui.startup_screen); return self.gui.show_screen(self.gui.startup_screen);
}); });
@ -89,22 +89,22 @@ odoo.define('pos_order_mgmt.widgets', function (require) {
} }
var search_timeout = null; var search_timeout = null;
this.$('.searchbox input').on('keyup', function () {
this.$('.searchbox input').on('keyup', function() {
self.search_query = this.value; self.search_query = this.value;
clearTimeout(search_timeout); clearTimeout(search_timeout);
search_timeout = setTimeout(function () {
search_timeout = setTimeout(function() {
self.perform_search(); self.perform_search();
}, 70); }, 70);
}); });
this.$('.searchbox .search-clear').click(function () {
this.$('.searchbox .search-clear').click(function() {
self.clear_search(); self.clear_search();
}); });
this.perform_search(); this.perform_search();
}, },
render_list: function () {
render_list: function() {
var self = this; var self = this;
var orders = this.orders; var orders = this.orders;
var contents = this.$el[0].querySelector('.order-list-contents'); var contents = this.$el[0].querySelector('.order-list-contents');
@ -138,27 +138,27 @@ odoo.define('pos_order_mgmt.widgets', function (require) {
this.$('.order-list-return').off('click'); this.$('.order-list-return').off('click');
this.$('.order-list-reprint').off('click'); this.$('.order-list-reprint').off('click');
this.$('.order-list-copy').off('click'); this.$('.order-list-copy').off('click');
this.$('.order-list-reprint').click(function (event) {
this.$('.order-list-reprint').click(function(event) {
self.order_list_actions(event, 'print'); self.order_list_actions(event, 'print');
}); });
this.$('.order-list-copy').click(function (event) {
this.$('.order-list-copy').click(function(event) {
self.order_list_actions(event, 'copy'); self.order_list_actions(event, 'copy');
}); });
this.$('.order-list-return').click(function (event) {
this.$('.order-list-return').click(function(event) {
self.order_list_actions(event, 'return'); self.order_list_actions(event, 'return');
}); });
}, },
order_list_actions: function (event, action) {
order_list_actions: function(event, action) {
var self = this; var self = this;
var dataset = event.target.parentNode.dataset; var dataset = event.target.parentNode.dataset;
self.load_order_data(parseInt(dataset.orderId, 10)) self.load_order_data(parseInt(dataset.orderId, 10))
.then(function (order_data) {
.then(function(order_data) {
self.order_action(order_data, action); self.order_action(order_data, action);
}); });
}, },
order_action: function (order_data, action) {
order_action: function(order_data, action) {
if (this.old_order !== null) { if (this.old_order !== null) {
this.gui.back(); this.gui.back();
} }
@ -171,7 +171,7 @@ odoo.define('pos_order_mgmt.widgets', function (require) {
this['action_' + action](order_data, order); this['action_' + action](order_data, order);
}, },
action_print: function (order_data, order) {
action_print: function(order_data, order) {
// We store temporarily the current order so we can safely compute // We store temporarily the current order so we can safely compute
// taxes based on fiscal position // taxes based on fiscal position
this.pos.current_order = this.pos.get_order(); this.pos.current_order = this.pos.get_order();
@ -180,13 +180,13 @@ odoo.define('pos_order_mgmt.widgets', function (require) {
if (this.pos.config.iface_print_via_proxy) { if (this.pos.config.iface_print_via_proxy) {
this.pos.proxy.print_receipt(QWeb.render( this.pos.proxy.print_receipt(QWeb.render(
'XmlReceipt', {
receipt: order.export_for_printing(),
'OrderReceipt', {
widget: this, widget: this,
pos: this.pos, pos: this.pos,
order: order, order: order,
receipt: order.export_for_printing(),
orderlines: order.get_orderlines(), orderlines: order.get_orderlines(),
paymentlines: order.get_paymentlines(),
paymentlinesf: order.get_paymentlines(),
})); }));
this.pos.set_order(this.pos.current_order); this.pos.set_order(this.pos.current_order);
this.pos.current_order = false; this.pos.current_order = false;
@ -199,7 +199,9 @@ odoo.define('pos_order_mgmt.widgets', function (require) {
// If it's invoiced, we also print the invoice // If it's invoiced, we also print the invoice
if (order_data.to_invoice) { if (order_data.to_invoice) {
this.pos.chrome.do_action('point_of_sale.pos_invoice_report', { this.pos.chrome.do_action('point_of_sale.pos_invoice_report', {
additional_context: { active_ids: [order_data.id] }
additional_context: {
active_ids: [order_data.id]
}
}) })
} }
@ -208,21 +210,21 @@ odoo.define('pos_order_mgmt.widgets', function (require) {
order.destroy(); order.destroy();
}, },
action_copy: function (order_data, order) {
action_copy: function(order_data, order) {
order.trigger('change'); order.trigger('change');
this.pos.get('orders').add(order); this.pos.get('orders').add(order);
this.pos.set('selectedOrder', order); this.pos.set('selectedOrder', order);
return order; return order;
}, },
action_return: function (order_data, order) {
action_return: function(order_data, order) {
order.trigger('change'); order.trigger('change');
this.pos.get('orders').add(order); this.pos.get('orders').add(order);
this.pos.set('selectedOrder', order); this.pos.set('selectedOrder', order);
return order; return order;
}, },
_prepare_order_from_order_data: function (order_data, action) {
_prepare_order_from_order_data: function(order_data, action) {
var self = this; var self = this;
var order = new pos.Order({}, { var order = new pos.Order({}, {
pos: this.pos, pos: this.pos,
@ -237,7 +239,7 @@ odoo.define('pos_order_mgmt.widgets', function (require) {
// Get fiscal position // Get fiscal position
if (order_data.fiscal_position && this.pos.fiscal_positions) { if (order_data.fiscal_position && this.pos.fiscal_positions) {
var fiscal_positions = this.pos.fiscal_positions; var fiscal_positions = this.pos.fiscal_positions;
order.fiscal_position = fiscal_positions.filter(function (p) {
order.fiscal_position = fiscal_positions.filter(function(p) {
return p.id === order_data.fiscal_position; return p.id === order_data.fiscal_position;
})[0]; })[0];
order.trigger('change'); order.trigger('change');
@ -265,7 +267,7 @@ odoo.define('pos_order_mgmt.widgets', function (require) {
// Get the same value as the original // Get the same value as the original
order.returned_order_id = order_data.returned_order_id; order.returned_order_id = order_data.returned_order_id;
order.returned_order_reference = order.returned_order_reference =
order_data.returned_order_reference;
order_data.returned_order_reference;
} else if (['return'].indexOf(action) !== -1) { } else if (['return'].indexOf(action) !== -1) {
order.returned_order_id = order_data.id; order.returned_order_id = order_data.id;
order.returned_order_reference = order_data.pos_reference; order.returned_order_reference = order_data.pos_reference;
@ -274,23 +276,23 @@ odoo.define('pos_order_mgmt.widgets', function (require) {
// Get Date // Get Date
if (['print'].indexOf(action) !== -1) { if (['print'].indexOf(action) !== -1) {
order.formatted_validation_date = order.formatted_validation_date =
moment(order_data.date_order).format('YYYY-MM-DD HH:mm:ss');
moment(order_data.date_order).format('YYYY-MM-DD HH:mm:ss');
} }
// Get Payment lines // Get Payment lines
if (['print'].indexOf(action) !== -1) { if (['print'].indexOf(action) !== -1) {
var paymentLines = order_data.statement_ids || [];
_.each(paymentLines, function (paymentLine) {
var paymentLines = order_data.payment_lines || [];
_.each(paymentLines, function(paymentLine) {
var line = paymentLine; var line = paymentLine;
// In case of local data // In case of local data
if (line.length === 3) { if (line.length === 3) {
line = line[2]; line = line[2];
} }
_.each(self.pos.cashregisters, function (cashregister) {
if (cashregister.journal.id === line.journal_id) {
_.each(self.pos.payment_methods, function(payment_method) {
if (payment_method.id === line.payment_method_id) {
if (line.amount > 0) { if (line.amount > 0) {
// If it is not change // If it is not change
order.add_paymentline(cashregister);
order.add_paymentline(payment_method);
order.selected_paymentline.set_amount( order.selected_paymentline.set_amount(
line.amount); line.amount);
} }
@ -301,12 +303,12 @@ odoo.define('pos_order_mgmt.widgets', function (require) {
return order; return order;
}, },
_prepare_orderlines_from_order_data: function (
_prepare_orderlines_from_order_data: function(
order, order_data, action) { order, order_data, action) {
var orderLines = order_data.line_ids || order_data.lines || []; var orderLines = order_data.line_ids || order_data.lines || [];
var self = this; var self = this;
_.each(orderLines, function (orderLine) {
_.each(orderLines, function(orderLine) {
var line = orderLine; var line = orderLine;
// In case of local data // In case of local data
if (line.length === 3) { if (line.length === 3) {
@ -333,20 +335,21 @@ odoo.define('pos_order_mgmt.widgets', function (require) {
}); });
}, },
load_order_data: function (order_id) {
load_order_data: function(order_id) {
var self = this; var self = this;
return this._rpc({ return this._rpc({
model: 'pos.order', model: 'pos.order',
method: 'load_done_order_for_pos', method: 'load_done_order_for_pos',
args: [order_id], args: [order_id],
}).fail(function (error) {
if (parseInt(error.code, 10) === 200) {
}).guardedCatch(function(reason) {
if (parseInt(reason.message.code, 10) === 200) {
// Business Logic Error, not a connection problem // Business Logic Error, not a connection problem
self.gui.show_popup( self.gui.show_popup(
'error-traceback', { 'error-traceback', {
'title': error.data.message, 'title': error.data.message,
'body': error.data.debug, 'body': error.data.debug,
});
}
);
} else { } else {
self.gui.show_popup('error', { self.gui.show_popup('error', {
'title': _t('Connection error'), 'title': _t('Connection error'),
@ -358,7 +361,7 @@ odoo.define('pos_order_mgmt.widgets', function (require) {
}); });
}, },
load_order_from_data: function (order_data, action) {
load_order_from_data: function(order_data, action) {
var self = this; var self = this;
this.unknown_products = []; this.unknown_products = [];
var order = self._prepare_order_from_order_data( var order = self._prepare_order_from_order_data(
@ -368,9 +371,9 @@ odoo.define('pos_order_mgmt.widgets', function (require) {
self.gui.show_popup('error-traceback', { self.gui.show_popup('error-traceback', {
'title': _t('Unknown Products'), 'title': _t('Unknown Products'),
'body': _t('Unable to load some order lines because the ' + 'body': _t('Unable to load some order lines because the ' +
'products are not available in the POS cache.\n\n' +
'Please check that lines :\n\n * ') +
self.unknown_products.join("; \n *"),
'products are not available in the POS cache.\n\n' +
'Please check that lines :\n\n * ') +
self.unknown_products.join("; \n *"),
}); });
return false; return false;
} }
@ -378,23 +381,23 @@ odoo.define('pos_order_mgmt.widgets', function (require) {
}, },
// Search Part // Search Part
search_done_orders: function (query) {
search_done_orders: function(query) {
var self = this; var self = this;
return this._rpc({ return this._rpc({
model: 'pos.order', model: 'pos.order',
method: 'search_done_orders_for_pos', method: 'search_done_orders_for_pos',
args: [query || '', this.pos.pos_session.id], args: [query || '', this.pos.pos_session.id],
}).then(function (result) {
}).then(function(result) {
self.orders = result; self.orders = result;
// Get the date in local time // Get the date in local time
_.each(self.orders, function (order) {
_.each(self.orders, function(order) {
if (order.date_order) { if (order.date_order) {
order.date_order = moment.utc(order.date_order) order.date_order = moment.utc(order.date_order)
.local().format('YYYY-MM-DD HH:mm:ss'); .local().format('YYYY-MM-DD HH:mm:ss');
} }
}); });
}).fail(function (error, event) {
if (parseInt(error.code, 10) === 200) {
}).guardedCatch(function(reason) {
if (parseInt(reason.message.code, 10) === 200) {
// Business Logic Error, not a connection problem // Business Logic Error, not a connection problem
self.gui.show_popup( self.gui.show_popup(
'error-traceback', { 'error-traceback', {
@ -410,19 +413,19 @@ odoo.define('pos_order_mgmt.widgets', function (require) {
' is currently offline'), ' is currently offline'),
}); });
} }
event.preventDefault();
reason.event.preventDefault();
}); });
}, },
perform_search: function () {
perform_search: function() {
var self = this; var self = this;
return this.search_done_orders(self.search_query) return this.search_done_orders(self.search_query)
.done(function () {
.then(function() {
self.render_list(); self.render_list();
}); });
}, },
clear_search: function () {
clear_search: function() {
var self = this; var self = this;
self.$('.searchbox input')[0].value = ''; self.$('.searchbox input')[0].value = '';
self.$('.searchbox input').focus(); self.$('.searchbox input').focus();
@ -438,21 +441,21 @@ odoo.define('pos_order_mgmt.widgets', function (require) {
var ListOrderButtonWidget = PosBaseWidget.extend({ var ListOrderButtonWidget = PosBaseWidget.extend({
template: 'ListOrderButtonWidget', template: 'ListOrderButtonWidget',
init: function (parent, options) {
init: function(parent, options) {
var opts = options || {}; var opts = options || {};
this._super(parent, opts); this._super(parent, opts);
this.action = opts.action; this.action = opts.action;
this.label = opts.label; this.label = opts.label;
}, },
button_click: function () {
button_click: function() {
this.gui.show_screen('orderlist'); this.gui.show_screen('orderlist');
}, },
renderElement: function () {
renderElement: function() {
var self = this; var self = this;
this._super(); this._super();
this.$el.click(function () {
this.$el.click(function() {
self.button_click(); self.button_click();
}); });
}, },

14
pos_order_mgmt/tests/test_module.py

@ -30,8 +30,8 @@ class TestModule(TransactionCase):
orders_data = self.PosOrder.search_done_orders_for_pos( orders_data = self.PosOrder.search_done_orders_for_pos(
[], self.pos_config.current_session_id.id) [], self.pos_config.current_session_id.id)
self.assertEqual(len(orders_data), 1) self.assertEqual(len(orders_data), 1)
self.assertEqual(
orders_data[0]['id'], order.id)
self.assertEqual(order.id,
orders_data[0]['id'])
detail_data = order.load_done_order_for_pos() detail_data = order.load_done_order_for_pos()
self.assertEqual( self.assertEqual(
@ -58,13 +58,11 @@ class TestModule(TransactionCase):
'price_subtotal_incl': 0.9, 'price_subtotal_incl': 0.9,
}]], }]],
'statement_ids': [[0, 0, { 'statement_ids': [[0, 0, {
'journal_id': self.pos_config.journal_ids[0].id,
'payment_method_id': self.pos_config.payment_method_ids[0].id,
'amount': 0.9, 'amount': 0.9,
'name': fields.Datetime.now(), 'name': fields.Datetime.now(),
'account_id':
self.env.user.partner_id.property_account_receivable_id.id,
'statement_id':
self.pos_config.current_session_id.statement_ids[0].id,
'payment_date' : fields.Datetime.now(),
'session_id' : self.pos_config.current_session_id.id,
}]], }]],
'creation_date': u'2018-09-27 15:51:03', 'creation_date': u'2018-09-27 15:51:03',
'amount_tax': 0, 'amount_tax': 0,
@ -76,5 +74,5 @@ class TestModule(TransactionCase):
}} }}
result = self.PosOrder.create_from_ui([order_data]) result = self.PosOrder.create_from_ui([order_data])
order = self.PosOrder.browse(result[0])
order = self.PosOrder.browse(result[0].get('id'))
return order return order
Loading…
Cancel
Save