Skip to content
Permalink
Browse files

[IMP] sale_timesheet: show all timesheets.

- in invoice and in timesheet tab show ordered and delivered timesheets.
  • Loading branch information...
pka-odoo committed Apr 12, 2019
1 parent 61ef388 commit 6749afe8bea32de690a2d87368c7a4672c622f87
Showing with 17 additions and 17 deletions.
  1. +17 −17 addons/sale_timesheet/controllers/portal.py
@@ -14,32 +14,32 @@

class CustomerPortal(CustomerPortal):

def get_domain_my_timesheet(self):
return ['|', '&',
('partner_id', '=', request.env.user.partner_id.id),
('user_id', '=', request.env.user.id),
('product_id.service_type', '!=', 'delivered_manual')]

def _prepare_portal_layout_values(self):
values = super(CustomerPortal, self)._prepare_portal_layout_values()

domain = ['&', '|', '&', ('timesheet_invoice_type', '=', 'billable_time'),
('timesheet_invoice_id', '!=', False),
('timesheet_invoice_type', '=', 'billable_fixed'),
('so_line', '!=', False)]

values['timesheet_count'] = request.env['account.analytic.line'].search_count(domain)
values['timesheet_count'] = request.env['account.analytic.line'].sudo().search_count(self.get_domain_my_timesheet())
return values

def _invoice_get_page_view_values(self, invoice, access_token, **kw):
values = super(CustomerPortal, self)._invoice_get_page_view_values(invoice, access_token, **kw)
timesheets = request.env['account.analytic.line'].search([('timesheet_invoice_id', '=', invoice.id)])
# add invoice related timesheets
if timesheets:
values['timesheets'] = timesheets

sale_order = invoice.mapped('invoice_line_ids.sale_line_ids.order_id')
values['timesheets'] = sale_order.mapped('timesheet_ids').sudo().filtered(lambda t: t.product_id.service_type != 'delivered_manual')

return values

@http.route(['/my/timesheets', '/my/timesheets/page/<int:page>'], type='http', auth="user", website=True)
def portal_my_timesheets(self, page=1, sortby=None, filterby=None, search=None, search_in='all', groupby='project', **kw):
values = self._prepare_portal_layout_values()
domain = ['&', '|', '&', ('timesheet_invoice_type', '=', 'billable_time'),
('timesheet_invoice_id', '!=', False),
('timesheet_invoice_type', '=', 'billable_fixed'),
('so_line', '!=', False)]
account_analytic_line_sudo = request.env['account.analytic.line'].sudo()

domain = self.get_domain_my_timesheet()

searchbar_sortings = {
'date': {'label': _('Newest'), 'order': 'date desc'},
@@ -87,7 +87,7 @@ def portal_my_timesheets(self, page=1, sortby=None, filterby=None, search=None,
search_domain = OR([search_domain, [('name', 'ilike', search)]])
domain += search_domain

timesheet_count = request.env['account.analytic.line'].search_count(domain)
timesheet_count = account_analytic_line_sudo.search_count(domain)
# pager
pager = portal_pager(
url="/my/timesheets",
@@ -99,9 +99,9 @@ def portal_my_timesheets(self, page=1, sortby=None, filterby=None, search=None,

if groupby == 'project':
order = "project_id, %s" % order
timesheets = request.env['account.analytic.line'].search(domain, order=order, limit=self._items_per_page, offset=pager['offset'])
timesheets = account_analytic_line_sudo.search(domain, order=order, limit=self._items_per_page, offset=pager['offset'])
if groupby == 'project':
grouped_timesheets = [request.env['account.analytic.line'].concat(*g) for k, g in groupbyelem(timesheets, itemgetter('project_id'))]
grouped_timesheets = [account_analytic_line_sudo.concat(*g) for k, g in groupbyelem(timesheets, itemgetter('project_id'))]
else:
grouped_timesheets = [timesheets]

0 comments on commit 6749afe

Please sign in to comment.
You can’t perform that action at this time.