[FIX] pos_cache: make it compatible with onboarding tool

STEPS:
* install pos_cache in clean database without demo
* open pos
* click OK on popup "Would you like to load demo data"

closes odoo/odoo#63103

Before: error, products are not loaded even after refreshing
After: no errors, products are loaded
X-original-commit: e669ea8a6a79fdf7e309b3191c9648c60179d195
Signed-off-by: pimodoo <pimodoo@users.noreply.github.com>
This commit is contained in:
Ivan Yelizariev
2020-12-09 15:12:53 +00:00
parent 80e0a2181d
commit 4938c84739
4 changed files with 18 additions and 2 deletions
+1
View File
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import models
from . import controllers
+2
View File
@@ -0,0 +1,2 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import main
+12
View File
@@ -0,0 +1,12 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo.addons.point_of_sale.controllers.main import PosController
from odoo import http
from odoo.http import request
class PosCache(PosController):
@http.route()
def load_onboarding_data(self):
super().load_onboarding_data()
request.env["pos.cache"].refresh_all_caches()
+3 -2
View File
@@ -21,6 +21,7 @@ models.PosModel = models.PosModel.extend({
// uncached way, so get rid of it.
if (product_index !== -1) {
this.models.splice(product_index, 1);
this.product_model = product_model;
}
return posmodel_super.load_server_data.apply(this, arguments).then(function () {
// Give both the fields and domain to pos_cache in the
@@ -28,8 +29,8 @@ models.PosModel = models.PosModel.extend({
// values in the backend and they automatically stay in
// sync with whatever is defined (and maybe extended by
// other modules) in js.
var product_fields = typeof product_model.fields === 'function' ? product_model.fields(self) : product_model.fields;
var product_domain = typeof product_model.domain === 'function' ? product_model.domain(self) : product_model.domain;
var product_fields = typeof self.product_model.fields === 'function' ? self.product_model.fields(self) : self.product_model.fields;
var product_domain = typeof self.product_model.domain === 'function' ? self.product_model.domain(self) : self.product_model.domain;
var records = rpc.query({
model: 'pos.config',
method: 'get_products_from_cache',