Browse Source

Nov 26: [FIX] Bug Fixed 'website_warranty_management'

pull/358/merge
Risvana Cybro 3 weeks ago
parent
commit
2a84669e67
  1. 2
      website_warranty_management/__manifest__.py
  2. 11
      website_warranty_management/controllers/website_warranty_management.py
  3. 5
      website_warranty_management/doc/RELEASE_NOTES.md
  4. 174
      website_warranty_management/static/src/js/website_registration.js
  5. 15
      website_warranty_management/views/website_registration_templates.xml

2
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

11
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')

5
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.

174
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($('<option>', {
value: '',
text: 'Select Sale Order'
}));
$.each(result, function (i, saleOrder) {
$saleOrderDropdown.append($('<option>', {
value: saleOrder.id,
@ -28,65 +36,143 @@ publicWidget.registry.WarrantyClaim = publicWidget.Widget.extend({
}));
});
});
// Clear products dropdown when customer changes
$('#products_id').empty().append($('<option>', {
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($('<option>', {
value: '',
text: 'Select Product'
}));
$.each(result, function (i, saleOrderLine) {
$.each(result, function (i, saleOrderLine) {
$productDropdown.append($('<option>', {
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($('<option>', {
value: saleOrderLine.product_id[0],
text: saleOrderLine.product_id[1],
}));
});
});
} else {
$productDropdown.empty();
$productDropdown.append($('<option>', {
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;

15
website_warranty_management/views/website_registration_templates.xml

@ -26,6 +26,7 @@
<select id="customer_id"
name="customer_id"
required="true">
<option value=""/>
<t t-foreach='customers'
t-as="customer">
<option t-esc='customer.name'
@ -35,6 +36,10 @@
</div>
</div>
<br/>
<div id="no_warranty_message"
class="alert alert-info"
style="display: none; margin: 10px 0;"/>
<br/>
<!-- Sale Order Selection -->
<div class="o_row">
<label class="o_form_label"
@ -45,6 +50,7 @@
<select id="sale_order_id"
name="sale_order_id"
required="true">
<option value=""/>
<t t-foreach='sale_orders'
t-as="sale_order">
<option t-esc='sale_order.name'
@ -64,6 +70,7 @@
<select id="products_id"
name="products_id"
required="true">
<option value=""/>
<t t-foreach='products'
t-as="product">
<option t-esc='product.name'
@ -87,7 +94,7 @@
</div>
</div>
<br/>
<button type="submit" onclick="submit();"
<button type="submit"
class="btn btn-primary btn-lg s_website_form_send">
Submit
</button>
@ -106,11 +113,11 @@
</div>
</t>
</template>
<template id="claim_thanks_view" >
<template id="claim_thanks_view">
<t t-call="website.layout">
<div id="wrap" class="oe_structure oe_empty">
<div class="s_website_form" data-vcss="001"
data-snippet="s_website_form">
data-snippet="s_website_form">
<div class="container">
<center>
<br/>
@ -126,7 +133,7 @@
<h5 class="text-center">
<span class="fa fa-check-circle"/>
<span>
Claim Request is Created
Claim Request is Created
<b>Successfully</b>
</span>
</h5>

Loading…
Cancel
Save