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. 105
      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>
* Pierrick Brun <pierrick.brun@akretion.com>
* Iván Todorovich <ivan.todorovich@druidoo.io>
* Ammar Officewala <https://twitter.com/AmmarOfficewala>
Maintainers
~~~~~~~~~~~

2
pos_order_mgmt/__manifest__.py

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

18
pos_order_mgmt/models/pos_order.py

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

1
pos_order_mgmt/readme/CONTRIBUTORS.rst

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

105
pos_order_mgmt/static/src/js/widgets.js

@ -3,7 +3,7 @@
Copyright 2019 Druidoo - Ivan Todorovich
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";
var core = require('web.core');
@ -19,12 +19,12 @@ odoo.define('pos_order_mgmt.widgets', function (require) {
var DomCache = screens.DomCache;
screens.ReceiptScreenWidget.include({
render_receipt: function () {
render_receipt: function() {
if (!this.pos.reloaded_order) {
return this._super();
}
var order = this.pos.reloaded_order;
this.$('.pos-receipt-container').html(QWeb.render('PosTicket', {
this.$('.pos-receipt-container').html(QWeb.render('OrderReceipt', {
widget: this,
pos: this.pos,
order: order,
@ -34,7 +34,7 @@ odoo.define('pos_order_mgmt.widgets', function (require) {
}));
this.pos.from_loaded_order = true;
},
click_next: function () {
click_next: function() {
if (!this.pos.from_loaded_order) {
return this._super();
}
@ -53,7 +53,7 @@ odoo.define('pos_order_mgmt.widgets', function (require) {
var OrderListScreenWidget = ScreenWidget.extend({
template: 'OrderListScreenWidget',
init: function (parent, options) {
init: function(parent, options) {
this._super(parent, options);
this.order_cache = new DomCache();
this.orders = [];
@ -64,7 +64,7 @@ odoo.define('pos_order_mgmt.widgets', function (require) {
auto_back: true,
show: function () {
show: function() {
var self = this;
var previous_screen = false;
if (this.pos.get_order()) {
@ -78,7 +78,7 @@ odoo.define('pos_order_mgmt.widgets', function (require) {
this._super();
this.renderElement();
this.old_order = this.pos.get_order();
this.$('.back').click(function () {
this.$('.back').click(function() {
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;
this.$('.searchbox input').on('keyup', function () {
this.$('.searchbox input').on('keyup', function() {
self.search_query = this.value;
clearTimeout(search_timeout);
search_timeout = setTimeout(function () {
search_timeout = setTimeout(function() {
self.perform_search();
}, 70);
});
this.$('.searchbox .search-clear').click(function () {
this.$('.searchbox .search-clear').click(function() {
self.clear_search();
});
this.perform_search();
},
render_list: function () {
render_list: function() {
var self = this;
var orders = this.orders;
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-reprint').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');
});
this.$('.order-list-copy').click(function (event) {
this.$('.order-list-copy').click(function(event) {
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');
});
},
order_list_actions: function (event, action) {
order_list_actions: function(event, action) {
var self = this;
var dataset = event.target.parentNode.dataset;
self.load_order_data(parseInt(dataset.orderId, 10))
.then(function (order_data) {
.then(function(order_data) {
self.order_action(order_data, action);
});
},
order_action: function (order_data, action) {
order_action: function(order_data, action) {
if (this.old_order !== null) {
this.gui.back();
}
@ -171,7 +171,7 @@ odoo.define('pos_order_mgmt.widgets', function (require) {
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
// taxes based on fiscal position
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) {
this.pos.proxy.print_receipt(QWeb.render(
'XmlReceipt', {
receipt: order.export_for_printing(),
'OrderReceipt', {
widget: this,
pos: this.pos,
order: order,
receipt: order.export_for_printing(),
orderlines: order.get_orderlines(),
paymentlines: order.get_paymentlines(),
paymentlinesf: order.get_paymentlines(),
}));
this.pos.set_order(this.pos.current_order);
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 (order_data.to_invoice) {
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();
},
action_copy: function (order_data, order) {
action_copy: function(order_data, order) {
order.trigger('change');
this.pos.get('orders').add(order);
this.pos.set('selectedOrder', order);
return order;
},
action_return: function (order_data, order) {
action_return: function(order_data, order) {
order.trigger('change');
this.pos.get('orders').add(order);
this.pos.set('selectedOrder', 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 order = new pos.Order({}, {
pos: this.pos,
@ -237,7 +239,7 @@ odoo.define('pos_order_mgmt.widgets', function (require) {
// Get fiscal position
if (order_data.fiscal_position && 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;
})[0];
order.trigger('change');
@ -279,18 +281,18 @@ odoo.define('pos_order_mgmt.widgets', function (require) {
// Get Payment lines
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;
// In case of local data
if (line.length === 3) {
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 it is not change
order.add_paymentline(cashregister);
order.add_paymentline(payment_method);
order.selected_paymentline.set_amount(
line.amount);
}
@ -301,12 +303,12 @@ odoo.define('pos_order_mgmt.widgets', function (require) {
return order;
},
_prepare_orderlines_from_order_data: function (
_prepare_orderlines_from_order_data: function(
order, order_data, action) {
var orderLines = order_data.line_ids || order_data.lines || [];
var self = this;
_.each(orderLines, function (orderLine) {
_.each(orderLines, function(orderLine) {
var line = orderLine;
// In case of local data
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;
return this._rpc({
model: 'pos.order',
method: 'load_done_order_for_pos',
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
self.gui.show_popup(
'error-traceback', {
'title': error.data.message,
'body': error.data.debug,
});
}
);
} else {
self.gui.show_popup('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;
this.unknown_products = [];
var order = self._prepare_order_from_order_data(
@ -378,23 +381,23 @@ odoo.define('pos_order_mgmt.widgets', function (require) {
},
// Search Part
search_done_orders: function (query) {
search_done_orders: function(query) {
var self = this;
return this._rpc({
model: 'pos.order',
method: 'search_done_orders_for_pos',
args: [query || '', this.pos.pos_session.id],
}).then(function (result) {
}).then(function(result) {
self.orders = result;
// Get the date in local time
_.each(self.orders, function (order) {
_.each(self.orders, function(order) {
if (order.date_order) {
order.date_order = moment.utc(order.date_order)
.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
self.gui.show_popup(
'error-traceback', {
@ -410,19 +413,19 @@ odoo.define('pos_order_mgmt.widgets', function (require) {
' is currently offline'),
});
}
event.preventDefault();
reason.event.preventDefault();
});
},
perform_search: function () {
perform_search: function() {
var self = this;
return this.search_done_orders(self.search_query)
.done(function () {
.then(function() {
self.render_list();
});
},
clear_search: function () {
clear_search: function() {
var self = this;
self.$('.searchbox input')[0].value = '';
self.$('.searchbox input').focus();
@ -438,21 +441,21 @@ odoo.define('pos_order_mgmt.widgets', function (require) {
var ListOrderButtonWidget = PosBaseWidget.extend({
template: 'ListOrderButtonWidget',
init: function (parent, options) {
init: function(parent, options) {
var opts = options || {};
this._super(parent, opts);
this.action = opts.action;
this.label = opts.label;
},
button_click: function () {
button_click: function() {
this.gui.show_screen('orderlist');
},
renderElement: function () {
renderElement: function() {
var self = this;
this._super();
this.$el.click(function () {
this.$el.click(function() {
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(
[], self.pos_config.current_session_id.id)
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()
self.assertEqual(
@ -58,13 +58,11 @@ class TestModule(TransactionCase):
'price_subtotal_incl': 0.9,
}]],
'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,
'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',
'amount_tax': 0,
@ -76,5 +74,5 @@ class TestModule(TransactionCase):
}}
result = self.PosOrder.create_from_ui([order_data])
order = self.PosOrder.browse(result[0])
order = self.PosOrder.browse(result[0].get('id'))
return order
Loading…
Cancel
Save