Skip to Content
Menu
You need to be registered to interact with the community.
This question has been flagged
2 Odgovori
7714 Prikazi

Hello. I am trying to add a new field in the current order and asing the value on click button in the pos screen, the button work fine, but not save the value in the python field


this is my field in python =

class PosOrder(models.Model):
_inherit = 'pos.order'

cita_id = fields.Many2one('citas.model')



And this in the javascript =

var models = require('point_of_sale.models');
var _super_Order = models.Order.prototype;
models.Order = models.Order.extend({

export_as_JSON: function () {
var json = _super_Order.export_as_JSON.apply(this, arguments);
if (this.cita_id){
json.cita_id = this.cita_id;
}
return json
}

        })


in the button_click i add the cita_id integer
button_click: function(){
    this.cita_id = 77 // for example
}


but it does not work, it does not save the value in the python field

Please suggest any solution.






Avatar
Opusti
Avtor

Vishnu Vanneri's answer worked for me. Thank you both for your answers. regards!!!

P.S. This is my first question!

Avtor

sorry, I do not have karma to select the answer.

Best Answer

Hi Omar Faccuseh, try like below,


var pos_screens = require('point_of_sale.screens');
var rpc = require('web.rpc');

var yourButton = pos_screens.ActionButtonWidget.extend({
template: 'yourButton',
button_click: function(){

var records = rpc.query({
model: 'pos.incentive',
method: 'your_pythton_method', // HERE YOU CAN CALL BAKEND PYTHON METHOD, WHERE YOU CAN USE A WIRTE FUNCTION
args: add_parameters_here_to_be_sented_to_python_method,

});

},
});


pos_screens.define_action_button({
'name': 'Button',
'widget': yourButton,
'condition': function(){
return this.pos;
},
});









Avatar
Opusti
Best Answer

Hello,

Try to add like this in PY.

class PosOrder(models.Model):
_inherit = 'pos.order'

cita_id = fields.Many2one('citas.model')

#use this function

@api.model
def _order_fields(self, ui_order):
order_fields = super(PosOrder, self)._order_fields(ui_order)
order_fields['cita_id'] = ui_order.get('cita_id', False)
return order_fields

Avatar
Opusti
Related Posts Odgovori Prikazi Aktivnost
1
jul. 21
15374
3
maj 22
9095
1
dec. 23
1502
0
mar. 19
3316
1
feb. 24
2563