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. 125
      pos_order_load/static/src/js/pos_order_load.js
  4. 6
      pos_order_load/static/src/xml/pos_order_load.xml
  5. 8
      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):

125
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({
var _super_order = models.Order.prototype;
models.Order = models.Order.extend({
set_order_id: function(id) {
this.set({
@ -43,15 +58,14 @@ 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({
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');
});
},
});
@ -60,14 +74,14 @@ openerp.pos_order_load = function(instance, local) {
New Widget SaveButtonWidget:
* On click, save the current draft order;
*/
module.SaveButtonWidget = module.PosBaseWidget.extend({
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(){
@ -86,54 +100,49 @@ openerp.pos_order_load = function(instance, local) {
* Create new screen;
* Add load and save button;
*/
module.PosWidget = module.PosWidget.extend({
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.screen_selector.screen_set.orderlist = this.orderlist_screen;
this.load_button = new LoadButtonWidget(this, {});
this.load_button.appendTo(this.$('div.order-empty'));
// 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:
* Extend OrderWidget:
*/
module.OrderWidget = module.OrderWidget.extend({
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:
* 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({
//
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,29 +163,27 @@ 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');
self.gui.show_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(
self.gui.show_popup(
'error-traceback', {
message: error.data.message,
comment: error.data.debug
});
}
else{
self.pos_widget.screen_selector.show_popup('error',{
self.gui.show_popup('error',{
message: _t('Connection error'),
comment: _t('Can not load the Selected Order because the POS is currently offline'),
});
@ -227,12 +234,12 @@ 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();
order.orderlines.reset();
var orderlines = result.orderlines || [];
var unknown_products = [];
for (var i=0, len=orderlines.length; i<len; i++) {
@ -253,15 +260,15 @@ openerp.pos_order_load = function(instance, local) {
}
}
order.addProduct(product,
order.add_product(product,
self.prepare_orderline_options(orderline)
);
last_orderline = order.getLastOrderline();
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.pos_widget.screen_selector.show_popup(
self.gui.show_popup(
'error-traceback', {
message: _t('Unknown Products'),
comment: _t('Unable to load some order lines because the ' +
@ -277,14 +284,14 @@ openerp.pos_order_load = function(instance, local) {
}).fail(function (error, event){
if (parseInt(error.code) === 200) {
// Business Logic Error, not a connection problem
self.pos_widget.screen_selector.show_popup(
self.gui.show_popup(
'error-traceback', {
message: error.data.message,
comment: error.data.debug
});
}
else{
self.pos_widget.screen_selector.show_popup('error',{
self.gui.show_popup('error',{
message: _t('Connection error'),
comment: _t('Can not execute this action because the POS is currently offline'),
});
@ -295,14 +302,14 @@ openerp.pos_order_load = function(instance, local) {
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(
self.gui.show_popup(
'error-traceback', {
message: error.data.message,
comment: error.data.debug
@ -310,7 +317,7 @@ openerp.pos_order_load = function(instance, local) {
);
}
else{
self.pos_widget.screen_selector.show_popup('error',{
self.gui.show_popup('error',{
message: _t('Connection error'),
comment: _t('Can not execute this action because the POS is currently offline'),
});
@ -321,15 +328,16 @@ openerp.pos_order_load = function(instance, local) {
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">

8
pos_order_load/view/pos_order_load.xml

@ -1,8 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- vim:fdn=3:
-->
<openerp>
<data>
<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>
@ -13,6 +10,5 @@
<link rel="stylesheet" href="/pos_order_load/static/src/css/pos_order_load.css"/>
</xpath>
</template>
</data>
</openerp>
</odoo>
Loading…
Cancel
Save