Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
6 Відповіді
15759 Переглядів

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>
Аватар
Відмінити
Автор Найкраща відповідь

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');

Найкраща відповідь

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!

Аватар
Відмінити
Найкраща відповідь


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);

},
)}

Аватар
Відмінити
Найкраща відповідь

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".

Have you any exemple plz ?

Related Posts Відповіді Переглядів Дія
0
жовт. 15
5550
1
лист. 24
1541
4
жовт. 24
3895
0
жовт. 22
5241
0
вер. 22
38