Browse Source

May 19: [FIX] Bug fixed 'product_warranty_management_odoo'

17.0
Cybrosys Technologies 3 weeks ago
parent
commit
4d8f1911bf
  1. 114
      product_warranty_management_odoo/static/src/js/website_registration.js

114
product_warranty_management_odoo/static/src/js/website_registration.js

@ -1,123 +1,127 @@
/**@odoo-module*/ /** @odoo-module **/
import publicWidget from "@web/legacy/js/public/public_widget"; import publicWidget from "@web/legacy/js/public/public_widget";
publicWidget.registry.WarrantyClaim = publicWidget.Widget.extend({ publicWidget.registry.WarrantyClaim = publicWidget.Widget.extend({
//init function to bind rpc
init(){
this.rpc = this.bindService("rpc");
},
selector: '.container', selector: '.container',
events: { events: {
'click #customer_id': '_onClickCustomer',
'change #customer_id': '_onClickCustomer', 'change #customer_id': '_onClickCustomer',
'click #sale_order_id': '_onClickSaleOrder',
'change #sale_order_id': '_onClickSaleOrder', 'change #sale_order_id': '_onClickSaleOrder',
'submit #form_submit': '_onSubmit' 'submit #form_submit': '_onSubmit',
},
willStart: function () {
const def = this._super.apply(this, arguments);
this.rpc = this.bindService("rpc");
return def;
}, },
_onClickCustomer: function (ev) { _onClickCustomer: function (ev) {
// To show the sale order of the selected customer only
ev.preventDefault(); ev.preventDefault();
var selectedCustomerId = this.$('#customer_id').val(); const selectedCustomerId = this.$('#customer_id').val();
var $saleOrderDropdown = this.$('#sale_order_id'); const $saleOrderDropdown = this.$('#sale_order_id');
var $productDropdown = this.$('#products_id'); const $productDropdown = this.$('#products_id');
$saleOrderDropdown.empty().append('<option value="">Select Sale Order</option>').prop('disabled', true); $saleOrderDropdown.empty().append('<option value="">Select Sale Order</option>').prop('disabled', true);
$productDropdown.empty().append('<option value="">Select Product</option>').prop('disabled', true); $productDropdown.empty().append('<option value="">Select Product</option>').prop('disabled', true);
if (selectedCustomerId) { if (selectedCustomerId) {
this.rpc('/partner/sale_order', { this.rpc('/partner/sale_order', {
'partner_id': parseInt(selectedCustomerId) partner_id: parseInt(selectedCustomerId)
}).then(function (result) { }).then(result => {
if (result.length > 0) { if (Array.isArray(result) && result.length > 0) {
$saleOrderDropdown.prop('disabled', false); $saleOrderDropdown.prop('disabled', false);
$.each(result, function (i, saleOrder) { result.forEach(saleOrder => {
$saleOrderDropdown.append($('<option>', { $saleOrderDropdown.append($('<option>', {
value: saleOrder.id, value: saleOrder.id,
text: saleOrder.name, text: saleOrder.name,
})); }));
}); });
$productDropdown.prop('disabled', false);
} else {
$productDropdown.prop('disabled', true);
} }
}); });
} }
}, },
_onClickSaleOrder: function (ev) { _onClickSaleOrder: function (ev) {
// get the product details of the selected sale order
ev.preventDefault(); ev.preventDefault();
var selectedSaleOrderId = this.$('#sale_order_id').val(); const selectedSaleOrderId = this.$('#sale_order_id').val();
var $productDropdown = this.$('#products_id'); const $productDropdown = this.$('#products_id');
const self = this;
$productDropdown.empty().append('<option value="">Select Product</option>').prop('disabled', true); $productDropdown.empty().append('<option value="">Select Product</option>').prop('disabled', true);
var self = this
if (selectedSaleOrderId) { if (selectedSaleOrderId) {
this.rpc('/partner/sale_order_line', { this.rpc('/partner/sale_order_line', {
'order_id': parseInt(selectedSaleOrderId) order_id: parseInt(selectedSaleOrderId)
}).then(function (result) { }).then(result => {
var $productDropdown = self.$('#products_id'); if (Array.isArray(result) && result.length > 0) {
$productDropdown.prop('disabled', false); $productDropdown.prop('disabled', false);
$productDropdown.empty(); result.forEach(saleOrderLine => {
$.each(result, function (i, saleOrderLine) { if (saleOrderLine.product_id && saleOrderLine.product_id.length === 2) {
$productDropdown.append($('<option>', { $productDropdown.append($('<option>', {
value: saleOrderLine.product_id[0], value: saleOrderLine.product_id[0],
text: saleOrderLine.product_id[1], text: saleOrderLine.product_id[1],
})); }));
}
}); });
}
}); });
} }
}, },
_onSubmit: function (ev) { _onSubmit: function (ev) {
var self = this
ev.preventDefault(); ev.preventDefault();
// Get the selected sale order ID, customer ID, and product ID const self = this;
var selectedSaleOrderId = this.$('#sale_order_id').val();
var selectedCustomerId = this.$('#customer_id').val(); const selectedSaleOrderId = this.$('#sale_order_id').val();
var selectedProductId = this.$('#products_id').val(); const selectedCustomerId = this.$('#customer_id').val();
var errorMessageElement = this.$('#error_message'); const selectedProductId = this.$('#products_id').val();
const errorMessageElement = this.$('#error_message');
if (selectedSaleOrderId && selectedCustomerId && selectedProductId) { if (selectedSaleOrderId && selectedCustomerId && selectedProductId) {
this.rpc('/partner/warranty_claim_count', { this.rpc('/partner/warranty_claim_count', {
'sale_order_id' : parseInt(selectedSaleOrderId) sale_order_id: parseInt(selectedSaleOrderId)
}).then(function (count) { }).then(count => {
if (count > 0) { if (count > 0) {
errorMessageElement.text("A warranty claim for this sale order already exists."); errorMessageElement.text("A warranty claim for this sale order already exists.");
setTimeout(function () { setTimeout(() => errorMessageElement.text(""), 10000);
errorMessageElement.text("");
}, 10000);
} else { } else {
errorMessageElement.text(""); errorMessageElement.text("");
self.rpc('/read/sale_order', { self.rpc('/read/sale_order', {
'order_id': parseInt(selectedSaleOrderId) , order_id: parseInt(selectedSaleOrderId),
}).then(function (saleOrderData) { }).then(saleOrderData => {
if (saleOrderData && saleOrderData[0] && saleOrderData[0].is_warranty_check === true) { const order = saleOrderData && saleOrderData[0];
if (order && order.is_warranty_check === true) {
self.rpc('/check/selected_product', { self.rpc('/check/selected_product', {
'product_id' : parseInt(selectedProductId) product_id: parseInt(selectedProductId)
}).then(function (productData) { }).then(productData => {
if (productData && productData[0] && productData[0].is_warranty_available === true) { const product = productData && productData[0];
if (product && product.is_warranty_available === true) {
self.rpc('/create_warranty_claim', { self.rpc('/create_warranty_claim', {
'sale_order_id': parseInt(selectedSaleOrderId), sale_order_id: parseInt(selectedSaleOrderId),
'customer_id': parseInt(selectedCustomerId), customer_id: parseInt(selectedCustomerId),
'product_id': parseInt(selectedProductId), product_id: parseInt(selectedProductId),
}).then(function (result) { }).then(() => {
window.location.href = '/warranty/claim/submit'; window.location.href = '/warranty/claim/submit';
}); });
} else { } else {
errorMessageElement.text("Selected product does not have warranty available."); errorMessageElement.text("Selected product does not have warranty available.");
setTimeout(function () { setTimeout(() => errorMessageElement.text(""), 10000);
errorMessageElement.text("");
}, 10000);
} }
}); });
} else { } else {
errorMessageElement.text("Selected sale order does not have warranty available."); errorMessageElement.text("Selected sale order does not have warranty available.");
setTimeout(function () { setTimeout(() => errorMessageElement.text(""), 10000);
errorMessageElement.text("");
}, 10000);
} }
}); });
} }
}); });
} else {
errorMessageElement.text("Please select all required fields.");
setTimeout(() => errorMessageElement.text(""), 10000);
} }
} }
}); });
return publicWidget.registry.WarrantyClaim; return publicWidget.registry.WarrantyClaim;

Loading…
Cancel
Save