Getting an Unknown CORS error in Odoo-12 POS UI Book Orders

910 views Asked by At

I am getting this error on POS UI I really need help because I don't understand the error

I am using the Book Order module and I often get this error like 1 in 10 book orders

Uncaught SyntaxError: Unexpected token u in JSON at position 0
    at JSON.parse (<anonymous>)
    at child.add_product (point_of_sale.assets.js:493)
    at Class.line_select (point_of_sale.assets.js:429)
    at HTMLButtonElement.<anonymous> (point_of_sale.assets.js:425)
    at HTMLTableSectionElement.dispatch (web.assets_common.js:892)
    at HTMLTableSectionElement.elemData.handle (web.assets_common.js:865)

here's how I modified the add_product function

add_product: function(product, options){
            var can_add = true;
            var changes = this.pos.get_order();
            var self = this;
            if(changes.selected_orderline){
                if(changes.selected_orderline.order){
                    if(changes.selected_orderline.order.quotation_ref){
                        if(changes.selected_orderline.order.quotation_ref.book_order){
                            can_add= false;
                        }
                    }
                }
            }
            if (can_add){
                if(this._printed){
                    this.destroy();
                    return this.pos.get_order().add_product(product, options);
                }
                this.assert_editable();
                options = options || {};
                var attr = JSON.parse(JSON.stringify(product));
                attr.pos = this.pos;
                attr.order = this;
                var line = new POSInheritmodel.Orderline({}, {pos: this.pos, order: this, product: product});
                if(options.quantity !== undefined){
                    line.set_quantity(options.quantity);
                }

                if(options.price !== undefined){
                    line.set_unit_price(options.price);
                }

                //To substract from the unit price the included taxes mapped by the fiscal position
                this.fix_tax_included_price(line);

                if(options.discount !== undefined){
                    line.set_discount(options.discount);
                }

                if(options.discounted_amount !== undefined){
                    line.set_discount_amount(options.discounted_amount);
                }

                if(options.discount_percentage !== undefined){
                    line.set_if_discount_percentage(options.discount_percentage);
                }

                if(options.discount_amount !== undefined){
                    line.set_if_discount_amount(options.discount_amount);
                }

                if(options.extras !== undefined){
                    for (var prop in options.extras) {
                        line[prop] = options.extras[prop];
                    }
                }

                if(options.uom !== undefined || options.uom !== false){
                    line.set_unit_id(options.uom);  
                }

                if(options.is_board_feet !== undefined && options.is_board_feet){
                    line.set_is_board_feet(true);
                    line.set_length(product.length);
                    line.set_thickness(product.thickness);
                    line.set_width(product.width);
                    // console.log(product.length);
                }else if(options.is_board_feet !== undefined && !options.is_board_feet){
                    line.set_is_board_feet(false);
                }else{
                    if(changes.attributes.client !== null){
                        if(changes.attributes.client.is_wholesale || changes.attributes.client.is_retail){
                            if(product.is_board_feet){
                                line.set_is_board_feet(true);
                                line.set_length(product.length);
                                line.set_thickness(product.thickness);
                                line.set_width(product.width);
                            }
                        }
                    }
                }
                if(options.is_lineal_feet && options.is_lineal_feet !== undefined){
                    line.set_is_lineal_feet(true);
                    line.set_length(product.length);
                    // console.log(product.length);
                }else if(options.is_lineal_feet !== undefined && !options.is_lineal_feet){
                    line.set_is_lineal_feet(false);
                }else{
                    if(changes.attributes.client !== null){
                        if(changes.attributes.client.is_wholesale || changes.attributes.client.is_retail){
                            if(product.is_lineal_feet){
                                line.set_is_lineal_feet(true);
                                line.set_length(product.length);
                            }
                        }
                    }
                }
                if(options.is_lineal_meter && options.is_lineal_meter !== undefined){
                    line.set_is_lineal_meter(true);
                    line.set_length(product.length);
                    // console.log(product.length);
                }else if(options.is_lineal_meter !== undefined && !options.is_lineal_meter){
                    line.set_is_lineal_meter(false);
                }else{
                    if(changes.attributes.client !== null){
                        if(changes.attributes.client.is_wholesale || changes.attributes.client.is_retail){
                            if(product.is_lineal_meter){
                                line.set_is_lineal_meter(true);
                                line.set_length(product.length);
                            }
                        }
                    }
                }
                if(options.with_base_price){
                    line.set_with_base_price(true);
                    if(options.base_price_discount !== undefined){
                        line.set_base_price_discount(options.base_price_discount);
                    }
                    if(options.markup !== undefined){
                        line.set_markup(options.markup);
                    }
                    // console.log(product.length);
                }
                if(options.is_weight !== undefined && options.is_weight){
                    line.set_is_weight(true);
                    line.set_weight_receipt_display(options.base_weight);
                }else if(options.is_weight !== undefined && !options.is_weight){
                    line.set_is_weight(false);
                    if(options.base_weight !== undefined && options.base_weight != 0){
                        line.set_weight_receipt_display(options.base_weight);
                    }else{
                        line.set_weight_receipt_display(product.weight);
                    }
                }else{
                    if(options.base_weight !== undefined && options.base_weight != 0){
                        line.set_weight_receipt_display(options.base_weight);
                    }else{
                        line.set_weight_receipt_display(product.weight);
                    }
                    if(changes.attributes.client !== null){
                        if(changes.attributes.client.is_wholesale || changes.attributes.client.is_retail){
                            if(product.is_weight){
                                line.set_is_weight(true);
                            }
                        }
                    }
                }

                var to_merge_orderline;
                for (var i = 0; i < this.orderlines.length; i++) {
                    if(this.orderlines.at(i).can_be_merged_with(line) && options.merge !== false){
                        to_merge_orderline = this.orderlines.at(i);
                    }
                }
                if (to_merge_orderline){
                    to_merge_orderline.merge(line);
                } else {
                    this.orderlines.add(line);
                }
                this.select_orderline(this.get_last_orderline());

                if(line.has_product_lot){
                    this.display_lot_popup();
                }
            }else{
                self.pos.gui.show_popup('error',{
                    title :_t('Modification Restricted'),
                    body  :_t('Modification is not allowed for booked orders.'),
                });
            }
        },

this is all that I can give I didn't try anything to fix this because I don't really know where to start any help is very much appreciated thank you.

0

There are 0 answers