Example #1
0
    def portal_my_requet(self,
                         page=1,
                         date_begin=None,
                         date_end=None,
                         sortby=None,
                         **kw):
        values = self._prepare_portal_layout_values()
        ReturnRequest = request.env['rma.request']
        domain = [
            ('state', 'in',
             ['draft', 'confirmed', 'rma_created', 'replacement_created'])
        ]
        request_count = ReturnRequest.search_count(domain)
        pager = portal_pager(url="/my/request",
                             url_args={},
                             total=request_count,
                             page=page,
                             step=self._items_per_page)
        # content according to pager and archive selected
        requests = ReturnRequest.sudo().search(domain,
                                               limit=self._items_per_page,
                                               offset=pager['offset'])
        request.session['my_requests_history'] = requests.ids[:100]

        values.update({
            'date': date_begin,
            'requests': requests.sudo(),
            'page_name': 'return_request',
            'pager': pager,
            'archive_groups': '',
            'default_url': '/my/request',
            'searchbar_sortings': '',
            'sortby': sortby,
        })
        return request.render("website_rma.portal_my_requests", values)
Example #2
0
    def portal_my_quotes(self, page=1, date_begin=None, date_end=None, sortby=None, **kw):
        values = self._prepare_portal_layout_values()
        partner = request.env.user.partner_id
        SaleOrder = request.env['sale.order']

        domain = [
            ('message_partner_ids', 'child_of', [partner.commercial_partner_id.id]),
            ('state', 'in', ['sent', 'cancel'])
        ]

        searchbar_sortings = {
            'date': {'label': _('Order Date'), 'order': 'date_order desc'},
            'name': {'label': _('Reference'), 'order': 'name'},
            'stage': {'label': _('Stage'), 'order': 'state'},
        }

        # default sortby order
        if not sortby:
            sortby = 'date'
        sort_order = searchbar_sortings[sortby]['order']

        archive_groups = self._get_archive_groups('sale.order', domain)
        if date_begin and date_end:
            domain += [('create_date', '>', date_begin), ('create_date', '<=', date_end)]

        # count for pager
        quotation_count = SaleOrder.search_count(domain)
        # make pager
        pager = portal_pager(
            url="/my/quotes",
            url_args={'date_begin': date_begin, 'date_end': date_end, 'sortby': sortby},
            total=quotation_count,
            page=page,
            step=self._items_per_page
        )
        # search the count to display, according to the pager data
        quotations = SaleOrder.search(domain, order=sort_order, limit=self._items_per_page, offset=pager['offset'])
        request.session['my_quotes_history'] = quotations.ids[:100]

        values.update({
            'date': date_begin,
            'quotations': quotations.sudo(),
            'page_name': 'quote',
            'pager': pager,
            'archive_groups': archive_groups,
            'default_url': '/my/quotes',
            'searchbar_sortings': searchbar_sortings,
            'sortby': sortby,
        })
        return request.render("sale.portal_my_quotations", values)
Example #3
0
    def pages_management(self, page=1, sortby='name', search='', **kw):
        # only website_designer should access the page Management
        if not request.env.user.has_group('website.group_website_designer'):
            raise werkzeug.exceptions.NotFound()

        Page = request.env['website.page']
        searchbar_sortings = {
            'url': {'label': _('Sort by Url'), 'order': 'url'},
            'name': {'label': _('Sort by Name'), 'order': 'name'},
        }
        # default sortby order
        sort_order = searchbar_sortings.get(sortby, 'name')['order']

        domain = ['|', ('website_ids', 'in', request.website.id), ('website_ids', '=', False)]
        if search:
            domain += ['|', ('name', 'ilike', search), ('url', 'ilike', search)]

        pages_count = Page.search_count(domain)

        pager = portal_pager(
            url="/website/pages",
            url_args={'sortby': sortby},
            total=pages_count,
            page=page,
            step=50
        )
        pages = Page.search(domain, order=sort_order, limit=50, offset=pager['offset'])

        values = {
            'pager': pager,
            'pages': pages,
            'search': search,
            'sortby': sortby,
            'searchbar_sortings': searchbar_sortings,
        }
        return request.render("website.edit_website_pages", values)
Example #4
0
    def portal_my_invoices(self,
                           page=1,
                           date_begin=None,
                           date_end=None,
                           sortby=None,
                           **kw):
        values = self._prepare_portal_layout_values()
        partner = request.env.user.partner_id
        AccountInvoice = request.env['account.invoice']

        domain = self._get_account_invoice_domain()

        searchbar_sortings = {
            'date': {
                'label': _('Invoice Date'),
                'order': 'date_invoice desc'
            },
            'duedate': {
                'label': _('Due Date'),
                'order': 'date_due desc'
            },
            'name': {
                'label': _('Reference'),
                'order': 'name desc'
            },
            'state': {
                'label': _('Status'),
                'order': 'state'
            },
        }
        # default sort by order
        if not sortby:
            sortby = 'date'
        order = searchbar_sortings[sortby]['order']

        archive_groups = self._get_archive_groups('account.invoice', domain)
        if date_begin and date_end:
            domain += [('create_date', '>', date_begin),
                       ('create_date', '<=', date_end)]

        # count for pager
        invoice_count = AccountInvoice.search_count(domain)
        # pager
        pager = portal_pager(url="/my/invoices",
                             url_args={
                                 'date_begin': date_begin,
                                 'date_end': date_end,
                                 'sortby': sortby
                             },
                             total=invoice_count,
                             page=page,
                             step=self._items_per_page)
        # content according to pager and archive selected
        invoices = AccountInvoice.search(domain,
                                         order=order,
                                         limit=self._items_per_page,
                                         offset=pager['offset'])
        values.update({
            'date': date_begin,
            'invoices': invoices,
            'page_name': 'invoice',
            'pager': pager,
            'archive_groups': archive_groups,
            'default_url': '/my/invoices',
            'searchbar_sortings': searchbar_sortings,
            'sortby': sortby,
        })
        return request.render("account.portal_my_invoices", values)
Example #5
0
    def portal_my_projects(self,
                           page=1,
                           date_begin=None,
                           date_end=None,
                           sortby=None,
                           **kw):
        values = self._prepare_portal_layout_values()
        Project = request.env['project.project']
        domain = [('privacy_visibility', '=', 'portal')]

        searchbar_sortings = {
            'date': {
                'label': _('Newest'),
                'order': 'create_date desc'
            },
            'name': {
                'label': _('Name'),
                'order': 'name'
            },
        }
        if not sortby:
            sortby = 'date'
        order = searchbar_sortings[sortby]['order']

        # archive groups - Default Group By 'create_date'
        archive_groups = self._get_archive_groups('project.project', domain)
        if date_begin and date_end:
            domain += [('create_date', '>', date_begin),
                       ('create_date', '<=', date_end)]
        # projects count
        project_count = Project.search_count(domain)
        # pager
        pager = portal_pager(url="/my/projects",
                             url_args={
                                 'date_begin': date_begin,
                                 'date_end': date_end,
                                 'sortby': sortby
                             },
                             total=project_count,
                             page=page,
                             step=self._items_per_page)

        # content according to pager and archive selected
        projects = Project.search(domain,
                                  order=order,
                                  limit=self._items_per_page,
                                  offset=pager['offset'])
        request.session['my_projects_history'] = projects.ids[:100]

        values.update({
            'date': date_begin,
            'date_end': date_end,
            'projects': projects,
            'page_name': 'project',
            'archive_groups': archive_groups,
            'default_url': '/my/projects',
            'pager': pager,
            'searchbar_sortings': searchbar_sortings,
            'sortby': sortby
        })
        return request.render("project.portal_my_projects", values)
Example #6
0
    def portal_my_tasks(self,
                        page=1,
                        date_begin=None,
                        date_end=None,
                        sortby=None,
                        filterby=None,
                        search=None,
                        search_in='content',
                        **kw):
        values = self._prepare_portal_layout_values()
        searchbar_sortings = {
            'date': {
                'label': _('Newest'),
                'order': 'create_date desc'
            },
            'name': {
                'label': _('Title'),
                'order': 'name'
            },
            'stage': {
                'label': _('Stage'),
                'order': 'stage_id'
            },
            'update': {
                'label': _('Last Stage Update'),
                'order': 'date_last_stage_update desc'
            },
        }
        searchbar_filters = {
            'all': {
                'label': _('All'),
                'domain': []
            },
        }
        searchbar_inputs = {
            'content': {
                'input': 'content',
                'label': _('Search <span class="nolabel"> (in Content)</span>')
            },
            'message': {
                'input': 'message',
                'label': _('Search in Messages')
            },
            'customer': {
                'input': 'customer',
                'label': _('Search in Customer')
            },
            'stage': {
                'input': 'stage',
                'label': _('Search in Stages')
            },
            'all': {
                'input': 'all',
                'label': _('Search in All')
            },
        }
        # extends filterby criteria with project (criteria name is the project id)
        # Note: portal users can't view projects they don't follow
        projects = request.env['project.project'].sudo().search([
            ('privacy_visibility', '=', 'portal')
        ])
        domain = [('project_id', 'in', projects.ids)]
        for proj in projects:
            searchbar_filters.update({
                str(proj.id): {
                    'label': proj.name,
                    'domain': [('project_id', '=', proj.id)]
                }
            })

        # default sort by value
        if not sortby:
            sortby = 'date'
        order = searchbar_sortings[sortby]['order']
        # default filter by value
        if not filterby:
            filterby = 'all'
        domain += searchbar_filters[filterby]['domain']

        # archive groups - Default Group By 'create_date'
        archive_groups = self._get_archive_groups('project.task', domain)
        if date_begin and date_end:
            domain += [('create_date', '>', date_begin),
                       ('create_date', '<=', date_end)]

        # search
        if search and search_in:
            search_domain = []
            if search_in in ('content', 'all'):
                search_domain = OR([
                    search_domain,
                    [
                        '|', ('name', 'ilike', search),
                        ('description', 'ilike', search)
                    ]
                ])
            if search_in in ('customer', 'all'):
                search_domain = OR(
                    [search_domain, [('partner_id', 'ilike', search)]])
            if search_in in ('message', 'all'):
                search_domain = OR(
                    [search_domain, [('message_ids.body', 'ilike', search)]])
            if search_in in ('stage', 'all'):
                search_domain = OR(
                    [search_domain, [('stage_id', 'ilike', search)]])
            domain += search_domain

        # task count
        task_count = request.env['project.task'].search_count(domain)
        # pager
        pager = portal_pager(url="/my/tasks",
                             url_args={
                                 'date_begin': date_begin,
                                 'date_end': date_end,
                                 'sortby': sortby,
                                 'filterby': filterby
                             },
                             total=task_count,
                             page=page,
                             step=self._items_per_page)
        # content according to pager and archive selected
        tasks = request.env['project.task'].search(domain,
                                                   order=order,
                                                   limit=self._items_per_page,
                                                   offset=pager['offset'])
        request.session['my_tasks_history'] = tasks.ids[:100]

        values.update({
            'date':
            date_begin,
            'date_end':
            date_end,
            'projects':
            projects,
            'tasks':
            tasks,
            'page_name':
            'task',
            'archive_groups':
            archive_groups,
            'default_url':
            '/my/tasks',
            'pager':
            pager,
            'searchbar_sortings':
            searchbar_sortings,
            'searchbar_inputs':
            searchbar_inputs,
            'search_in':
            search_in,
            'sortby':
            sortby,
            'searchbar_filters':
            OrderedDict(sorted(searchbar_filters.items())),
            'filterby':
            filterby,
        })
        return request.render("project.portal_my_tasks", values)
Example #7
0
    def portal_my_purchase_orders(self,
                                  page=1,
                                  date_begin=None,
                                  date_end=None,
                                  sortby=None,
                                  filterby=None,
                                  **kw):
        values = self._prepare_portal_layout_values()
        partner = request.env.user.partner_id
        PurchaseOrder = request.env['purchase.order']

        domain = [
            '|',
            ('message_partner_ids', 'child_of',
             [partner.commercial_partner_id.id]),
            ('partner_id', 'child_of', [partner.commercial_partner_id.id]),
        ]

        archive_groups = self._get_archive_groups('purchase.order', domain)
        if date_begin and date_end:
            domain += [('create_date', '>', date_begin),
                       ('create_date', '<=', date_end)]

        searchbar_sortings = {
            'date': {
                'label': _('Newest'),
                'order': 'create_date desc, id desc'
            },
            'name': {
                'label': _('Name'),
                'order': 'name asc, id asc'
            },
            'amount_total': {
                'label': _('Total'),
                'order': 'amount_total desc, id desc'
            },
        }
        # default sort by value
        if not sortby:
            sortby = 'date'
        order = searchbar_sortings[sortby]['order']

        searchbar_filters = {
            'all': {
                'label': _('All'),
                'domain': [('state', 'in', ['purchase', 'done', 'cancel'])]
            },
            'purchase': {
                'label': _('Purchase Order'),
                'domain': [('state', '=', 'purchase')]
            },
            'cancel': {
                'label': _('Cancelled'),
                'domain': [('state', '=', 'cancel')]
            },
            'done': {
                'label': _('Locked'),
                'domain': [('state', '=', 'done')]
            },
        }
        # default filter by value
        if not filterby:
            filterby = 'all'
        domain += searchbar_filters[filterby]['domain']

        # count for pager
        purchase_count = PurchaseOrder.search_count(domain)
        # make pager
        pager = portal_pager(url="/my/purchase",
                             url_args={
                                 'date_begin': date_begin,
                                 'date_end': date_end
                             },
                             total=purchase_count,
                             page=page,
                             step=self._items_per_page)
        # search the purchase orders to display, according to the pager data
        orders = PurchaseOrder.search(domain,
                                      order=order,
                                      limit=self._items_per_page,
                                      offset=pager['offset'])
        request.session['my_purchases_history'] = orders.ids[:100]

        values.update({
            'date':
            date_begin,
            'orders':
            orders,
            'page_name':
            'purchase',
            'pager':
            pager,
            'archive_groups':
            archive_groups,
            'searchbar_sortings':
            searchbar_sortings,
            'sortby':
            sortby,
            'searchbar_filters':
            OrderedDict(sorted(searchbar_filters.items())),
            'filterby':
            filterby,
            'default_url':
            '/my/purchase',
        })
        return request.render("purchase.portal_my_purchase_orders", values)