Browse Source

[IMP] : Take in account @antespi remark's

Clean way to inherit in JS And improve get_display_price method
pull/39/head
Adil Houmadi 10 years ago
parent
commit
5261216b01
  1. 25
      pos_pricelist/static/src/js/models.js
  2. 7
      pos_pricelist/static/src/js/widgets.js

25
pos_pricelist/static/src/js/models.js

@ -24,13 +24,14 @@ function pos_pricelist_models(instance, module) {
/** /**
* Extend the POS model * Extend the POS model
*/ */
var PosModelParent = module.PosModel;
module.PosModel = module.PosModel.extend({ module.PosModel = module.PosModel.extend({
/** /**
* @param session * @param session
* @param attributes * @param attributes
*/ */
initialize: function (session, attributes) { initialize: function (session, attributes) {
this.constructor.__super__.initialize.apply(this, arguments);
PosModelParent.prototype.initialize.apply(this, arguments);
this.pricelist_engine = new module.PricelistEngine({ this.pricelist_engine = new module.PricelistEngine({
'pos': this, 'pos': this,
'db': this.db, 'db': this.db,
@ -59,7 +60,7 @@ function pos_pricelist_models(instance, module) {
* @param reason * @param reason
*/ */
on_removed_order: function (removed_order, index, reason) { on_removed_order: function (removed_order, index, reason) {
this.constructor.__super__.on_removed_order.apply(this, arguments);
PosModelParent.prototype.on_removed_order.apply(this, arguments);
if ((reason === 'abandon' || removed_order.temporary) if ((reason === 'abandon' || removed_order.temporary)
&& this.get('orders').size() > 0) { && this.get('orders').size() > 0) {
var current_order = (this.get('orders').at(index) var current_order = (this.get('orders').at(index)
@ -129,13 +130,14 @@ function pos_pricelist_models(instance, module) {
/** /**
* Extend the Order line * Extend the Order line
*/ */
var OrderlineParent = module.Orderline;
module.Orderline = module.Orderline.extend({ module.Orderline = module.Orderline.extend({
/** /**
* @param attr * @param attr
* @param options * @param options
*/ */
initialize: function (attr, options) { initialize: function (attr, options) {
this.constructor.__super__.initialize.apply(this, arguments);
OrderlineParent.prototype.initialize.apply(this, arguments);
this.manuel_price = false; this.manuel_price = false;
if (this.product !== undefined) { if (this.product !== undefined) {
var qty = this.compute_qty(this.order, this.product); var qty = this.compute_qty(this.order, this.product);
@ -160,7 +162,7 @@ function pos_pricelist_models(instance, module) {
* @param quantity * @param quantity
*/ */
set_quantity: function (quantity) { set_quantity: function (quantity) {
this.constructor.__super__.set_quantity.apply(this, arguments);
OrderlineParent.prototype.set_quantity.apply(this, arguments);
var partner = this.order.get_client(); var partner = this.order.get_client();
var product = this.product; var product = this.product;
var db = this.pos.db; var db = this.pos.db;
@ -215,7 +217,7 @@ function pos_pricelist_models(instance, module) {
* @returns {boolean} * @returns {boolean}
*/ */
can_be_merged_with: function (orderline) { can_be_merged_with: function (orderline) {
var result = this.constructor.__super__.can_be_merged_with.apply(
var result = OrderlineParent.prototype.can_be_merged_with.apply(
this, arguments this, arguments
); );
if (!result) { if (!result) {
@ -234,7 +236,7 @@ function pos_pricelist_models(instance, module) {
* @param orderline * @param orderline
*/ */
merge: function (orderline) { merge: function (orderline) {
this.constructor.__super__.merge.apply(this, arguments);
OrderlineParent.prototype.merge.apply(this, arguments);
this.set_unit_price(orderline.price); this.set_unit_price(orderline.price);
}, },
/** /**
@ -297,6 +299,17 @@ function pos_pricelist_models(instance, module) {
} }
return product_taxes; return product_taxes;
}, },
/**
* @returns {*}
*/
get_display_price: function () {
if (this.pos.config.display_price_with_taxes) {
return this.get_price_with_tax();
}
return OrderlineParent.prototype.get_display_price.apply(
this, arguments
);
}
}); });
/** /**

7
pos_pricelist/static/src/js/widgets.js

@ -55,7 +55,12 @@ function pos_pricelist_widgets(instance, module) {
}, },
renderElement: function () { renderElement: function () {
this._super(); this._super();
this.pos.pricelist_engine.update_products_ui(null);
var order = posmodel.get_order();
var customer = null;
if(order) {
customer = order.get_client();
}
this.pos.pricelist_engine.update_products_ui(customer);
} }
}); });
} }

Loading…
Cancel
Save