Browse Source

[ADD] : When we mouseover the price tag, a tooltip is shown to indicate the computation depending on the quantity like this output :

1x -> 100 €
3x -> 70 €
5x -> 50 €
[IMP] : update readme to indicate the new improvements
pull/39/head
Adil Houmadi 10 years ago
parent
commit
9663670948
  1. 11
      pos_pricelist/README.rst
  2. 102
      pos_pricelist/static/src/css/style.css
  3. 13
      pos_pricelist/static/src/js/db.js
  4. 85
      pos_pricelist/static/src/js/models.js
  5. 4
      pos_pricelist/static/src/js/widgets.js

11
pos_pricelist/README.rst

@ -35,9 +35,16 @@ The POS will recognize it and will compute the price according to the rule defin
2. (-2) : Rule based on supplierinfo
3. (default) : Any price type which is set on the product form
3. An new option is introduced in the POS config to let the user show price with taxes in product widget.
the UI is updated when we change the customer in order to adapt the prices.
The computation take in account the pricelist and the fiscal position of the customer
4. When we mouseover the price tag, a tooltip is shown to indicate the computation depending on the quantity like this output :
1x -> 100 €
3x -> 70 €
5x -> 50 €
Missing features
----------------
* As you may know, product template is not fully implemented in the POS, so I decided to drop it from this module.
* When there are more than one price depending on the quantity, only the price
for first interval is shown.

102
pos_pricelist/static/src/css/style.css

@ -43,4 +43,104 @@
background-color: #f7f7f7;
border-bottom: 1px solid #ebebeb;
border-radius: 5px 5px 0 0;
}
}
/* ToolTip */
.tooltip {
position: absolute;
z-index: 1070;
display: block;
font-size: 12px;
line-height: 1.4;
visibility: visible;
filter: alpha(opacity=0);
opacity: 0;
}
.tooltip.in {
filter: alpha(opacity=90);
opacity: .9;
}
.tooltip.top {
padding: 5px 0;
margin-top: -3px;
}
.tooltip.right {
padding: 0 5px;
margin-left: 3px;
}
.tooltip.bottom {
padding: 5px 0;
margin-top: 3px;
}
.tooltip.left {
padding: 0 5px;
margin-left: -3px;
}
.tooltip-inner {
max-width: 200px;
padding: 3px 8px;
color: #fff;
text-align: center;
text-decoration: none;
background-color: #000;
border-radius: 4px;
}
.tooltip-arrow {
position: absolute;
width: 0;
height: 0;
border-color: transparent;
border-style: solid;
}
.tooltip.top .tooltip-arrow {
bottom: 0;
left: 50%;
margin-left: -5px;
border-width: 5px 5px 0;
border-top-color: #000;
}
.tooltip.top-left .tooltip-arrow {
bottom: 0;
left: 5px;
border-width: 5px 5px 0;
border-top-color: #000;
}
.tooltip.top-right .tooltip-arrow {
right: 5px;
bottom: 0;
border-width: 5px 5px 0;
border-top-color: #000;
}
.tooltip.right .tooltip-arrow {
top: 50%;
left: 0;
margin-top: -5px;
border-width: 5px 5px 5px 0;
border-right-color: #000;
}
.tooltip.left .tooltip-arrow {
top: 50%;
right: 0;
margin-top: -5px;
border-width: 5px 0 5px 5px;
border-left-color: #000;
}
.tooltip.bottom .tooltip-arrow {
top: 0;
left: 50%;
margin-left: -5px;
border-width: 0 5px 5px;
border-bottom-color: #000;
}
.tooltip.bottom-left .tooltip-arrow {
top: 0;
left: 5px;
border-width: 0 5px 5px;
border-bottom-color: #000;
}
.tooltip.bottom-right .tooltip-arrow {
top: 0;
right: 5px;
border-width: 0 5px 5px;
border-bottom-color: #000;
}

13
pos_pricelist/static/src/js/db.js

@ -174,6 +174,19 @@ function pos_pricelist_db(instance, module) {
= prices['priceWithTax']
}
}
},
find_product_rules: function (product) {
var len = this.pricelist_item_sorted.length;
var rules = [];
for (var i = 0; i < len; i++) {
var rule = this.pricelist_item_sorted[i];
if ((rule.product_id && rule.product_id[0] == product.id) ||
(rule.categ_id && product.categ_id
&& rule.categ_id[0] == product.categ_id[0])) {
rules.push(rule);
}
}
return rules;
}
})
}

85
pos_pricelist/static/src/js/models.js

@ -189,7 +189,7 @@ function pos_pricelist_models(instance, module) {
var taxdetail = {};
var product_taxes = this.get_applicable_taxes_for_orderline();
var all_taxes = _(this.compute_all(product_taxes, base)).flatten();
_(all_taxes).each(function(tax) {
_(all_taxes).each(function (tax) {
if (tax.price_include) {
totalNoTax -= tax.amount;
} else {
@ -259,13 +259,13 @@ function pos_pricelist_models(instance, module) {
/**
* @returns {Array}
*/
get_applicable_taxes_for_orderline: function() {
get_applicable_taxes_for_orderline: function () {
// find applicable taxes for this product and this customer
var fiscal_position_taxes = [];
var product_taxes = [];
var product = this.get_product();
var partner = this.order ? this.order.get_client() : null;
var taxes = this.pos.taxes;
var taxes = this.pos.taxes;
if (partner && partner.property_account_position) {
fiscal_position_taxes =
this.pos.db.find_taxes_by_fiscal_position_id(
@ -516,35 +516,66 @@ function pos_pricelist_models(instance, module) {
for (var i = 0, len = product_list_ui.length; i < len; i++) {
var product_ui = product_list_ui[i];
var product_id = $(product_ui).data('product-id');
// price which computed via pricelist
var product = $.extend({}, db.get_product_by_id(product_id));
var price = this.compute_price_all(db, product, partner, 1);
if (price !== false && price !== 0.0) {
if (this.pos.config.display_price_with_taxes) {
// create a fake order in order to get price
// for this customer
var order = new module.Order({pos: this.pos});
order.set_client(partner);
var orderline = new openerp.point_of_sale.Orderline({},
{
pos: this.pos,
order: order,
product: product,
price: price
}
);
// reset the sequence
this.pos.pos_session.sequence_number--;
var prices = orderline.get_all_prices();
price = prices['priceWithTax'];
var rules = db.find_product_rules(product);
var quantities = [];
quantities.push(1);
for (var j = 0; j < rules.length; j++) {
quantities.push(rules[j].min_quantity);
}
quantities = quantities.sort();
var prices_displayed = '';
for (var k = 0; k < quantities.length; k++) {
var qty = quantities[k];
var price = this.compute_price_all(
db, product, partner, qty
);
if (price !== false && price !== 0.0) {
if (this.pos.config.display_price_with_taxes) {
var prices = this.simulate_price(
product, partner, price, qty
);
price = prices['priceWithTax']
}
price = round_di(parseFloat(price)
|| 0, this.pos.dp['Product Price']);
price = this.pos_widget.format_currency(price);
if (k == 0) {
$(product_ui).find('.price-tag').html(price);
}
prices_displayed += qty
+ 'x &#8594; ' + price + '<br/>';
}
price = round_di(parseFloat(price)
|| 0, this.pos.dp['Product Price']);
price = this.pos_widget.format_currency(price);
$(product_ui).find('.price-tag').html(price);
}
if (prices_displayed != '') {
$(product_ui).find('.price-tag').attr(
'data-original-title', prices_displayed
);
$(product_ui).find('.price-tag').attr(
'data-toggle', 'tooltip'
);
$(product_ui).find('.price-tag').tooltip(
{delay: {show: 50, hide: 100}}
);
}
}
},
simulate_price: function (product, partner, price, qty) {
// create a fake order in order to get price
// for this customer
var order = new module.Order({pos: this.pos});
order.set_client(partner);
var orderline = new openerp.point_of_sale.Orderline
({}, {
pos: this.pos, order: order,
product: product, price: price
});
orderline.set_quantity(qty);
// reset the sequence
this.pos.pos_session.sequence_number--;
var prices = orderline.get_all_prices();
return prices;
},
/**
*
* @param partner

4
pos_pricelist/static/src/js/widgets.js

@ -52,6 +52,10 @@ function pos_pricelist_widgets(instance, module) {
this.display_price_with_taxes
= posmodel.config.display_price_with_taxes
}
},
renderElement: function () {
this._super();
this.pos.pricelist_engine.update_products_ui(null);
}
});
}

Loading…
Cancel
Save