Bỏ qua để đến Nội dung
Odoo Menu
  • Đăng nhập
  • Dùng thử miễn phí
  • Ứng dụng
    Tài chính
    • Kế toán
    • Hóa đơn
    • Chi phí
    • Bảng tính (BI)
    • Tài liệu
    • Ký tên
    Bán hàng
    • CRM
    • Bán hàng
    • POS Cửa hàng
    • POS Nhà hàng
    • Đăng ký
    • Cho thuê
    Trang web
    • Trình tạo trang web
    • Thương mại điện tử
    • Blog
    • Diễn đàn
    • Trò chuyện trực tiếp
    • Học trực tuyến
    Chuỗi cung ứng
    • Tồn kho
    • Sản xuất
    • PLM
    • Mua hàng
    • Bảo dưỡng
    • Chất lượng
    Nhân sự
    • Nhân viên
    • Tuyển dụng
    • Ngày nghỉ
    • Đánh giá
    • Giới thiệu
    • Đội xe
    Marketing
    • Marketing trên MXH
    • Marketing qua email
    • Marketing qua SMS
    • Sự kiện
    • Tự động hóa Marketing
    • Khảo sát
    Dịch vụ
    • Dự án
    • Bảng chấm công
    • Dịch vụ hiện trường
    • Hỗ trợ
    • Kế hoạch
    • Lịch hẹn
    Năng suất
    • Thảo luận
    • Phê duyệt
    • IoT
    • VoIP
    • Kiến thức
    • WhatsApp
    Ứng dụng của bên thứ ba Studio Odoo Nền tảng Đám mây Odoo
  • Ngành
    Bán lẻ
    • Nhà sách
    • Cửa hàng quần áo
    • Cửa hàng nội thất
    • Cửa hàng tạp hóa
    • Cửa hàng đồ kim khí
    • Cửa hàng đồ chơi
    Ẩm thực & Dịch vụ lưu trú
    • Bar và quán rượu
    • Nhà hàng
    • Đồ ăn nhanh
    • Guest house
    • Nhà phân phối đồ uống
    • Khách sạn
    Bất động sản
    • Công ty môi giới bất động sản
    • Công ty kiến trúc
    • Xây dựng
    • Quản lý bất động sản
    • Làm vườn
    • Hiệp hội chủ sở hữu bất động sản
    Tư vấn
    • Công ty kế toán
    • Đối tác Odoo
    • Công ty marketing
    • Công ty luật
    • Tuyển dụng
    • Thanh tra & chứng nhận
    Sản xuất
    • Dệt may
    • Kim loại
    • Nội thất
    • Ẩm thực
    • Nhà máy bia
    • Quà tặng doanh nghiệp
    Sức khoẻ & fitness
    • CLB thể thao
    • Cửa hàng kính mắt
    • Trung tâm fitness
    • Chuyên gia chăm sóc sức khỏe
    • Hiệu thuốc
    • Tiệm làm tóc
    Thương mại
    • Dịch vụ sửa chữa
    • Phần cứng CNTT & Hỗ trợ
    • Hệ thống năng lượng mặt trời
    • Công ty sản xuất giày
    • Dịch vụ vệ sinh
    • Dịch vụ HVAC
    Khác
    • Tổ chức phi lợi nhuận
    • Cơ quan môi trường
    • Cho thuê biển quảng cáo
    • Nhiếp ảnh
    • Cho thuê xe đạp
    • Đại lý phần mềm
    Xem tất cả ngành
  • Cộng đồng
    Học tập
    • Khóa học
    • Tài liệu
    • Chứng chỉ
    • Đào tạo
    • Blog
    • Podcast
    Thúc đẩy đào tạo
    • Chương trình đào tạo
    • Trò chơi kinh doanh Scale Up!
    • Tham quan Odoo
    Nhận phần mềm
    • Tải xuống
    • So sánh các phiên bản
    • Phiên bản
    Hợp tác
    • Github
    • Diễn đàn
    • Sự kiện
    • Dịch thuật
    • Trở thành đối tác
    • Dịch vụ dành cho Đối tác
    • Đăng ký công ty kế toán của bạn
    Nhận dịch vụ
    • Tìm đối tác
    • Tìm kế toán
    • Gặp chuyên gia hỗ trợ
    • Dịch vụ Triển khai
    • Khách hàng tham khảo
    • Hỗ trợ
    • Nâng cấp
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Nhận một buổi demo
  • Bảng giá
  • Trợ giúp

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
  • Dự án
  • MRP
All apps
Bạn cần phải đăng ký để tương tác với cộng đồng.
Tất cả bài viết Người Huy hiệu
Thẻ (Xem tất cả)
odoo accounting v14 pos v15
Về diễn đàn này
Bạn cần phải đăng ký để tương tác với cộng đồng.
Tất cả bài viết Người Huy hiệu
Thẻ (Xem tất cả)
odoo accounting v14 pos v15
Về diễn đàn này
Hỗ trợ

How to Load Related Many2Many Data (pos.ticket.type) into the Frontend?

Đăng ký nhận tin

Nhận thông báo khi có hoạt động trên bài viết này

Câu hỏi này đã bị gắn cờ
javascriptdevelopment
1831 Lượt xem
Ảnh đại diện
Samar Guicha

Hello Odoo Community,

I'm developing a custom module for the Odoo Point of Sale (POS) and have encountered a persistent issue with data loading for a custom Many2Many field, preventing me from displaying the correct information in a custom popup.

My Goal: I'm implementing a new payment method type for "Tickets Restaurant" (or similar vouchers). Each such payment method needs to be associated with specific pos.ticket.type records, which define properties like a name and discount_rate. When a user selects one of these ticket payment methods in the POS, I intend to open a custom popup (ManageTicketRestaurantPopup). This popup should then display a list of the actual names and discount rates of the pos.ticket.type records that are linked to the selected payment method.

Any guidance or common pitfalls I might be overlooking would be greatly appreciated! Thank you!

My Current Setup (Odoo 18):

Here's a simplified view of my relevant models and JavaScript:

  1. pos.ticket.type Model (Python): This model defines the structure for my ticket types. Python
    # your_module_name/models/pos_ticket_type.py
    from odoo import models, fields
    
    class PosTicketType(models.Model):
        _name = 'pos.ticket.type'
        _description = 'Type de Ticket'
    
        name = fields.Char(required=True)
        discount_rate = fields.Float(string="Taux de retenue (%)", required=True)
    
  2. pos.payment.method Model (Python - Inherited): I've added a boolean flag and a Many2Many field to link to the ticket types. I've also extended _load_pos_data_fields to ensure these fields are loaded for the payment method itself. Python
    # your_module_name/models/pos_payment_method.py
    from odoo import models, fields, api
    
    class PosPaymentMethod(models.Model):
        _inherit = 'pos.payment.method'
    
        is_ticket_payment = fields.Boolean(string="Mode de paiement par ticket ?", default=False)
        allowed_ticket_type_ids = fields.Many2many('pos.ticket.type', string="Types de tickets autorisés")
    
        @api.model
        def _load_pos_data_fields(self, config_id):
            res = super()._load_pos_data_fields(config_id)
            res += ['is_ticket_payment', 'allowed_ticket_type_ids']
            return res
    
  3. pos.config Model (Python - Loading related data): To make the full pos.ticket.type records available in the frontend, I've extended _get_pos_ui_res_config. Python
    # your_module_name/models/pos_config.py
    from odoo import models, fields, api
    
    class PosConfig(models.Model):
        _inherit = 'pos.config'
    
        @api.model
        def _get_pos_ui_res_config(self, config):
            result = super()._get_pos_ui_res_config(config)
            ticket_types_data = self.env['pos.ticket.type'].search_read([], ['id', 'name', 'discount_rate'])
            result['pos_ticket_types'] = ticket_types_data
            return result
    
  4. payment_screen_patch.js (JavaScript Frontend): This is where I try to access the data and pass it to my custom popup. JavaScript
    // your_module_name/static/src/js/payment_screen_patch.js
    /** @odoo-module **/
    import { _t } from "@web/core/l10n/translation";
    import { patch } from "@web/core/utils/patch";
    import { PaymentScreen } from "@point_of_sale/app/screens/payment_screen/payment_screen";
    import { ManageTicketRestaurantPopup } from "@pos_ticket_voucher/js/ticket_restaurant_popup"; // Ensure this path is correct
    import { useService } from "@web/core/utils/hooks";
    
    patch(PaymentScreen.prototype, {
        setup() {
            super.setup(...arguments);
            this.dialog = useService("dialog");
            this.pos = useService("pos"); // Access the pos service
        },
    
        async addNewPaymentLine(payment_method) {
            await super.addNewPaymentLine(payment_method);
    
            if (payment_method.is_ticket_payment) {
                // This line is where the problem occurs for me.
                // I expect full voucher types, but I get just IDs or an empty array when trying to map.
                const allowedTicketTypeIds = payment_method.allowed_ticket_type_ids || [];
    
                // Access the loaded pos_ticket_types data from this.pos
                const allPosTicketTypes = this.pos.pos_ticket_types; // This seems to contain full records
    
                // Attempt to map IDs to full objects
                const ticketTypes = allowedTicketTypeIds.map(id =>
                    allPosTicketTypes.find(ticketType => ticketType.id === id)
                ).filter(Boolean);
    
                console.log("Allowed Ticket Type IDs (from payment_method):", allowedTicketTypeIds);
                console.log("All loaded POS Ticket Types (from this.pos):", allPosTicketTypes);
                console.log("Filtered Ticket Types for Popup (EXPECTING FULL OBJECTS):", ticketTypes);
    
                const { payload } = await this.dialog.add(ManageTicketRestaurantPopup, {
                    title: _t("Tickets Restaurant"),
                    ticketTypes: ticketTypes, // This `ticketTypes` array is empty or contains wrong data
                    getPayload: (tickets) => {
                        const total = tickets.reduce((sum, t) => sum + parseFloat(t.discounted), 0);
                        const paymentline = this.currentOrder.selected_paymentline;
                        if (paymentline) {
                            paymentline.set_amount(total);
                            paymentline.ticket_data = tickets; // for later use
                        }
                    },
                    close: () => {},
                });
    
                // (Optional code to remove payment line if popup is cancelled)
                // if (!payload || !payload.length) {
                //     this.currentOrder.remove_paymentline(this.currentOrder.selected_paymentline);
                // }
            }
        }
    }); 
0
Ảnh đại diện
Huỷ bỏ
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
How can I use my only web url domain using odoo?
javascript development
Ảnh đại diện
Ảnh đại diện
1
thg 9 25
1523
Odoo 18 POS - Discount Button Group Permissions Not Working
javascript development
Ảnh đại diện
Ảnh đại diện
2
thg 6 25
1994
¿Cómo puedo crear un Dashboard con KPIs y gráficos con Chart.js?
javascript development
Ảnh đại diện
0
thg 4 25
1957
Odoo icon change Đã xử lý
javascript development
Ảnh đại diện
Ảnh đại diện
2
thg 1 25
2507
How to get the Model name and Action of the Current page? v7 Đã xử lý
javascript development
Ảnh đại diện
Ảnh đại diện
Ảnh đại diện
2
thg 2 24
13716
Cộng đồng
  • Khóa học
  • Tài liệu
  • Diễn đàn
Open source
  • Tải xuống
  • Github
  • Runbot
  • Dịch thuật
Dịch vụ
  • Lưu trữ Odoo.sh
  • Hỗ trợ
  • Nâng cấp
  • Phát triển tùy chỉnh
  • Đào tạo
  • Tìm kế toán
  • Tìm đối tác
  • Trở thành đối tác
Giới thiệu công ty
  • Công ty của chúng tôi
  • Tài sản thương hiệu
  • Liên hệ
  • Việc làm
  • Sự kiện
  • Podcast
  • Blog
  • Khách hàng
  • Pháp lý • Riêng tư
  • Bảo mật
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo là bộ ứng dụng kinh doanh có open source đáp ứng tất cả các nhu cầu của công ty bạn: CRM, thương mại điện tử, kế toán, tồn kho, POS, quản lý dự án, v.v.

Định hướng giá trị riêng biệt của Odoo là tích hợp hoàn toàn và dễ dàng sử dụng.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now