콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
6 답글
15615 화면

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 ?

관련 게시물 답글 화면 활동
0
10월 15
5386
1
11월 24
1107
4
10월 24
3334
0
10월 22
5070
0
9월 22
38