İçereği Atla
Menü
Bu soru işaretlendi
1 Cevapla
806 Görünümler

Hi peeps.
i have made an app that shows serial numbers in the portal based on logged in customer. On lot serial i have a field that the partner_id is set and this is how i show the serial numbers that belong to the logged in user. In the same time my serial numbers have conditions that come from stock.production.lot.condition and there the show_on_portal boolean determines the records with selected conditions to show.

So far so good, i have my search bar working like a charm. My issue is the defaults when the page opens. There for some reason i see the records that belong to the logged in user with all the conditions. 

Here is my controller:


from collections import OrderedDict


from odoo import http, _

from odoo.http import request

from odoo.osv.expression import OR, AND


from odoo.addons.portal.controllers.portal import CustomerPortal, pager as portal_pager



class ProductStatusCustomerPortal(CustomerPortal):


    def _prepare_home_portal_values(self, counters):

        values = super()._prepare_home_portal_values(counters)

        if 'product_status_count' in counters:

            Lots = request.env['stock.production.lot']

            condition_id = 1

            domain = Lots._product_status_get_portal_domain()

            values['product_status_count'] = Lots.sudo().search_count(domain)

        return values


    def _get_searchbar_inputs(self):

        return {

            'serial': {'input': 'serial', 'label': _('Search in Serial')},

            'product': {'input': 'product', 'label': _('Search in Parts')},

          # 'owner': {'input': 'owner', 'label': _('Search in Owner')},

          # 'part': {'input': 'part', 'label': _('Search in Part Number')},

            'condition': {'input': 'condition', 'label': _('Search in Condition')},

          # 'box': {'input': 'box', 'label': _('Search in Box number')},

          # 'location': {'input': 'location', 'label': _('Search in Location')},

            'all': {'input': 'all', 'label': _('Search in All')},

        }


    def _get_searchbar_groupby(self):

        return {

            'none': {'input': 'none', 'label': _('None')},

          # 'owner': {'input': 'owner', 'label': _('Owner')},

            'product': {'input': 'product', 'label': _('Product')},

            'condition': {'input': 'condition', 'label': _('Condition')},

        }


    def _get_search_domain(self, search_in, search, condition_ids=None):

        search_domain = []


        if search and search_in in ('serial', 'owner', 'part', 'condition', 'box', 'location', 'product', 'all'):

            if search_in == 'condition':

                if show_on_portal:

                    search_domain = [('condition_id.show_on_portal', '=', True), ('condition_id.name', 'ilike', search)]

                else:

                    search_domain = [('condition_id', 'ilike', search)]

            else:

                search_domain = [(search_in, 'ilike', search)]


        return search_domain



    def _get_groupby_mapping(self):

        return {

            'owner': 'partner_id',

            'product': 'product_id',

            'condition': 'condition_id',

        }


    def _get_searchbar_filters(self):

        res = {

            'all': {'label': _('All'), 'domain': self._get_search_domain('all', '')},

        }

        allowed_conditions = request.env['stock.production.lot.condition'].sudo().search([('show_on_portal', '=', True)])

        for condition in allowed_conditions:

            res[str(Washburn Computer Group

Avatar
Vazgeç
En İyi Yanıt

Hi,

You can modify the code like:

@http.route(['/my/product_status', '/my/product_status/page/'], type='http', auth="user", website=True)
def portal_my_product_status(self, page=1, sortby=None, filterby=None, search=None, search_in='all', groupby='none', **kw):
    Lots = request.env['stock.production.lot']
    domain = Lots._product_status_get_portal_domain()

    # Add condition to filter records by logged-in user
    domain += [('partner_id', '=', request.env.user.partner_id.id)]

    # Modify the rest of the code to handle search, filter, and group by as before
    ...
With this change, when the page is opened, it will display only the records of the first logged-in user. Then, the user can further filter or search as needed.


Hope it helps

Avatar
Vazgeç