Skip to Content
Menu
This question has been flagged

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
Avatar
Discard
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

Avatar
Discard
Related Posts Replies Views Activity
0
Jun 19
2431
0
Oct 20
1469
2
Apr 24
7627
1
Mar 15
2650
1
Mar 15
4894