Skip to Content
Odoo Menu
  • Prihlásiť sa
  • Vyskúšajte zadarmo
  • Aplikácie
    Financie
    • Účtovníctvo
    • Fakturácia
    • Výdavky
    • Tabuľka (BI)
    • Dokumenty
    • Podpis
    Predaj
    • CRM
    • Predaj
    • POS Shop
    • POS Restaurant
    • Manažment odberu
    • Požičovňa
    Webstránky
    • Tvorca webstránok
    • eShop
    • Blog
    • Fórum
    • Živý chat
    • eLearning
    Supply Chain
    • Sklad
    • Výroba
    • Správa životného cyklu produktu
    • Nákup
    • Údržba
    • Manažment kvality
    Ľudské zdroje
    • Zamestnanci
    • Nábor zamestnancov
    • Voľné dni
    • Hodnotenia
    • Odporúčania
    • Vozový park
    Marketing
    • Marketing sociálnych sietí
    • Email marketing
    • SMS marketing
    • Eventy
    • Marketingová automatizácia
    • Prieskumy
    Služby
    • Projektové riadenie
    • Pracovné výkazy
    • Práca v teréne
    • Helpdesk
    • Plánovanie
    • Schôdzky
    Produktivita
    • Tímová komunikácia
    • Schvalovania
    • IoT
    • VoIP
    • Znalosti
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Managament
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Výroba
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware and Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Komunita
    Vzdelávanie
    • Tutoriály
    • Dokumentácia
    • Certifikácie
    • Školenie
    • Blog
    • Podcast
    Empower Education
    • Vzdelávací program
    • Scale Up! Business Game
    • Visit Odoo
    Softvér
    • Stiahnuť
    • Porovnanie Community a Enterprise vierzie
    • Releases
    Spolupráca
    • Github
    • Fórum
    • Eventy
    • Preklady
    • Staň sa partnerom
    • Services for Partners
    • Register your Accounting Firm
    Služby
    • Nájdite partnera
    • Nájdite účtovníka
    • Meet an advisor
    • Implementation Services
    • Zákaznícke referencie
    • Podpora
    • Upgrades
    ​Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Získajte demo
  • Cenník
  • Help

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Účtovníctvo
  • Sklady
  • PoS
  • Projektové riadenie
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tagy (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tagy (View all)
odoo accounting v14 pos v15
About this forum
Pomoc

odoo v18, Odoo Many2XAutocomplete Problem: Unable to Retrieve Current Line ID, Only Line Records When Updating Purchase Requisition Lines via RPC

Odoberať

Get notified when there's activity on this post

This question has been flagged
codemany2onewidget
919 Zobrazenia
Avatar
vlad

I’m customizing purchase requisition lines in Odoo, using a Many2XAutocomplete widget for selecting product templates. After selecting a template, a product configurator dialog opens where I pick a variant. Once selected, I want the product field in the exact line the user is editing to autocomplete with the chosen product variant.

The problem:

Many2XAutocomplete only gives me a list of line record IDs or a general record context, but not the exact current line ID being edited. Without knowing this current line ID, I cannot properly update that line with the selected product variant.

I’ve tried accessing this.env.model and this.env.model.root, but neither reliably provides the precise line ID for the current autocomplete widget instance.

Does anyone know:

  • How to get the exact line ID from within Many2XAutocomplete when a selection is made?
  • Or, an alternative approach to reliably identify and update the line that triggered the product template selection and configurator?

This is crucial because without the line ID, I can’t correctly set the product variant on the intended line, breaking the expected user flow.

Thanks in advance for any guidance or examples!

Here you can see my code :

import { patch } from "@web/core/utils/patch";

import { ProductConfiguratorDialog } from "@sale/js/product_configurator_dialog/product_configurator_dialog";

import { Many2XAutocomplete } from "@web/views/fields/relational_utils";

import { rpc } from "@web/core/network/rpc";

import { useInputField } from "@web/views/fields/input_field_hook";



const originalOnSelect = Many2XAutocomplete.prototype.onSelect;


patch(Many2XAutocomplete.prototype, {

    async onSelect(option, params = {}) {

        if (this.props.resModel === "product.template" && option?.value) {

            const dialog = this.env.services.dialog;

            const env = this.env;


            try {

                const result = await rpc("/my_product_configurator/get_values", {

                    product_template_id: option.value,

                    currency_id: 1,

                    so_date: new Date().toISOString(),

                });


                await dialog.add(ProductConfiguratorDialog, {

                    productTemplateId: result.product_template_id,

                    quantity: 1.0,

                    ptavIds: [],

                    customPtavs: [],

                    soDate: result.so_date,

                    productUOMId: 1,

                    companyId: 1,

                    pricelistId: 1,

                    currencyId: result.currency_id,

                    options: result.options,


                    discard: () => console.log("Discard clicked"),


                    save: async (mainProduct) => {

                        const record = this.env.model.root;


                        if (!record.resId) {

                            await record.save();

                        }


                        const requisitionId = record.resId;

                        if (!requisitionId) {

                            console.error("Missing requisition ID even after save.");

                            return;

                        }


                        const ptavIds = (mainProduct.attribute_lines || []).flatMap(

                            line => line.selected_attribute_value_ids || []

                        );


                        const templateIds = [mainProduct.product_tmpl_id];

                        const lineIds = env.model.root._values.line_ids.currentIds


                        try {

                            const response = await rpc("/my_product_configurator/set_variants_for_lines", {

                                ptav_ids: ptavIds,

                                template_ids: templateIds,

                                requisition_id: requisitionId,

                                line_ids: lineIds

                            });


                            if (response?.status === "ok") {

                                console.log("Created requisition lines:", response.created_line_ids);

                            } else {

                                console.error("Error from controller:", response?.error || "Unknown error");

                            }

                        } catch (rpcError) {

                            console.error("RPC Error:", rpcError);

                        }


                       await this.env.model.root.load();


                        if (this.env.model.root.model.root) {

                            await this.env.model.root.model.root.load();  

                        }



                    },  


                    close: () => console.log("Dialog closed"),

                });


            } catch (dialogError) {

                console.error("Dialog setup failed:", dialogError);

            }

        }


        return await originalOnSelect.call(this, option, params);

    },

});






0
Avatar
Zrušiť
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Registrácia
Related Posts Replies Zobrazenia Aktivita
Odoo 10: How to filter on a Many2one field?
many2one widget
Avatar
Avatar
4
sep 20
9716
Help with customizing Many2one dropdown background color in Odoo
javascript many2one widget
Avatar
0
apr 25
1458
How to remove or disable search option in many2one widget in openerp 6.1?
many2one widget search options
Avatar
Avatar
Avatar
2
máj 21
11260
How to add line of One2many field related child record with another parent record.
code many2one one2many customization
Avatar
0
apr 21
6
Odoo mobile framework V2 - many2one field selection widget
many2one widget selection mobile
Avatar
0
feb 19
4341
Komunita
  • Tutoriály
  • Dokumentácia
  • Fórum
Open Source
  • Stiahnuť
  • Github
  • Runbot
  • Preklady
Služby
  • Odoo.sh hosting
  • Podpora
  • Vyššia verzia
  • Custom Developments
  • Vzdelávanie
  • Nájdite účtovníka
  • Nájdite partnera
  • Staň sa partnerom
O nás
  • Naša spoločnosť
  • Majetok značky
  • Kontaktujte nás
  • Pracovné ponuky
  • Eventy
  • Podcast
  • Blog
  • Zákazníci
  • Právne dokumenty • Súkromie
  • Bezpečnosť
الْعَرَبيّة 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 je sada podnikových aplikácií s otvoreným zdrojovým kódom, ktoré pokrývajú všetky potreby vašej spoločnosti: CRM, e-shop, účtovníctvo, skladové hospodárstvo, miesto predaja, projektový manažment atď.

Odoo prináša vysokú pridanú hodnotu v jednoduchom použití a súčasne plne integrovanými biznis aplikáciami.

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