Odoo Help

walid mashal
On 2/8/17, 4:18 AM

It's probably late for an answer but if any one wants to do something like this, they can do the following to achieve this purpose. I have just added the code of odoo source but you can replace the code inside set_discount with any code you want and do what you need to do.
create a .js file under your static > src > js folder and add the following code to it:

odoo.define('pos_discounts_question', function (require) {
    "use strict";
    var pos_models = require('point_of_sale.models');
    var custom_models = pos_models.Orderline.extend({   
        set_discount: function(discount){
            var disc = Math.min(Math.max(parseFloat(discount) || 0, 0),100);
            this.discount = disc;
            this.discountStr = '' + disc;
    pos_models.Orderline = custom_models;

make sure you add this .js file to the web.assets_backend

Bernardo Kyotoku
On 2/8/17, 1:39 AM

Part of point_of_sale are extended from web.Class that has the include function. But the model in models.js are extended from Backbone.Model which don't. I assume the Odoo people didn't have time to get at it. Anyway, my workaround was using the prototype properties in Backbone.Model.

Suppose you want to modify the function foo from Model_of_interest. First rename the foo to old_foo using the prototype. Then create the new foo function, you can use the old foo function within the new foo if you (probably) need.

Model_of_interest.prototype.old_foo = model_of_interest.prototype.foo;
Model_of_interest.prototype.foo = function(args){ return this.old_foo(args)}

I don't know the problems of this method, but it worked for me.

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

2 follower(s)


Asked: 12/7/16, 11:31 PM
Seen: 1713 times
Last updated: 3/2/17, 4:29 AM