Skip to content
Permalink
Browse files

[IMP] sale_timesheet: improvement

  • Loading branch information...
pka-odoo committed Apr 15, 2019
1 parent 073229f commit 1762c65eba1898ea7229ab7faa7416b0ef63f447
@@ -14,27 +14,31 @@

class CustomerPortal(CustomerPortal):

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

def _prepare_portal_layout_values(self):
values = super(CustomerPortal, self)._prepare_portal_layout_values()
domain = [('timesheet_invoice_id', '!=', False)]

values['timesheet_count'] = request.env['account.analytic.line'].search_count(domain)
values['timesheet_count'] = request.env['account.analytic.line'].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)])
if timesheets:
values['timesheets'] = timesheets
sale_order = invoice.mapped('invoice_line_ids.sale_line_ids.order_id')
values['timesheets'] = sale_order.mapped('tasks_ids.timesheet_ids').filtered(lambda t: t.timesheet_invoice_type != 'non_billable')

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_id', '!=', False)]
domain = self.get_domain_my_timesheet()

searchbar_sortings = {
'date': {'label': _('Newest'), 'order': 'date desc'},
@@ -26,13 +26,14 @@ def _default_sale_line_domain(self):
def _compute_timesheet_invoice_type(self):
for timesheet in self:
if timesheet.project_id: # AAL will be set to False
invoice_type = 'non_billable_project' if not timesheet.task_id else 'non_billable'
if not timesheet.task_id:
invoice_type = 'non_billable_project'
if timesheet.task_id and timesheet.so_line.product_id.type == 'service':
if timesheet.so_line.product_id.invoice_policy == 'delivery':
if timesheet.so_line.product_id.service_type == 'timesheet':
invoice_type = 'billable_time'
else:
invoice_type = 'billable_fixed'
invoice_type = 'non_billable'
elif timesheet.so_line.product_id.invoice_policy == 'order':
invoice_type = 'billable_fixed'
timesheet.timesheet_invoice_type = invoice_type
@@ -58,7 +58,7 @@ def create(self, values):
"""
invoice_line = super(AccountInvoiceLine, self).create(values)
if invoice_line.invoice_id.type == 'out_invoice' and invoice_line.invoice_id.state == 'draft':
sale_line_delivery = invoice_line.sale_line_ids.filtered(lambda sol: sol.product_id.service_type == 'timesheet')
sale_line_delivery = invoice_line.sale_line_ids.filtered(lambda sol: sol.product_id.invoice_policy == 'delivery' and sol.product_id.service_type == 'timesheet')
if sale_line_delivery:
domain = self._timesheet_domain_get_invoiced_lines(sale_line_delivery)
timesheets = self.env['account.analytic.line'].search(domain)

0 comments on commit 1762c65

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