Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • 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 Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & 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
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help

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

  • CRM
  • e-Commerce
  • Accounting
  • Inventory
  • PoS
  • Project
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

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

Subscribe

Get notified when there's activity on this post

This question has been flagged
codemany2onewidget
928 Views
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
Discard
Enjoying the discussion? Don't just read, join in!

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

Sign up
Related Posts Replies Views Activity
Odoo 10: How to filter on a Many2one field?
many2one widget
Avatar
Avatar
4
Sep 20
9722
Help with customizing Many2one dropdown background color in Odoo
javascript many2one widget
Avatar
0
Apr 25
1459
How to remove or disable search option in many2one widget in openerp 6.1?
many2one widget search options
Avatar
Avatar
Avatar
2
May 21
11270
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
4349
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة 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 is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

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