Skip to content

Commit

Permalink
[FIX] point_of_sale: load orders with archived product
Browse files Browse the repository at this point in the history
Before this commit: if one product in one of the previous orders is
archived, it won't load the order properly for order management.

opw-3035231

closes odoo#105952

Signed-off-by: Trinh Jacky (trj) <trj@odoo.com>
  • Loading branch information
pedrambiria committed Nov 23, 2022
1 parent c920966 commit 434ec00
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ odoo.define('point_of_sale.OrderFetcher', function (require) {
const idsNotInCache = ids.filter((id) => !(id in this.cache));
if (idsNotInCache.length > 0) {
const fetchedOrders = await this._fetchOrders(idsNotInCache);
await this.comp.env.pos._loadMissingProducts(fetchedOrders);
// Cache these fetched orders so that next time, no need to fetch
// them again, unless invalidated. See `invalidateCache`.
fetchedOrders.forEach((order) => {
Expand Down
8 changes: 6 additions & 2 deletions addons/point_of_sale/static/src/js/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,9 @@ var PosDB = core.Class.extend({
var list = [];
if (product_ids) {
for (var i = 0, len = Math.min(product_ids.length, this.limit); i < len; i++) {
list.push(this.product_by_id[product_ids[i]]);
const product = this.product_by_id[product_ids[i]];
if (!(product.active && product.available_in_pos)) continue;
list.push(product);
}
}
return list;
Expand All @@ -385,7 +387,9 @@ var PosDB = core.Class.extend({
var r = re.exec(this.category_search_string[category_id]);
if(r){
var id = Number(r[1]);
results.push(this.get_product_by_id(id));
const product = this.get_product_by_id(id);
if (!(product.active && product.available_in_pos)) continue;
results.push(product);
}else{
break;
}
Expand Down
27 changes: 24 additions & 3 deletions addons/point_of_sale/static/src/js/models.js
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ exports.PosModel = Backbone.Model.extend({
model: 'product.product',
fields: ['display_name', 'lst_price', 'standard_price', 'categ_id', 'pos_categ_id', 'taxes_id',
'barcode', 'default_code', 'to_weight', 'uom_id', 'description_sale', 'description',
'product_tmpl_id','tracking', 'write_date', 'available_in_pos', 'attribute_line_ids'],
'product_tmpl_id','tracking', 'write_date', 'available_in_pos', 'attribute_line_ids', 'active'],
order: _.map(['sequence','default_code','name'], function (name) { return {name: name}; }),
domain: function(self){
var domain = ['&', '&', ['sale_ok','=',true],['available_in_pos','=',true],'|',['company_id','=',self.config.company_id[0]],['company_id','=',false]];
Expand Down Expand Up @@ -777,8 +777,9 @@ exports.PosModel = Backbone.Model.extend({
* Second load all orders belonging to the same config but from other sessions,
* Only if tho order has orderlines.
*/
load_orders: function(){
load_orders: async function(){
var jsons = this.db.get_unpaid_orders();
await this._loadMissingProducts(jsons);
var orders = [];

for (var i = 0; i < jsons.length; i++) {
Expand Down Expand Up @@ -810,7 +811,27 @@ exports.PosModel = Backbone.Model.extend({
this.get('orders').add(orders);
}
},

async _loadMissingProducts(orders) {
const missingProductIds = new Set([]);
for (const order of orders) {
for (const line of order.lines) {
const productId = line[2].product_id;
if (missingProductIds.has(productId)) continue;
if (!this.db.get_product_by_id(productId)) {
missingProductIds.add(productId);
}
}
}
const productModel = _.find(this.models, function(model){return model.model === 'product.product';});
const fields = productModel.fields;
const products = await this.rpc({
model: 'product.product',
method: 'read',
args: [[...missingProductIds], fields],
context: Object.assign(this.session.user_context, { display_default_code: false }),
});
productModel.loaded(this, products);
},
set_start_order: function(){
var orders = this.get('orders').models;

Expand Down

0 comments on commit 434ec00

Please sign in to comment.