Help

2

How to Create Button in Pos for Clear orderline in one click

Avatar
jithesh

Hi, friends its simple example to start customization with the pos

xml part.............................................

<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>

        <template id="assets_backend" name="OrderLine_Clear assets" inherit_id="web.assets_backend">
            <xpath expr="." position="inside">
                <script type="text/javascript" src="/pos_clear_orderline/static/src/js/pos.js"/>
            </xpath>
        </template>

    </data>
</openerp>


js part.....................................

odoo.define('pos_clear_orderline.pos', function (require) {
"use strict";

var screens = require('point_of_sale.screens');

    var OrderLineClear = screens.ActionButtonWidget.extend({
        template: 'OrderLineClear',
        button_click: function(){
         var order = self.pos.get_order();
             var lines = jQuery.extend(true, {}, order['orderlines']['models']);

     //looping through each line
             $.each(lines, function(k, line){
             console.log(line);
             line.set_quantity('remove');
        });

        },
    });
    screens.define_action_button({
        'name': 'OrderLine_Clear',
        'widget': OrderLineClear,
    });
});

Avatar
Discard
1 Answer
0
Avatar
Tintuk Tomin
Best Answer

The below code is enough for clear a single line.

var OrderLineClear = screens.ActionButtonWidget.extend({
template: "OrderLineClear",

button_click: function(){
var self = this;
this.clear_button_fun();
},

clear_button_fun(){
var order = this.pos.get_order();
order.remove_orderline(order.get_selected_orderline())
},
});
screens.define_action_button({'name': 'clear_button_fun','widget': OrderLineClear,});

If you want to change it to clear all the cart the code will be,


var order = this.pos.get_order();

for (var lines in order.get_orderlines()){
    order.remove_orderline(order.get_orderlines());



Avatar
Discard