Skip to Content
Menu
This question has been flagged
1 Reply
5034 Views

I have defined a variable that gets updated, on my odoo 11 JS file but the value gets lost when I close the POS, I want to store this value in a very simple model, do any one know if this is possible?

this is my JS code, I want to store this value into a python model and access the value again if needed:

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

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

    var AlertPaymentScreenWidget = screens.PaymentScreenWidget.include({

        validate_order: function(force_validation) {
            var self = this;
            var order = this.pos.get_order();

            if (this.order_is_valid(force_validation)) {
                this.finalize_validation();
            }

            if(order.is_paid_with_cash()){
                globalCashierTotal += Number(order.get_total_with_tax())
            }
            if(globalCashierTotal >= 3000){
                alert("Some alert");
            }
            rpc.query(
                model: 'send.cash.data',
                method: 'cash_data',
                args: [ globalCashierTotal ]
            )
            alert(globalCashierTotal)
        },

    });

});

This is my python model:

from odoo import models, api

class SendCashData(models.Model):
     _name = 'send.cash.data'

    @api.model
    def cash_data(self, pos_sale):
        total_cash = 0
        total_cash += pos_sale
        return total_cash

The value that I want to store is globalCashierTotal. Thanks in advance.

Avatar
Discard
Best Answer

My common Understanding 

if you want to fetch data from model table ( python to javascript ) we simply call rpc.query in odoo 13.

if you want to send or update data of model table ( javascript to python ) we simply call rurl trigger ( controller) in odoo 13.

Here is my rpc query sending data to my model i hop it helps


val_list = {


'token_number': Token,
'partner_id': customer_name,
'pos_order_id': torder.name,
'est_time': e_time,
 
};
rpc.query({
  model: 'pos.queue',
  method: 'create_token',
  args: [val_list],
}).then(function() {

  console.log("Success")
  }
}).catch(function(reason) {
var error = reason.message;
});

My model is like this
class POSOrderQueue(models.Model):
_name = 'pos.queue'


token_number = fields.Integer(string="Token Number", store=True)
partner_id = fields.Char(store=True)
pos_order_id = fields.Char(store=True)
est_time = fields.Text(string="estimated time", store=True)

@api.model
def create_token(self, val_list):
res = super(POSOrderQueue, self).create(val_list)
print("yes working")
return res.id
Avatar
Discard