Odoo Help

Welcome!

This community 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.

0

POS module modify javascript function odoo 9

By
Sam
on 10/14/15, 10:32 AM 4,018 views

Need to replace original function of odoo 9 pos module with my own one. Never did it before so studied manuals and samples first but still no success.

Original code in screens.js is the following:


var PosBaseWidget = require('point_of_sale.BaseWidget');
var gui = require('point_of_sale.gui');
var models = require('point_of_sale.models');
var core = require('web.core');
var Model = require('web.DataModel');
var utils = require('web.utils');
var formats = require('web.formats');
var QWeb = core.qweb;
var _t = core._t;
var round_pr = utils.round_precision;
/*--------------------------------------*\
| THE SCREEN WIDGET |
\*======================================*/
// The screen widget is the base class inherited
var ScreenWidget = PosBaseWidget.extend({
init: function(parent,options){
this._super(parent,options);
this.hidden = false;
},
barcode_product_screen: 'products', //if defined, this screen will be loaded when a product is scanned
// what happens when a product is scanned :
// it will add the product to the order and go to barcode_product_screen.
barcode_product_action: function(code){
var self = this;
if (self.pos.scan_product(code)) {
if (self.barcode_product_screen) {
self.gui.show_screen(self.barcode_product_screen);
}
} else {
this.barcode_error_action(code);
}
},
... etc ...

I'm doing the following thing:

openerp.my_pos = function (instance) {
module = instance.point_of_sale;
var QWeb = instance.web.qweb;
var _t = instance.web._t;
var gui = require('point_of_sale.gui');
var models = require('point_of_sale.models');
var core = require('web.core');
var Model = require('web.DataModel');
var utils = require('web.utils');
var formats = require('web.formats');
module.ScreenWidget.prototype.barcode_product_action = function (code) {
var show_code;
if (code.code.length > 32) {
show_code = code.code.substring(0, 29) + '...';
} else {
show_code = code.code;
}
this.gui.show_popup('error-barcode', show_code);
};
};

But it does not affect behavior.

Below is my xml file I'm inserting my code with:


<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<template id="assets_backend" name="pos assets" inherit_id="point_of_sale.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript" src="/mopnex_erp/static/src/js/my_pos.js"></script>
</xpath>
</template>
</data>
</openerp>
0
Sam
On 10/14/15, 5:24 PM

Solved finally. Below is the code (v9)


odoo.define('my_pos.my_pos', function (require) {
"use strict";
var screens = require('point_of_sale.screens');

screens.ScreenWidget.include({
barcode_product_action: function (code) {
var show_code;
if (code.code.length > 32) {
show_code = code.code.substring(0, 29) + '...';
} else {
show_code = code.code;
}
this.gui.show_popup('error-barcode', show_code);
},
});
});

I have tried something like that but I got this error:

"Missing dependencies: ["account.account_payment_widget"] " at the line :

var payment = require('account.account_payment_widget');

Adnier Rosello
on 9/8/16, 5:26 PM
0
Tuan
On 1/7/16, 6:48 AM

Hello isio-odoo


Here is an example for you


```

module.PaymentScreenWidget.include({
    	
    	validate_order: function=||var=this(options) {
    		options  options  {}; 
           
            
            // Write your code here

          ._super(options);
}, });

```

Hope it help!

0
Shahid M
On 12/15/15, 4:34 AM


here is a complete example, i have orride set_discount method in orderline module 
openerp.yourprojectname = function(instance, module) {

var module = instance.point_of_sale;

var _t = instance.web._t,

_lt = instance.web._lt;

var QWeb = instance.web.qweb;

var round_di = instance.web.round_decimals;

var round_pr = instance.web.round_precision

var orderline_id = 1;

module.Orderline = Backbone.Model.extend({

initialize: function (attr, options) {

this.pos = options.pos;

this.order = options.order;

this.product = options.product;

this.price = options.product.price;

this.quantity = 1;

this.quantityStr = '1';

this.discount = 0;

this.discountStr = '0';

this.type = 'unit';

this.selected = false;

this.id = orderline_id++;},

set_discount: function (discount) {

//var disc = Math.min(Math.max(parseFloat(discount) || 0, 0), 100);

//this.discount = disc;

this.discount = discount;

this.discountStr = '' + discount;

this.trigger('change', this);

},
)}

0
isio-odoo
On 10/15/15, 5:52 AM

Hello,

I want to change this function from screen on the point of sale

validate_order 

i need to add some other contrainte  on this function

how i can do it (Odoo V8 )

thank you

You can overload this function just like it is done in the code above. Find the proper module and widget, find the function, use "include" or "extend" to add your own code, do not forget to call the original one with "_super" or "prototype".

Sam
on 10/16/15, 4:22 AM

Have you any exemple plz ?

isio-odoo
on 10/16/15, 4:26 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

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

Question tools

1 follower(s)

Stats

Asked: 10/14/15, 10:32 AM
Seen: 4018 times
Last updated: 1/7/16, 6:48 AM