# -*- coding: utf-8 -*-
##############################################################################
#
#    Odoo, Open Source Management Solution
#    Copyright (C) 2016 Prime Consulting SA, Cape Verde (<http://prime.cv>).
#
##############################################################################
import sys
reload(sys)  
sys.setdefaultencoding('utf8')

from odoo import models, fields, api

class account_invoice(models.Model):
	_inherit = "account.invoice"

	@api.depends('invoice_line_ids')
	def _get_product_names(self):
		"""Compute Product Names from Invoice Lines to be showed on Invoice List.
		"""
		for invoice in self:
			product_desc = ''
			for line in invoice.invoice_line_ids:
				if line.product_id:
					if not product_desc:
						product_desc = line.product_id.product_tmpl_id.name
					else:
						product_desc = product_desc + ', ' + str(line.product_id.product_tmpl_id.name)
			invoice.product_desc = product_desc

	product_id = fields.Many2one('product.product', related='invoice_line_ids.product_id', string='Product')
	product_desc = fields.Char(compute='_get_product_names', string='Product')

