Skip to Content
Menú
This question has been flagged
1 Respondre
591 Vistes

I added customer field in pos.payment.method and i need to use it in the payment when pay in session to prevent requesting customer when i a click on validate button after choosing payment method which has identify customer field equal true 
i added this code in js to take customer from the selected payment method but it doesn't work

odoo15

odoo.define('pos_set_default_customer.GetCustomer', function(require) {
"use strict";

var models = require('point_of_sale.models');
models.load_fields('pos.payment.method', 'default_partner_id');


var _super_order = models.Order.prototype;
models.Order = models.Order.extend({
initialize: function() {
_super_order.initialize.apply(this, arguments);
if (this.pos.payment.method.default_partner_id && !this.export_as_JSON().partner_id) {
this.set_client(this.pos.db.get_partner_by_id(this.pos.payment.method.default_partner_id[0]));
}
},
});
});


Avatar
Descartar
Best Answer

Hi,

Try the below code:


Load custom fields in pos models.

odoo.define('module_name.models', function (require) {

    'use strict';


    const models = require('point_of_sale.models');

    models.load_fields('pos.payment.method', 'default_partner_id');

});


Extend payment screen:

odoo.define('module_name.PaymentScreen', function (require) {

    'use strict';


    const PaymentScreen = require('point_of_sale.PaymentScreen');

    const Registries = require('point_of_sale.Registries');


    const CustomPaymentScreen = (PaymentScreen) =>

        class extends PaymentScreen {

            addNewPaymentLine({ detail: paymentMethod }) {

                        const order = this.env.pos.get_order();

                                const PaymentLine = paymentMethod.default_partner_id[0];

                                order.set_client(this.env.pos.db.get_partner_by_id(PaymentLine));

                                super.addNewPaymentLine({ detail: paymentMethod });

            }

            }

        }

    Registries.Component.extend(PaymentScreen, CustomPaymentScreen);


    return PaymentScreen;

});


Hope it helps

Avatar
Descartar