diff --git a/website_warranty_management/__manifest__.py b/website_warranty_management/__manifest__.py index 18c668093..1cd7d0df4 100644 --- a/website_warranty_management/__manifest__.py +++ b/website_warranty_management/__manifest__.py @@ -21,7 +21,7 @@ ############################################################################# { 'name': 'Website Warranty Management', - 'version': '18.0.1.0.0', + 'version': '18.0.1.0.1', 'category': 'Sale', 'summary': 'Warranty management used to manage warranty of product', 'description': """The "Warranty Management" module enables businesses to diff --git a/website_warranty_management/controllers/website_warranty_management.py b/website_warranty_management/controllers/website_warranty_management.py index a7dbdb154..87636bc39 100644 --- a/website_warranty_management/controllers/website_warranty_management.py +++ b/website_warranty_management/controllers/website_warranty_management.py @@ -38,11 +38,8 @@ class WarrantyClaimController(http.Controller): 'customers': customers, 'products': products}) - @http.route('/warranty/claim/submit', type="http", - auth="public", - methods=["POST"], - website=True, - csrf=False) - def warranty_claim_submit(self,**kwrgs): - """Function to render the claim thanks view""" + + @http.route('/warranty/claim/submit', type='http', auth="public", website=True, csrf=True) + def warranty_claim_submit(self, **post): return request.render('website_warranty_management.claim_thanks_view') + diff --git a/website_warranty_management/doc/RELEASE_NOTES.md b/website_warranty_management/doc/RELEASE_NOTES.md index cd9ff41ee..9d5018ee6 100644 --- a/website_warranty_management/doc/RELEASE_NOTES.md +++ b/website_warranty_management/doc/RELEASE_NOTES.md @@ -4,3 +4,8 @@ #### Version 18.0.1.0.0 #### ADD - Initial Commit for Warranty Management + +#### 18.11.2025 +#### Version 18.0.1.0.1 +##### UPDT +- Added a feature to automatically create the warranty request in the backend when a request is submitted through the website. \ No newline at end of file diff --git a/website_warranty_management/static/src/js/website_registration.js b/website_warranty_management/static/src/js/website_registration.js index 17141aef8..dd44c3bae 100644 --- a/website_warranty_management/static/src/js/website_registration.js +++ b/website_warranty_management/static/src/js/website_registration.js @@ -3,24 +3,32 @@ import publicWidget from "@web/legacy/js/public/public_widget"; publicWidget.registry.WarrantyClaim = publicWidget.Widget.extend({ - selector: '.container', + selector: '.warranty-claim-widget', events: { - 'click #customer_id': '_onClickCustomer', - 'click #sale_order_id': '_onClickSaleOrder', + 'change #customer_id': '_onClickCustomer', + 'change #sale_order_id': '_onClickSaleOrder', 'submit #form_submit': '_onSubmit' }, + init() { this._super(...arguments); this.orm = this.bindService("orm"); }, + async _onClickCustomer(ev) { ev.preventDefault(); var selectedCustomerId = this.$('#customer_id').val(); if (selectedCustomerId) { - var NameId = parseInt(selectedCustomerId); - await this.orm.call("sale.order", "search_read", [[['partner_id', '=', parseInt(selectedCustomerId)]]]).then(function (result) { + await this.orm.call("sale.order", "search_read", [ + [['partner_id', '=', parseInt(selectedCustomerId)], ['is_warranty_check', '=', true]], + ['id', 'name'] + ]).then(function (result) { var $saleOrderDropdown = $('#sale_order_id'); $saleOrderDropdown.empty(); + $saleOrderDropdown.append($('', { + value: '', + text: 'Select Sale Order' + })); $.each(result, function (i, saleOrder) { $saleOrderDropdown.append($('', { value: saleOrder.id, @@ -28,65 +36,143 @@ publicWidget.registry.WarrantyClaim = publicWidget.Widget.extend({ })); }); }); + // Clear products dropdown when customer changes + $('#products_id').empty().append($('', { + value: '', + text: 'Select Product' + })); } }, + async _onClickSaleOrder(ev) { ev.preventDefault(); var selectedSaleOrderId = $('#sale_order_id').val(); + var $productDropdown = $('#products_id'); + if (selectedSaleOrderId) { - await this.orm.call("sale.order.line", "search_read", [[['order_id', '=', parseInt(selectedSaleOrderId)]]]).then(function (result) { - var $productDropdown = $('#products_id'); + await this.orm.call("sale.order.line", "search_read", [ + [['order_id', '=', parseInt(selectedSaleOrderId)]], + ['product_id'] + ]).then(function (result) { $productDropdown.empty(); + $productDropdown.append($('', { + value: '', + text: 'Select Product' + })); $.each(result, function (i, saleOrderLine) { - $.each(result, function (i, saleOrderLine) { - $productDropdown.append($('', { - value: saleOrderLine.product_id[0], // Assuming product_id is a many2one field - text: saleOrderLine.product_id[1], // Assuming product_id has a name field - })); - }); + $productDropdown.append($('', { + value: saleOrderLine.product_id[0], + text: saleOrderLine.product_id[1], + })); }); }); + } else { + $productDropdown.empty(); + $productDropdown.append($('', { + value: '', + text: 'Select Product' + })); } }, + async _onSubmit(ev) { ev.preventDefault(); - // Get the selected sale order ID, customer ID, and product ID var self = this; + + // Get the selected values var selectedSaleOrderId = $('#sale_order_id').val(); var selectedCustomerId = $('#customer_id').val(); var selectedProductId = $('#products_id').val(); var errorMessageElement = $('#error_message'); - if (selectedSaleOrderId && selectedCustomerId && selectedProductId) { - await self.orm.call('warranty.claim', "search_count", [[['sale_order_id', '=', parseInt(selectedSaleOrderId)]]]).then(function (count) { - if (count > 0) { - errorMessageElement.text("A warranty claim for this sale order already exists."); - setTimeout(function () { - errorMessageElement.text(""); - }, 10000); - } else { + + // Clear previous error messages + errorMessageElement.text(""); + + // Validate all fields are selected + if (!selectedCustomerId) { + errorMessageElement.text("Please select a customer."); + setTimeout(function () { + errorMessageElement.text(""); + }, 5000); + return; + } + + if (!selectedSaleOrderId) { + errorMessageElement.text("Please select a sale order."); + setTimeout(function () { + errorMessageElement.text(""); + }, 5000); + return; + } + + if (!selectedProductId) { + errorMessageElement.text("Please select a product."); + setTimeout(function () { + errorMessageElement.text(""); + }, 5000); + return; + } + + try { + // Check if warranty claim already exists for this sale order + const count = await self.orm.call('warranty.claim', "search_count", [ + [['sale_order_id', '=', parseInt(selectedSaleOrderId)]] + ]); + + if (count > 0) { + errorMessageElement.text("A warranty claim for this sale order already exists."); + setTimeout(function () { errorMessageElement.text(""); - self.orm.call('sale.order', 'read', [[parseInt(selectedSaleOrderId)], ['is_warranty_check']]).then(function (saleOrderData) { - if (saleOrderData && saleOrderData[0] && saleOrderData[0].is_warranty_check === true) { - self.orm.call('product.product', 'read', [[parseInt(selectedProductId)], ['is_warranty_available']], ).then(function (productData) { - if (productData && productData[0] && productData[0].is_warranty_available === true) { - self.orm.call('warranty.claim', 'create', [{ - 'sale_order_id': parseInt(selectedSaleOrderId), - 'customer_id': parseInt(selectedCustomerId), - 'product_id': parseInt(selectedProductId), - }], ).then(function (result) { - window.location.href = '/warranty/claim/submit'; - }); - } - }); - } else { - errorMessageElement.text("Selected product does not have warranty available."); - setTimeout(function () { - errorMessageElement.text(""); - }, 10000); - } - }); - } - }); + }, 10000); + return; + } + + // Check if sale order has warranty + const saleOrderData = await self.orm.call('sale.order', 'read', [ + [parseInt(selectedSaleOrderId)], + ['is_warranty_check'] + ]); + + if (!saleOrderData || !saleOrderData[0] || saleOrderData[0].is_warranty_check !== true) { + errorMessageElement.text("Selected sale order does not have warranty available."); + setTimeout(function () { + errorMessageElement.text(""); + }, 10000); + return; + } + + // Check if product has warranty + const productData = await self.orm.call('product.product', 'read', [ + [parseInt(selectedProductId)], + ['is_warranty_available'] + ]); + + if (!productData || !productData[0] || productData[0].is_warranty_available !== true) { + errorMessageElement.text("Selected product does not have warranty available."); + setTimeout(function () { + errorMessageElement.text(""); + }, 10000); + return; + } + + // All validations passed, create the warranty claim + await self.orm.call('warranty.claim', 'create', [{ + 'sale_order_id': parseInt(selectedSaleOrderId), + 'customer_id': parseInt(selectedCustomerId), + 'product_id': parseInt(selectedProductId), + }]); + + // Redirect to success page + window.location.href = '/warranty/claim/submit'; + + } catch (error) { + console.error('Error creating warranty claim:', error); + errorMessageElement.text("An error occurred while creating the warranty claim. Please try again."); + setTimeout(function () { + errorMessageElement.text(""); + }, 10000); } } }); + +export default publicWidget.registry.WarrantyClaim; \ No newline at end of file diff --git a/website_warranty_management/views/website_registration_templates.xml b/website_warranty_management/views/website_registration_templates.xml index 000529394..fdb6f0877 100644 --- a/website_warranty_management/views/website_registration_templates.xml +++ b/website_warranty_management/views/website_registration_templates.xml @@ -26,6 +26,7 @@ + + + + + - Submit @@ -106,11 +113,11 @@ - + + data-snippet="s_website_form"> @@ -126,7 +133,7 @@ - Claim Request is Created + Claim Request is Created Successfully