Search code examples
javascriptodoo-8

Modify payment lines pos odoo 8


someone have any idea how i should modify the payment-lines in the POS,I want to add a type of credit card(like a many2one, I did it) but every time I add a line my option change to the first and also when the order is finished not save the value in pos.order -> statement_id. enter image description here

here is my code:

function POS_CashRegister (instance, local) {
var pos = instance.point_of_sale;
var _t = instance.web._t;
var QWeb = instance.web.qweb;
var round_pr = instance.web.round_precision
const ParentOrder = pos.Order;

pos.PosModel.prototype.models.push({ //loaded model
model:  'pos.credit.card',
    fields: ['id', 'name'],
    domain: [['pos_active','=',true]],
    loaded: function(self,credit_cards){ //pass parameters
        self.credit_cards = credit_cards;
    },
});

pos.PaymentScreenWidget = pos.PaymentScreenWidget.extend({
    validate_order: function(options) {
        var self = this;
        var currentOrder = self.pos.get('selectedOrder');
        var plines = currentOrder.get('paymentLines').models;
        for (var i = 0; i < plines.length; i++) {
            if(plines[i].cashregister.journal_id[1] === 'Tarjeta de Credito (PEN)')
            {
                var value = plines[i].node.firstElementChild.nextElementSibling.nextElementSibling.firstElementChild.value;
                plines[i].set_credit_card(parseInt(value));
                //console.log(plines[i].node.firstElementChild.nextElementSibling.nextElementSibling.firstElementChild.value);
                //plines[i].node
            }

        }
        console.log(currentOrder);
        self._super(options);
    },
    render_paymentline: function (line) {
        var self = this;

        if(line.cashregister.journal_id[1] !== 'Tarjeta de Credito (PEN)'){
            if (line.cashregister.currency[1] !== 'USD') {
                return this._super(line);
            } else {
                var el_html  = openerp.qweb.render('Paymentline', {widget: this, line: line});
                el_html  = _.str.trim(el_html);

                var el_node  = document.createElement('tbody');

                el_node.innerHTML = el_html;
                el_node = el_node.childNodes[0];
                el_node.line = line;
                el_node.querySelector('.paymentline-delete')
                    .addEventListener('click', this.line_delete_handler);

                el_node.addEventListener('click', this.line_click_handler);
                var sourceInput = el_node.querySelector('.source-input');
                var convertedInput = el_node.querySelector('.converted-input');
                sourceInput.addEventListener('keyup', function (event) {
                    el_node.line.set_usd_amount(event.target.value);
                    convertedInput.value = el_node.line.get_amount_str();
                });
                line.node = el_node;
                return el_node;
            }
        }else {
            return this._super(line);
        }
    },
});

pos.Paymentline = pos.Paymentline.extend({
    initialize: function(attributes, options) {
        this.amount = 0;
        this.cashregister = options.cashregister;
        this.name = this.cashregister.journal_id[1];
        this.selected = false;
        this.credit_card = false;
        this.pos = options.pos;
    },
    set_credit_card: function(value){
        this.credit_card = value;
        this.trigger('change:credit_card',this);
    },
    get_credit_card: function(){
        return this.credit_card;
    },
    export_as_JSON: function(){
        return {
            name: instance.web.datetime_to_str(new Date()),
            statement_id: this.cashregister.id,
            account_id: this.cashregister.account_id[0],
            journal_id: this.cashregister.journal_id[0],
            amount: this.get_amount(),
            credit_card_id: this.get_credit_card(),
        };
    },
});

}

any suggestions?


Solution

  • You can create 2 journals here too. One for visa and another for master If you don't want that drop down there. Another way is you have to store selected option in a variable and then print that variable in front.

    To store selected option initially assigned ids to each values of option and after then while validating order you can get that id of that field and from that id you can get your value. By this way also you can do that.