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

Related field wrong value with multi-company

Subscribe

Get notified when there's activity on this post

This question has been flagged
relatedstock_moverelated_fieldsmulti-companyodoo12
1 Reply
4897 Views
Avatar
Aïmane

Hello, 

I am on odoo 12.

I have two companies and different quantities for the same product.

I have a custom model with a field related to the product qty_available 

qty_available = fields.Float(related='product_id.qty_available', string="Qté Disponible")

The problem is that I got the quantity of both company in my view.

I've tried this option :
qty_available = fields.Float(related='product_id.qty_available', string="Qté Disponible", company_dependent=True)
Nothing changes.
The closest I can get to the issue is in the module stock, product.py, def _get_domain_locations(self):
The instruction line 205 

Warehouse.search([]).ids
It returns current company locations and the other company locations. 

I know that there is something related to the context but I can't figure out what, there is something I am missing concerning multi company, your help would be very appreciated :)

Most of my knowledge is coming from this article: https://www.cybrosys.com/blog/how-to-handle-multi-company-odoo-custom-module 


For the moment I've got around the issue using compute attribute just like that, its working fine but I am not fully satisfied, I want to understand :) Thank you in advance

qty_available = fields.Float(string="Qté Disponible", store=False, readonly=True, compute='_compute_qty_available')

def _compute_qty_available(self):
for line in self:
 
  line.qty_available = line.product_id.qty_available
0
Avatar
Discard
Avatar
Begineer
Best Answer

Hi, 

I hope you want to show the quantity of the product related to your specified company , so try this,

def _compute_qty_available(self):

    for line in self:

        In your case you can go with, your currently logged in users company //

        line.qty_available = line.product_id.with_context(force_company = self.env.user.company_id.id).qty_available

                                                                                or         
        you can give your own defined company  //

        company_id = your_company_id

        line.qty_available = line.product_id.with_context(force_company = company_id.id).qty_available


For your info,

line.qty_available = line.product_id.with_context(lot_id=line.prodlot_id and line.prodlot_id.id or False, location=each.src_location_id.id).qty_available

       Here lot is used for tracking purpose , for tracking the product quantity in the specific lot and in specific location

       you may use this if your product has tracking options enabled.


Hope it helps,

Thanks

1
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
How update One2many records regarding to another one related to same modue
one2many multiple related related_fields odoo12
Avatar
0
Jun 19
4020
Can I stop calculating itself a related field if state != draft
related_fields odoo12
Avatar
0
Oct 20
2763
Related field not saving
v8 related related_fields
Avatar
Avatar
Avatar
2
Apr 24
9770
can we relate a field to a related field ? Solved
fields related related_fields
Avatar
1
Mar 15
4155
Could not edit origin field in stock move. What happen if no related object for related field is found?
stock_move related_fields fields_related
Avatar
Avatar
1
Mar 15
6450
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