Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie

Hi, I need to show only the types that have the warehouse of the user logged, in the stock summary (stock.picking.type)


Therefore I made an ir.actions.server that calls python code to filter and it works fine, showing only the expected types


ir.actions.server



Show own stock picking type


ir.actions.server
kanban
code
action = model.x_open_own_stock_picking_type()



Python function

@api.model
def x_open_own_stock_picking_type(self):
if not self.env.user.has_group('stock.group_stock_manager'):
records = self.env['stock.picking.type'].search([('warehouse_id', '=', self.env.user.property_warehouse_id.id)])
else:
records = self.env['stock.picking.type'].search([])

action = self.env['ir.actions.act_window']._for_xml_id('stock.stock_picking_type_action')

action['domain'] = [('id', 'in', records.ids)]

return action


Expected result





But when I reload the page from the browser, the domain does not work and it shows all again





Can someone help me please


Awatar
Odrzuć
Najlepsza odpowiedź

The issue you're encountering with the ir.actions.server not persisting its domain filter across page refreshes is a common one in Odoo. This is because ir.actions.server actions are typically executed once, not dynamically maintained on every page load.



  Instead of relying on an ir.actions.server for this filtering, consider using a custom Odoo view with a domain that dynamically reflects the logged-in user's warehouse. This ensures the filter is applied every time the view is rendered.

  To achieve this, modify your stock.picking.type view (likely a kanban or tree view) to include a domain that checks the warehouse_id against the current user's warehouse. This domain should be computed using a Python method on the model.

  This approach leverages Odoo's built-in view mechanisms for data filtering, providing a more efficient and reliable solution than repeatedly executing server actions. This will ensure the correct records are displayed consistently, even after page refreshes.


For personalized assistance:
https://www.pragtech.co.in/contact-us-mql.html

Awatar
Odrzuć
Najlepsza odpowiedź

Hi,

You can refer to this blog for auto-refresh kanban views:

https://www.cybrosys.com/blog/overview-of-real-time-kanban-boards-in-odoo-18-with-auto-updates


Hope it helps.

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
1
lis 23
6
2
sie 24
4423
2
sty 24
2195
1
lis 23
2414
5
paź 22
14112