Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
4 Odpovědi
5108 Zobrazení

Hello Dear Odoers,

I need some help I have created a related field in my model 

location_dest_id = fields.Many2one('stock.location', string='To', domain="[('usage', '=', 'internal')]", required=True)

Currently it shows stock locations from the company assigned to a user, I want to show all records in stock location for user selection.

Please help.

Avatar
Zrušit
Autor Nejlepší odpověď

I have found a solution by changing the field from many2one to selection and computing selection records. with that, I can able to select stock location from other companies as well.

def _location_selection(self):
domain = [('usage', '=', 'internal')]
locations = self.env['stock.location'].sudo().search(domain)
return list(map(lambda location: (str(location.id), ', '.join([location.complete_name, location.company_id.name])), locations))
location_dest_id = fields.Selection(
selection=lambda self: self._location_selection(),
string="To",
help="Destination Stock Location.",
required=True
)


Avatar
Zrušit
Nejlepší odpověď

Hi, 

You can see following for this, it has complete explanation for company_dependent fields alongwith access restriction and python code:

https://youtu.be/GkNgc-fZO-I

Hope it helps,

Thanks

Avatar
Zrušit
Nejlepší odpověď

Hi,

Add "check_company=False" in your code

location_dest_id = fields.Many2one('stock.location', string='To', domain="[('usage', '=', 'internal')]", required=True, check_company=False)

Regards

Avatar
Zrušit
Autor

Hi,
Thanks for your response, I have added check_company=False no difference. user has to select both companies in order to get locations.
I want user to select location from B Company regardless of allowed company to the user.
I am using 13 CE.

Nejlepší odpověď

Hi, im trying understand your code. Can you tell me what is the purpose of the model that has field 'location_dest_id'?

That model has many-to-one relationship with model 'stock.location', right? So how does this relationship help with your object that is showing all records in stock location?

Avatar
Zrušit
Autor

Thanks for your response.
I have built inter warehouse stock transfer module. Which is working flawlessly, but there is a problem. In my case we are working with a multi-company environment.

Suppose
User A assigned to -> Company A
User B assigned to -> Company B
User C assigned to -> Company C

Stock.Location
WH/Stock1 | Company A
WH/Stock2 | Company B
WH/Stock3 | Company C

Now User A has logged in and open the form which contains mainy2one stock.location field
He can able to see in many2one selection WH/Stock1, Until unless I give him all the companies access, and he selects all companies he won't be able to see other locations.

I want him to able to see all locations in that particular many2one field all the available locations regardless of companies he is assigned.

Currently Odoo has a very ridiculous approach in terms of inter companies stock transfer, It didn't have branch management so we are using companies as branches. I have built this module inspired by the Microsoft Dynamics RMS stock transfer mechanism, which is way more easier to work, less prone to user mistakes, and highly flexible on reporting.

Hope you understand my pain :(

Related Posts Odpovědi Zobrazení Aktivita
5
čvn 20
5834
1
bře 16
12566
2
čvc 25
1754
3
čvc 25
2140
1
čvc 25
1472