Odoo Help

4 Answers
walid mashal
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
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.

Ask a Question
Keep Informed
2 follower(s)
About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now