Browse Source

[MIG] pos_order_load: Migration to 10.0

pull/320/head
Invitu 7 years ago
parent
commit
9c6285aede
  1. 2
      pos_order_load/__manifest__.py
  2. 2
      pos_order_load/models/pos_order.py
  3. 319
      pos_order_load/static/src/js/pos_order_load.js
  4. 6
      pos_order_load/static/src/xml/pos_order_load.xml
  5. 28
      pos_order_load/view/pos_order_load.xml

2
pos_order_load/__openerp__.py → pos_order_load/__manifest__.py

@ -22,7 +22,7 @@
{
'name': 'POS Order Load and Save',
'version': '8.0.1.0.0',
'version': '10.0.1.0.0',
'author': 'Akretion,GRAP,Odoo Community Association (OCA)',
'category': 'Point Of Sale',
'license': 'AGPL-3',

2
pos_order_load/models/pos_order.py

@ -21,7 +21,7 @@
#
##############################################################################
from openerp import models, api
from odoo import models, api
class PosOrder(models.Model):

319
pos_order_load/static/src/js/pos_order_load.js

@ -15,17 +15,32 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/
openerp.pos_order_load = function(instance, local) {
module = instance.point_of_sale;
var QWeb = instance.web.qweb;
var _t = instance.web._t;
var round_pr = instance.web.round_precision;
odoo.define('pos_order_load', function (require) {
"use strict";
var PosBaseWidget = require('point_of_sale.BaseWidget');
var chrome = require('point_of_sale.chrome');
var gui = require('point_of_sale.gui');
var models = require('point_of_sale.models');
var screens = require('point_of_sale.screens');
var Model = require('web.DataModel');
var utils = require('web.utils');
var round_pr = utils.round_precision;
var core = require('web.core');
var QWeb = core.qweb;
var _t = core._t;
/*************************************************************************
Extend Model Order:
* Add getter and setter function for field 'order_id';
*/
module.Order = module.Order.extend({
* Add getter and setter function for field 'order_id';
*/
var _super_order = models.Order.prototype;
models.Order = models.Order.extend({
set_order_id: function(id) {
this.set({
@ -41,33 +56,32 @@ openerp.pos_order_load = function(instance, local) {
/*************************************************************************
New Widget LoadButtonWidget:
* On click, display a new screen to select draft orders;
*/
module.LoadButtonWidget = module.PosBaseWidget.extend({
* On click, display a new screen to select draft orders;
*/
var LoadButtonWidget = PosBaseWidget.extend({
template: 'LoadButtonWidget',
renderElement: function() {
var self = this;
this._super();
this.$el.click(function(){
var ss = self.pos.pos_widget.screen_selector;
ss.set_current_screen('orderlist');
self.gui.show_screen('orderlist');
});
},
});
/*************************************************************************
New Widget SaveButtonWidget:
* On click, save the current draft order;
*/
module.SaveButtonWidget = module.PosBaseWidget.extend({
* On click, save the current draft order;
*/
var SaveButtonWidget = PosBaseWidget.extend({
template: 'SaveButtonWidget',
renderElement: function() {
var self = this;
this._super();
this.$el.click(function(){
self.pos.pos_widget.screen_selector.show_popup('confirm',{
self.gui.show_popup('confirm',{
message: _t('Save The current Order ?'),
comment: _t('This operation will save the current order in a draft state. You\'ll have to mark it as paid after.'),
confirm: function(){
@ -83,57 +97,52 @@ openerp.pos_order_load = function(instance, local) {
/*************************************************************************
Extend PosWidget:
* Create new screen;
* Add load and save button;
*/
module.PosWidget = module.PosWidget.extend({
* Create new screen;
* Add load and save button;
*/
chrome.Chrome.include({
build_widgets: function() {
this._super();
// New Screen to select Draft Orders
this.orderlist_screen = new module.OrderListScreenWidget(this, {});
this.orderlist_screen.appendTo(this.$('.screens'));
this.orderlist_screen.hide();
this.load_button = new LoadButtonWidget(this, {});
this.load_button.appendTo(this.$('div.order-empty'));
this.screen_selector.screen_set.orderlist = this.orderlist_screen;
// Add buttons
this.load_button = new module.LoadButtonWidget(this,{});
this.load_button.appendTo(this.pos_widget.$('li.orderline.empty'));
this.save_button = new module.SaveButtonWidget(this,{});
this.save_button = new SaveButtonWidget(this, {});
},
});
/*************************************************************************
Extend OrderWidget:
*/
module.OrderWidget = module.OrderWidget.extend({
* Extend OrderWidget:
*/
screens.OrderWidget.include({
renderElement: function(scrollbottom){
this._super(scrollbottom);
if (this.pos_widget.load_button) {
this.pos_widget.load_button.appendTo(
this.pos_widget.$('li.orderline.empty')
if (this.chrome.load_button) {
this.chrome.load_button.appendTo(
this.chrome.$('div.order-empty')
);
}
if (this.pos_widget.save_button && (this.pos.get('selectedOrder').get('orderLines').length > 0)) {
this.pos_widget.save_button.appendTo(
this.pos_widget.$('div.summary')
);
if (this.pos.get_order()) {
if (this.chrome.save_button && (this.pos.get_order().get_orderlines().length > 0)) {
this.chrome.save_button.appendTo(
this.chrome.$('div.summary')
);
}
}
}
});
/*************************************************************************
New ScreenWidget OrderListScreenWidget:
* On show, display all draft orders;
* on click on an order, display the content;
* on click on 'validate', allow to use this POS Order;
* on click on 'cancel', display the preview screen;
*/
module.OrderListScreenWidget = module.ScreenWidget.extend({
* New ScreenWidget OrderListScreenWidget:
* On show, display all draft orders;
* on click on an order, display the content;
* on click on 'validate', allow to use this POS Order;
* on click on 'cancel', display the preview screen;
*/
//
var OrderListScreenWidget = screens.ScreenWidget.extend({
template: 'OrderListScreenWidget',
show_leftpane: true,
model: 'pos.order',
@ -146,7 +155,7 @@ openerp.pos_order_load = function(instance, local) {
reset_order: function(order) {
order.set_client(undefined);
order.set_order_id(undefined);
order.get('orderLines').reset();
order.orderlines.reset();
return order;
},
@ -154,35 +163,33 @@ openerp.pos_order_load = function(instance, local) {
var self = this;
this._super();
this.$el.find('span.button.back').click(function(){
order = self.pos.get('selectedOrder');
var order = self.pos.get('selectedOrder');
self.reset_order(order);
self.pos_widget.order_widget.change_selected_order();
var ss = self.pos.pos_widget.screen_selector;
ss.set_current_screen('products');
self.chrome.screens.products.order_widget.change_selected_order();
self.gui.show_screen('products');
});
this.$el.find('span.button.validate').click(function(){
var orderModel = new instance.web.Model('pos.order');
var orderModel = new Model('pos.order');
return orderModel.call('unlink', [[self.current_order_id]])
.then(function (result) {
var ss = self.pos.pos_widget.screen_selector;
ss.set_current_screen('products');
}).fail(function (error, event){
if (parseInt(error.code) === 200) {
// Business Logic Error, not a connection problem
self.pos_widget.screen_selector.show_popup(
'error-traceback', {
message: error.data.message,
comment: error.data.debug
.then(function (result) {
self.gui.show_screen('products');
}).fail(function (error, event){
if (parseInt(error.code) === 200) {
// Business Logic Error, not a connection problem
self.gui.show_popup(
'error-traceback', {
message: error.data.message,
comment: error.data.debug
});
}
else{
self.gui.show_popup('error',{
message: _t('Connection error'),
comment: _t('Can not load the Selected Order because the POS is currently offline'),
});
}
else{
self.pos_widget.screen_selector.show_popup('error',{
message: _t('Connection error'),
comment: _t('Can not load the Selected Order because the POS is currently offline'),
});
}
event.preventDefault();
});
}
event.preventDefault();
});
});
var search_timeout = null;
@ -227,109 +234,110 @@ openerp.pos_order_load = function(instance, local) {
load_order: function(order_id) {
var self = this;
var orderModel = new instance.web.Model(this.model);
var orderModel = new Model(this.model);
return orderModel.call('load_order', [order_id])
.then(function (result) {
var order = self.pos.get('selectedOrder');
order = self.load_order_fields(order, result);
order.get('orderLines').reset();
var orderlines = result.orderlines || [];
var unknown_products = [];
for (var i=0, len=orderlines.length; i<len; i++) {
var orderline = orderlines[i];
var product_id = orderline.product_id[0];
var product_name = orderline.product_id[1];
var product = self.pos.db.get_product_by_id(product_id);
if (_.isUndefined(product)) {
unknown_products.push(product_name);
continue;
}
.then(function (result) {
var order = self.pos.get('selectedOrder');
order = self.load_order_fields(order, result);
order.orderlines.reset();
var orderlines = result.orderlines || [];
var unknown_products = [];
for (var i=0, len=orderlines.length; i<len; i++) {
var orderline = orderlines[i];
var product_id = orderline.product_id[0];
var product_name = orderline.product_id[1];
var product = self.pos.db.get_product_by_id(product_id);
if (_.isUndefined(product)) {
unknown_products.push(product_name);
continue;
}
for (var key in orderline) {
if (!key.indexOf('product__')) {
product = self.add_product_attribute(
for (var key in orderline) {
if (!key.indexOf('product__')) {
product = self.add_product_attribute(
product, key, orderline
);
);
}
}
}
order.addProduct(product,
self.prepare_orderline_options(orderline)
);
last_orderline = order.getLastOrderline();
last_orderline = jQuery.extend(last_orderline, orderline);
}
// Forbid POS Order loading if some products are unknown
if (unknown_products.length > 0){
self.pos_widget.screen_selector.show_popup(
'error-traceback', {
message: _t('Unknown Products'),
comment: _t('Unable to load some order lines because the ' +
order.add_product(product,
self.prepare_orderline_options(orderline)
);
var last_orderline = order.get_last_orderline();
last_orderline = jQuery.extend(last_orderline, orderline);
}
// Forbid POS Order loading if some products are unknown
if (unknown_products.length > 0){
self.gui.show_popup(
'error-traceback', {
message: _t('Unknown Products'),
comment: _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 * ') + unknown_products.join("; \n *")
});
self.$el.find('span.button.validate').hide();
}
else{
self.$el.find('span.button.validate').show();
}
});
self.$el.find('span.button.validate').hide();
}
else{
self.$el.find('span.button.validate').show();
}
}).fail(function (error, event){
if (parseInt(error.code) === 200) {
// Business Logic Error, not a connection problem
self.pos_widget.screen_selector.show_popup(
'error-traceback', {
message: error.data.message,
comment: error.data.debug
}).fail(function (error, event){
if (parseInt(error.code) === 200) {
// Business Logic Error, not a connection problem
self.gui.show_popup(
'error-traceback', {
message: error.data.message,
comment: error.data.debug
});
}
else{
self.gui.show_popup('error',{
message: _t('Connection error'),
comment: _t('Can not execute this action because the POS is currently offline'),
});
}
else{
self.pos_widget.screen_selector.show_popup('error',{
message: _t('Connection error'),
comment: _t('Can not execute this action because the POS is currently offline'),
});
}
event.preventDefault();
});
}
event.preventDefault();
});
},
load_orders: function(query) {
var self = this;
var orderModel = new instance.web.Model(this.model);
var orderModel = new Model(this.model);
return orderModel.call('search_read_orders', [query || ''])
.then(function (result) {
self.render_list(result);
}).fail(function (error, event){
if (parseInt(error.code) === 200) {
// Business Logic Error, not a connection problem
self.pos_widget.screen_selector.show_popup(
'error-traceback', {
message: error.data.message,
comment: error.data.debug
}
);
}
else{
self.pos_widget.screen_selector.show_popup('error',{
message: _t('Connection error'),
comment: _t('Can not execute this action because the POS is currently offline'),
});
}
event.preventDefault();
});
.then(function (result) {
self.render_list(result);
}).fail(function (error, event){
if (parseInt(error.code) === 200) {
// Business Logic Error, not a connection problem
self.gui.show_popup(
'error-traceback', {
message: error.data.message,
comment: error.data.debug
}
);
}
else{
self.gui.show_popup('error',{
message: _t('Connection error'),
comment: _t('Can not execute this action because the POS is currently offline'),
});
}
event.preventDefault();
});
},
show: function() {
this._super();
var ss = this.pos.pos_widget.screen_selector;
if (ss.get_current_screen() == 'orderlist') {
if (this.gui.get_current_screen() == 'orderlist') {
this.load_orders();
}
},
on_click_draft_order: function(event){
this.$('.order-list .highlight').removeClass('highlight');
this.current_order_id = parseInt(event.target.parentNode.dataset.orderId);
this.load_order(this.current_order_id);
$(event.target.parentNode).addClass('highlight');
},
render_list: function(orders){
@ -359,5 +367,10 @@ openerp.pos_order_load = function(instance, local) {
},
});
gui.define_screen({'name': 'orderlist', 'widget': OrderListScreenWidget});
return {
LoadButtonButton: LoadButtonWidget,
SaveButtonButton: SaveButtonWidget,
OrderListScreenWidget: OrderListScreenWidget,
};
});

6
pos_order_load/static/src/xml/pos_order_load.xml

@ -44,12 +44,6 @@
</section>
<section class="full-content">
<div class="window">
<section class="subwindow collapsed">
<div class="subwindow-container">
<div class="subwindow-container-fix order-details-contents">
</div>
</div>
</section>
<section class="subwindow">
<div class="subwindow-container">
<div class="subwindow-container-fix touch-scrollable scrollable-y">

28
pos_order_load/view/pos_order_load.xml

@ -1,18 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- vim:fdn=3:
-->
<openerp>
<data>
<template id="assets_backend" name="pos_order_load assets" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript" src="/pos_order_load/static/src/js/pos_order_load.js"></script>
</xpath>
</template>
<template id="index_pos_order_load" name="POS Index Order Load" inherit_id="point_of_sale.index">
<xpath expr="//head" position="inside">
<link rel="stylesheet" href="/pos_order_load/static/src/css/pos_order_load.css"/>
</xpath>
</template>
</data>
</openerp>
<odoo>
<template id="assets_backend" name="pos_order_load assets" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript" src="/pos_order_load/static/src/js/pos_order_load.js"></script>
</xpath>
</template>
<template id="index_pos_order_load" name="POS Index Order Load" inherit_id="point_of_sale.index">
<xpath expr="//head" position="inside">
<link rel="stylesheet" href="/pos_order_load/static/src/css/pos_order_load.css"/>
</xpath>
</template>
</odoo>
Loading…
Cancel
Save