Skip to content

Commit

Permalink
Mostrar todos los proveedores en los filtros, y arreglar los filtros …
Browse files Browse the repository at this point in the history
…de búsqueda (#56)
  • Loading branch information
Miguel-Granda1121 authored Jan 10, 2025
1 parent c414c17 commit e7866f6
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 18 deletions.
24 changes: 15 additions & 9 deletions purchase_portal/controllers/prequest_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,23 +66,29 @@ def get_purchase_request_product_table(self, **kw):
}
)

product_ids = property_id.product_ids
if search:
product_ids = request.env["product.product"].search([
product_ids = property_id.sudo().product_ids
if search and search != '':
product_ids = request.env["product.product"].sudo().search([
("id", "in", product_ids.ids),
"|",
("name", "ilike", search),
("default_code", "ilike", search)
])
if category_id and category_id != 'all':
product_ids = product_ids.filtered(lambda x: x.categ_id.id == int(category_id))
product_ids = request.env["product.product"].sudo().search([
("id", "in", product_ids.ids),
("categ_id", "=", int(category_id))
])

if seller_id and seller_id != 'all':
partner_id = request.env['res.partner'].browse(int(seller_id))
product_ids = product_ids.filtered(
lambda x: partner_id.id in x.seller_ids.mapped('name').ids
or partner_id.commercial_partner_id.id in x.seller_ids.mapped('name').ids
)
partner_id = request.env['res.partner'].sudo().search([('id', '=', int(seller_id))])
commercial_partner_id = partner_id.commercial_partner_id
product_ids = request.env["product.product"].sudo().search([
("id", "in", product_ids.ids),
"|",
("seller_ids.name", "in", [partner_id.name]),
("seller_ids.name", "in", [commercial_partner_id.name])
])

if request.env.user.banned_product_ids:
product_ids = product_ids - request.env.user.banned_product_ids
Expand Down
18 changes: 15 additions & 3 deletions purchase_portal/static/src/js/purchase_request.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,15 @@ publicWidget.registry.PurchaseRequestPortal = publicWidget.Widget.extend({
let search = $(ev.currentTarget).val();
let property_id = $(ev.currentTarget).attr("data-property_id");
let purchase_request = $(ev.currentTarget).attr("data-purchase_request");
let seller_id = $("#product_seller").val();
let category_id = $("#product_category").val();

this._rpc({
route: "/purchase_request_product_table",
params: {
'search': search,
'seller_id': seller_id,
'category_id': category_id,
'property_id': property_id,
'purchase_request': purchase_request,
},
Expand All @@ -59,7 +63,7 @@ publicWidget.registry.PurchaseRequestPortal = publicWidget.Widget.extend({
let json_data = JSON.parse(new_data);
if ("error" in json_data) {
$("#edit_errors")[0].innerHTML = "<div class='alert alert-danger' role='alert'>"+json_data["message"]+"</div>";
}
}
} catch (e) {
$("#edit_errors").empty();
$("#purchase_request_details_list").empty();
Expand All @@ -83,7 +87,7 @@ publicWidget.registry.PurchaseRequestPortal = publicWidget.Widget.extend({
let json_data = JSON.parse(new_data);
if ("error" in json_data) {
$("#edit_errors")[0].innerHTML = "<div class='alert alert-danger' role='alert'>"+json_data["message"]+"</div>";
}
}
} catch (e) {
$("#edit_errors").empty();
$("#purchase_request_details_list").empty();
Expand All @@ -105,7 +109,7 @@ publicWidget.registry.PurchaseRequestPortal = publicWidget.Widget.extend({
let json_data = JSON.parse(new_data);
if ("error" in json_data) {
$("#edit_errors")[0].innerHTML = "<div class='alert alert-danger' role='alert'>"+json_data["message"]+"</div>";
}
}
} catch (e) {
$("#edit_errors").empty();
$("#purchase_request_details_list").empty();
Expand All @@ -115,13 +119,17 @@ publicWidget.registry.PurchaseRequestPortal = publicWidget.Widget.extend({
},

_onChangeSelect: function (ev) {
let search = $("#search").val();
let category_id = $(ev.currentTarget).val();
let seller_id = $("#product_seller").val();
let property_id = $(ev.currentTarget).attr("data-property_id");
let purchase_request = $(ev.currentTarget).attr("data-purchase_request");

this._rpc({
route: "/purchase_request_product_table",
params: {
'search': search,
'seller_id': seller_id,
'category_id': category_id,
'property_id': property_id,
'purchase_request': purchase_request,
Expand Down Expand Up @@ -177,14 +185,18 @@ publicWidget.registry.PurchaseRequestPortal = publicWidget.Widget.extend({
},

_onChangeSeller: function (ev) {
let search = $("#search").val();
let seller_id = $(ev.currentTarget).val();
let category_id = $("#product_category").val();
let property_id = $(ev.currentTarget).attr("data-property_id");
let purchase_request = $(ev.currentTarget).attr("data-purchase_request");

this._rpc({
route: "/purchase_request_product_table",
params: {
'search': search,
'seller_id': seller_id,
'category_id': category_id,
'property_id': property_id,
'purchase_request': purchase_request,
},
Expand Down
13 changes: 7 additions & 6 deletions purchase_portal/templates/purchase_request.xml
Original file line number Diff line number Diff line change
Expand Up @@ -252,20 +252,21 @@
<div class="row">
<div t-attf-class="col-6 input-group mb-2" role="search">
<t t-set="search_placeholder">Search...</t>
<input type="search" t-att-data-purchase_request="purchase_request.id" t-att-data-property_id="current_property_id.id" name="search" class="search-query form-control oe_search_box" t-att-placeholder="placeholder if placeholder else search_placeholder" t-att-value="search"/>
<input id="search" type="search" t-att-data-purchase_request="purchase_request.id" t-att-data-property_id="current_property_id.id" name="search" class="search-query form-control oe_search_box" t-att-placeholder="placeholder if placeholder else search_placeholder" t-att-value="search"/>
</div>
<div t-attf-class="col-6 input-group mb-2">
<select name="product_category" class="purchase_select" t-att-data-purchase_request="purchase_request.id" t-att-data-property_id="current_property_id.id">
<select id="product_category" name="product_category" class="purchase_select" t-att-data-purchase_request="purchase_request.id" t-att-data-property_id="current_property_id.id">
<option value="all">All categories</option>
<t t-foreach="current_property_id.product_ids.mapped('categ_id')" t-as="categorie">
<option t-att-value="categorie.id">
<t t-esc="categorie.name"/>
</option>
</t>
</select>
<select name="product_seller" class="purchase_seller ml-2" t-att-data-purchase_request="purchase_request.id" t-att-data-property_id="current_property_id.id">
<select id="product_seller" name="product_seller" class="purchase_seller ml-2" t-att-data-purchase_request="purchase_request.id" t-att-data-property_id="current_property_id.id">
<option value="all">All sellers</option>
<t t-foreach="current_property_id.product_ids.seller_ids.filtered(lambda x: x.name in purchase_request.property_id.seller_ids).mapped('name')" t-as="seller">
<!-- <t t-foreach="current_property_id.product_ids.seller_ids.filtered(lambda x: x.name in purchase_request.property_id.seller_ids).mapped('name')" t-as="seller"> -->
<t t-foreach="current_property_id.seller_ids" t-as="seller">
<option t-att-value="seller.id">
<t t-esc="seller.name"/>
</option>
Expand Down Expand Up @@ -322,7 +323,7 @@
</td>
<td class="text-right">
<t t-if="product.mapped('seller_ids.name') and purchase_request.property_id.seller_ids">
<t t-foreach="product.seller_ids.filtered(lambda x: x.name in (purchase_request.property_id.seller_ids + purchase_request.property_id.seller_commercial_ids)).mapped('name')" t-as="seller">
<t t-foreach="product.seller_ids.filtered(lambda x: x.name in (purchase_request.property_id.seller_ids + purchase_request.property_id.seller_commercial_ids)).mapped('name')[0]" t-as="seller">
<t t-if="seller not in purchase_request.property_id.seller_ids">
<t t-set="seller_child" t-value="purchase_request.property_id.seller_ids.filtered(lambda x: x.commercial_partner_id == seller)"/>
<span class="ml-2">
Expand All @@ -338,7 +339,7 @@
<t t-esc="seller.phone"/>
</span>
</t>
<br t-if="seller.id != product.mapped('seller_ids.name')[-1].id" />
<br t-if="seller.id != product.mapped('seller_ids.name')[-1].id" />
<hr t-if="seller.id != product.mapped('seller_ids.name')[-1].id" />
</t>
</t>
Expand Down

0 comments on commit e7866f6

Please sign in to comment.