|
| 1 | +<?xml version="1.0" encoding="utf-8"?> |
| 2 | +<odoo> |
| 3 | + <record id="website_menu_vendor_portal" model="website.menu"> |
| 4 | + <field name="name">Vendor Portal</field> |
| 5 | + <field name="url">/vendor-portal</field> |
| 6 | + <field name="parent_id" ref="website.main_menu"/> |
| 7 | + </record> |
| 8 | + |
| 9 | + <template id="vendor_portal_template" name="Vendor Portal"> |
| 10 | + <t t-call="website.layout"> |
| 11 | + <div class="container my-5"> |
| 12 | + <h2 class="text-center text-primary fw-bold mb-4">Vendor Portal</h2> |
| 13 | + <form id="filterForm" method="GET" action="/vendor-portal" class="row g-3 mb-4 align-items-end"> |
| 14 | + <div class="col-md-3"> |
| 15 | + <label class="form-label">Vendor's Country</label> |
| 16 | + <select name="vendor_country" class="form-select"> |
| 17 | + <option value="">Select Country</option> |
| 18 | + <t t-foreach="countries" t-as="country"> |
| 19 | + <option t-att-value="country['id']" |
| 20 | + t-att-selected="selected_country == country['id'] and 'selected' or None"> |
| 21 | + <t t-esc="country['name']"/> |
| 22 | + </option> |
| 23 | + </t> |
| 24 | + </select> |
| 25 | + </div> |
| 26 | + <div class="col-md-3"> |
| 27 | + <label class="form-label">Vendor</label> |
| 28 | + <select name="vendor_id" class="form-select"> |
| 29 | + <option value="">Select Vendor</option> |
| 30 | + <t t-foreach="vendors" t-as="vendor"> |
| 31 | + <option t-att-value="vendor['id']" |
| 32 | + t-att-selected="selected_vendor == vendor['id'] and 'selected' or None"> |
| 33 | + <t t-esc="vendor['name']"/> |
| 34 | + </option> |
| 35 | + </t> |
| 36 | + </select> |
| 37 | + </div> |
| 38 | + <div class="col-md-3"> |
| 39 | + <label class="form-label">Product Category</label> |
| 40 | + <select name="category_id" class="form-select"> |
| 41 | + <option value="">Select Category</option> |
| 42 | + <t t-foreach="categories" t-as="category"> |
| 43 | + <option t-att-value="category['id']" |
| 44 | + t-att-selected="selected_category == category['id'] and 'selected' or None"> |
| 45 | + <t t-esc="category['name']"/> |
| 46 | + </option> |
| 47 | + </t> |
| 48 | + </select> |
| 49 | + </div> |
| 50 | + <div class="col-md-2"> |
| 51 | + <label class="form-label">Product</label> |
| 52 | + <input type="text" id="productSearch" name="product_name" class="form-control" placeholder="Search Product" |
| 53 | + t-att-value="search_product" autocomplete="off"/> |
| 54 | + <datalist id="product_list"> |
| 55 | + <t t-foreach="matching_products" t-as="product"> |
| 56 | + <option t-att-value="product"/> |
| 57 | + </t> |
| 58 | + </datalist> |
| 59 | + </div> |
| 60 | + <div class="col-md-1 text-end"> |
| 61 | + <button type="submit" class="btn btn-primary w-100">SEARCH</button> |
| 62 | + </div> |
| 63 | + </form> |
| 64 | + <div class="row g-4"> |
| 65 | + <t t-foreach="products" t-as="product"> |
| 66 | + <div class="col-md-12"> |
| 67 | + <div class="card shadow-sm border-0 p-3"> |
| 68 | + <div class="row align-items-center"> |
| 69 | + <div class="col-md-3 text-center"> |
| 70 | + <img t-att-src="product['image_url']" |
| 71 | + class="img-fluid rounded" |
| 72 | + alt="Product Image" |
| 73 | + style="max-width: 150px;"/> |
| 74 | + </div> |
| 75 | + <div class="col-md-6"> |
| 76 | + <h4 class="fw-semibold mb-2"> |
| 77 | + <t t-esc="product['name']"/> |
| 78 | + </h4> |
| 79 | + <p class="text-muted">Vendors:</p> |
| 80 | + <ul class="list-group"> |
| 81 | + <t t-foreach="product['vendors']" t-as="vendor"> |
| 82 | + <li class="list-group-item d-flex justify-content-between"> |
| 83 | + <span><t t-esc="vendor['name']"/></span> |
| 84 | + <span class="fw-bold text-success">💰 <t t-esc="vendor['price']"/> $</span> |
| 85 | + </li> |
| 86 | + </t> |
| 87 | + </ul> |
| 88 | + </div> |
| 89 | + <div class="col-md-3 text-end"> |
| 90 | + <p class="mb-1 text-muted">Min Price: <b><t t-esc="product['min_price']"/></b> $</p> |
| 91 | + <p class="mb-2 text-muted">Max Price: <b><t t-esc="product['max_price']"/></b> $</p> |
| 92 | + <button class="btn btn-primary open-purchase-modal" |
| 93 | + t-att-data-product-id="product['id']" |
| 94 | + t-att-data-vendors="json.dumps(product['vendors'])" |
| 95 | + data-bs-toggle="modal" |
| 96 | + data-bs-target="#purchaseModal"> |
| 97 | + Create Purchase |
| 98 | + </button> |
| 99 | + </div> |
| 100 | + </div> |
| 101 | + </div> |
| 102 | + </div> |
| 103 | + </t> |
| 104 | + </div> |
| 105 | + <div class="my-4 d-flex justify-content-center"> |
| 106 | + <t t-call="website.pager" t-set="pager" t-set-options="{'url': '/vendor-portal'}"/> |
| 107 | + </div> |
| 108 | + <div class="modal fade" id="purchaseModal" tabindex="-1" aria-hidden="true"> |
| 109 | + <div class="modal-dialog"> |
| 110 | + <div class="modal-content"> |
| 111 | + <div class="modal-header"> |
| 112 | + <h5 class="modal-title">Create Purchase Order</h5> |
| 113 | + <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> |
| 114 | + </div> |
| 115 | + <form action="/create-purchase-order" method="post"> |
| 116 | + <div class="modal-body"> |
| 117 | + <label for="vendorSelect" class="form-label">Select Vendor</label> |
| 118 | + <select id="vendorSelect" name="vendor_id" class="form-select" required='True'> |
| 119 | + <option value="">Select Vendor</option> |
| 120 | + </select> |
| 121 | + <label for="quantityInput" class="form-label mt-2">Quantity</label> |
| 122 | + <input type="number" id="quantityInput" name="quantity" class="form-control" value="1" min="1" required='True'/> |
| 123 | + <input type="hidden" id="productInput" name="product_id"/> |
| 124 | + </div> |
| 125 | + <div class="modal-footer"> |
| 126 | + <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button> |
| 127 | + <button type="submit" class="btn btn-primary">Confirm</button> |
| 128 | + </div> |
| 129 | + </form> |
| 130 | + </div> |
| 131 | + </div> |
| 132 | + </div> |
| 133 | + <script> |
| 134 | + document.addEventListener("DOMContentLoaded", function () { |
| 135 | + const productSearch = document.getElementById("productSearch"); |
| 136 | + productSearch.removeAttribute("list"); |
| 137 | + productSearch.addEventListener("input", function () { |
| 138 | + if (this.value.length > 0) { |
| 139 | + this.setAttribute("list", "product_list"); |
| 140 | + } else { |
| 141 | + this.removeAttribute("list"); |
| 142 | + } |
| 143 | + }); |
| 144 | + document.querySelectorAll(".open-purchase-modal").forEach(button => { |
| 145 | + button.addEventListener("click", function () { |
| 146 | + let productId = this.getAttribute("data-product-id"); |
| 147 | + let vendors = JSON.parse(this.getAttribute("data-vendors")); |
| 148 | + |
| 149 | + document.getElementById("productInput").value = productId; |
| 150 | + let vendorSelect = document.getElementById("vendorSelect"); |
| 151 | + vendorSelect.innerHTML = '<option value="">Select Vendor</option>'; |
| 152 | + |
| 153 | + vendors.forEach(vendor => { |
| 154 | + let option = document.createElement("option"); |
| 155 | + option.value = vendor.id; |
| 156 | + option.textContent = vendor.name + " - $" + vendor.price; |
| 157 | + vendorSelect.appendChild(option); |
| 158 | + }); |
| 159 | + }); |
| 160 | + }); |
| 161 | + const urlParams = new URLSearchParams(window.location.search); |
| 162 | + if (urlParams.has('success') && urlParams.get('success') === 'po_created') { |
| 163 | + const poId = urlParams.get('po_id'); |
| 164 | + alert("Purchase Order Created Successfully! PO ID: " + poId); |
| 165 | + urlParams.delete('success'); |
| 166 | + urlParams.delete('po_id'); |
| 167 | + const newUrl = window.location.pathname + (urlParams.toString() ? '?' + urlParams.toString() : ''); |
| 168 | + window.history.replaceState({}, document.title, newUrl); |
| 169 | + } |
| 170 | + }); |
| 171 | + </script> |
| 172 | + </div> |
| 173 | + </t> |
| 174 | + </template> |
| 175 | +</odoo> |
0 commit comments