/** @odoo-module */
import { registry } from "@web/core/registry";
import { listView } from "@web/views/list/list_view";
import { ListController } from "@web/views/list/list_controller";
import { ListRenderer } from "@web/views/list/list_renderer";
import { useService } from "@web/core/utils/hooks";
import { useState } from "@odoo/owl";
class SaleOrderListController extends ListController {
setup() {
super.setup();
this.orm = useService("orm");
this.searchFilters = {};
this.state=useState({ searchList:[],
uniqueNames:[]
})
this.busService = useService("bus_service");
this.busService.addEventListener("custom_event", this._onCustomEvent.bind(this));
this.busService.addEventListener("searching update", this._onSearchUpdate.bind(this));
}
async _onCustomEvent(event) {
const deta=event.detail.data
await this.model.load({ domain :deta ? [["partner_id","ilike",deta]] : [] })
}
async _onSearchUpdate(event) {
this.searchFilters = event.detail;
console.log("search=>", this.searchFilters);
let domain = [];
Object.keys(this.searchFilters).forEach(field => {
domain = domain.concat(this.searchFilters[field]);
});
await this.model.load({ domain });
this.showResult(domain);
}
async showResult(domain){
this.state.searchList = await this.orm.searchRead('sale.order',domain,['partner_id'])
this.state.uniqueNames = [...new Set(this.state.searchList.map(task => task.partner_id[1]))];
const names=Object.values(this.state.uniqueNames)
console.log("name=>",names)
}
}
class SaleOrderListRenderer extends ListRenderer {
static template = "owl.SaleOrderListView.render";
setup() {
super.setup();
this.orm = useService("orm");
this.busService = useService("bus_service");
this.passValue = this.passValue.bind(this);
this.records = [];
this.filters = {};
this.partnerTags = useState([]);
this.salespersonTags = useState([]);
this.searchList = useState([])
this.uniqueNames = useState([])
this.names = useState([])
this.toggle = true
this.events=""
}
async onSearchInput(event) {
const field = event.target.dataset.field;
const query = event.target.value.trim();
if (!field) return;
if (field == 'partner_id'){
this.toggle = true
this.events = event.target.value;
if(query == ""){
this.toggle = false
console.log("trigger")
this.render(true)
}
}
else{
this.toggle = false
}
if (field === "create_date_start" || field === "create_date_end") {
if (field === "create_date_start") {
this.startDate = query;
} else {
this.endDate = query;
}
if (this.startDate && this.endDate) {
this.filters["create_date"] = [["create_date", ">=", this.startDate], ["create_date", "<=", this.endDate]];
} else {
delete this.filters["create_date"];
}
await this.busService.trigger("searching update", this.filters);
return;
}
if (field === "state") {
if (query) {
this.filters[field] = [[field, "=", query]];
} else {
delete this.filters[field];
}
await this.busService.trigger("searching update", this.filters);
return;
}
if (field === "partner_id" || field === "user_id") {
if (event.inputType === "insertText" && event.data === " ") {
const values = query.split(/\s+/).filter(val => val);
if (values.length > 0) {
if (field === "partner_id" && !this.partnerTags.includes(values[0])) {
this.partnerTags.push(values[0]);
} else if (field === "user_id" && !this.salespersonTags.includes(values[0])) {
this.salespersonTags.push(values[0]);
}
event.target.value = "";
}
this.updateFilters();
return;
}
}
if (query) {
this.filters[field] = [[field, "ilike", query]];
} else {
delete this.filters[field];
}
this.showResult(this.filters)
await this.busService.trigger("searching update", this.filters);
}
removeTag(field, index) {
if (field === "partner_id") {
this.partnerTags.splice(index, 1);
} else if (field === "user_id") {
this.salespersonTags.splice(index, 1);
}
this.updateFilters();
}
updateFilters() {
let partnerConditions = this.partnerTags.map(tag => ["partner_id", "ilike", tag]);
// let salespersonConditions = this.salespersonTags.map(tag => ["user_id", "ilike", tag]);
console.log("Condition tags =>", partnerConditions);
if (partnerConditions.length > 1) {
// Ensure correct Odoo domain syntax
let combinedPartnerConditions = [];
for (let i = 0; i < partnerConditions.length; i++) {
if (i > 0) combinedPartnerConditions.unshift("|"); // Add "|" before every condition
combinedPartnerConditions.push(partnerConditions[i]);
}
this.filters["partner_id"] = combinedPartnerConditions;
} else if (partnerConditions.length === 1) {
this.filters["partner_id"] = [partnerConditions[0]];
} else {
delete this.filters["partner_id"];
}
// if (salespersonConditions.length > 1) {
// let combinedSalespersonConditions = [];
// for (let i = 0; i < salespersonConditions.length; i++) {
// if (i > 0) combinedSalespersonConditions.unshift("|");
// combinedSalespersonConditions.push(salespersonConditions[i]); /// in that section problem is when user search in partner_id then partner_id changed by user_id fix it letter
// }
//// this.filters["user_id"] = combinedSalespersonConditions;
// } else {
//// this.filters["user_id"] = salespersonConditions;
// }
this.busService.trigger("searching update", this.filters);
}
async showResult(filters){
let domain = [];
Object.keys(filters).forEach(field => {
domain = domain.concat(filters[field]);
});
console.log("here is from in=>",Object.keys(filters)[0])
if(Object.keys(filters)[0]=='partner_id'){
this.searchList = await this.orm.searchRead('sale.order',domain,['partner_id'])
this.uniqueNames = [...new Set(this.searchList.map(task => task.partner_id[1]))];
this.names=Object.values(this.uniqueNames)
this.render(true)
}
}
passValue(event) {
if (!this.partnerTags.includes(event)) {
this.partnerTags.push(event);
}
this.events = "";
this.toggle = false;
this.updateFilters();
this.render(true);
}
}
export const SaleOrderListView = {
...listView,
Controller: SaleOrderListController,
Renderer: SaleOrderListRenderer,
};
registry.category("views").add("sale_order_list_search", SaleOrderListView);
this is right code which is written in odoo16 but now problem is in odoo17 when i migrate that in odoo17 its return error because of useService("bus_service") its not work in odoo17 please give me solution how can i use bus_service
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Kế toán
- Tồn kho
- PoS
- Project
- MRP
Câu hỏi này đã bị gắn cờ
2
Trả lời
1966
Lượt xem
Thank you for your support!
i already solve it
Hi Kishan Toliya,
You can access the bus service from the environment like this:
setup() {
this.busService = this.env.services.bus_service;
}
Hope this helps
Bạn có hứng thú với cuộc thảo luận không? Đừng chỉ đọc, hãy tham gia nhé!
Tạo tài khoản ngay hôm nay để tận hưởng các tính năng độc đáo và tham gia cộng đồng tuyệt vời của chúng tôi!
Đăng kýBài viết liên quan | Trả lời | Lượt xem | Hoạt động | |
---|---|---|---|---|
|
1
thg 8 24
|
3541 | ||
|
3
thg 8 25
|
980 | ||
|
0
thg 3 25
|
1116 | ||
|
1
thg 8 24
|
3113 | ||
|
1
thg 7 24
|
2225 |