[merge] pos improvements

bzr revid: nicolas.vanhoren@openerp.com-20120106145639-gi7pkwppqo6pzmrb
This commit is contained in:
niv-openerp 2012-01-06 15:56:39 +01:00
commit 10d569c703
2 changed files with 75 additions and 10 deletions

View File

@ -22,6 +22,7 @@
import time
from datetime import datetime
from dateutil.relativedelta import relativedelta
import logging
import netsvc
from osv import fields, osv
@ -29,6 +30,8 @@ from tools.translate import _
from decimal import Decimal
import decimal_precision as dp
_logger = logging.getLogger(__name__)
class pos_config_journal(osv.osv):
""" Point of Sale journal configuration"""
_name = 'pos.config.journal'
@ -46,6 +49,15 @@ class pos_order(osv.osv):
_name = "pos.order"
_description = "Point of Sale"
_order = "id desc"
def create_from_ui(self, cr, uid, orders, context=None):
#_logger.info("orders: %r", orders)
list = []
for order in orders:
list.append(self.create(cr, uid, order, context))
wf_service = netsvc.LocalService("workflow")
wf_service.trg_validate(uid, 'pos.order', list[-1], 'paid', cr)
return list
def unlink(self, cr, uid, ids, context=None):
for rec in self.browse(cr, uid, ids, context=context):

View File

@ -90,6 +90,7 @@ openerp.point_of_sale = function(db) {
this.fetch('account.bank.statement', ['account_id', 'currency', 'journal_id', 'state', 'name'],
[['state', '=', 'open'], ['user_id', '=', this.session.uid]]),
this.fetch('account.journal', ['auto_cash', 'check_dtls', 'currency', 'name', 'type']),
this.fetch('account.tax', ['amount', 'price_include', 'type']),
this.get_app_data())
.pipe(_.bind(this.build_tree, this));
},
@ -119,9 +120,9 @@ openerp.point_of_sale = function(db) {
self.set({'user': result});
}));
},
push: function(osvModel, record) {
pushOrder: function(record) {
var ops = _.clone(this.get('pending_operations'));
ops.push({model: osvModel, record: record});
ops.push(record);
this.set({pending_operations: ops});
return this.flush();
},
@ -135,11 +136,10 @@ openerp.point_of_sale = function(db) {
if (ops.length === 0)
return $.when();
var op = ops[0];
var dataSet = new db.web.DataSet(this, op.model, null);
/* we prevent the default error handler and assume errors
* are a normal use case, except we stop the current iteration
*/
return dataSet.create(op.record).fail(function(unused, event) {
return new db.web.Model("pos.order").get_func("create_from_ui")([op]).fail(function(unused, event) {
event.preventDefault();
}).pipe(_.bind(function() {
console.debug('saved 1 record');
@ -299,8 +299,57 @@ openerp.point_of_sale = function(db) {
quantity: (this.get('quantity')) + 1
});
},
getTotal: function() {
return (this.get('quantity')) * (this.get('list_price')) * (1 - (this.get('discount')) / 100);
getPriceWithoutTax: function() {
return this.getAllPrices().priceWithoutTax;
},
getPriceWithTax: function() {
return this.getAllPrices().priceWithTax;
},
getTax: function() {
return this.getAllPrices().tax;
},
getAllPrices: function() {
var self = this;
var base = (this.get('quantity')) * (this.get('list_price')) * (1 - (this.get('discount')) / 100);
var totalTax = base;
var totalNoTax = base;
var products = pos.store.get('product.product');
var product = _.detect(products, function(el) {return el.id === self.get('id');});
var taxes_ids = product.taxes_id;
var taxes = pos.store.get('account.tax');
var taxtotal = 0;
_.each(taxes_ids, function(el) {
var tax = _.detect(taxes, function(t) {return t.id === el;});
if (tax.price_include) {
var tmp;
if (tax.type === "percent") {
tmp = base - (base / (1 + tax.amount));
} else if (tax.type === "fixed") {
tmp = tax.amount * self.get('quantity');
} else {
throw "This type of tax is not supported by the point of sale: " + tax.type;
}
taxtotal += tmp;
totalNoTax -= tmp;
} else {
var tmp;
if (tax.type === "percent") {
tmp = tax.amount * base;
} else if (tax.type === "fixed") {
tmp = tax.amount * self.get('quantity');
} else {
throw "This type of tax is not supported by the point of sale: " + tax.type;
}
taxtotal += tmp;
totalTax += tmp;
}
});
return {
"priceWithTax": totalTax,
"priceWithoutTax": totalNoTax,
"tax": taxtotal,
};
},
exportAsJSON: function() {
var result;
@ -414,14 +463,18 @@ openerp.point_of_sale = function(db) {
};
Order.prototype.getTotal = function() {
return (this.get('orderLines')).reduce((function(sum, orderLine) {
return sum + orderLine.getTotal();
return sum + orderLine.getPriceWithTax();
}), 0);
};
Order.prototype.getTotalTaxExcluded = function() {
return this.getTotal() / 1.21;
return (this.get('orderLines')).reduce((function(sum, orderLine) {
return sum + orderLine.getPriceWithoutTax();
}), 0);
};
Order.prototype.getTax = function() {
return this.getTotal() / 1.21 * 0.21;
return (this.get('orderLines')).reduce((function(sum, orderLine) {
return sum + orderLine.getTax();
}), 0);
};
Order.prototype.getPaidTotal = function() {
return (this.get('paymentLines')).reduce((function(sum, paymentLine) {
@ -937,7 +990,7 @@ openerp.point_of_sale = function(db) {
var callback, currentOrder;
currentOrder = this.shop.get('selectedOrder');
$('button#validate-order', this.$element).attr('disabled', 'disabled');
pos.push('pos.order', currentOrder.exportAsJSON()).then(_.bind(function() {
pos.pushOrder(currentOrder.exportAsJSON()).then(_.bind(function() {
$('button#validate-order', this.$element).removeAttr('disabled');
return currentOrder.set({
validated: true