# -*- coding: utf-8 -*-
##############################################################################
#
#    Odoo, Open Source Management Solution
#    Copyright (C) 2014-TODAY Prime Consulting SA, Cape Verde (<http://prime.cv>).
#
##############################################################################

from odoo import models, fields, api

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

    @api.multi
    def get_invoice_folio(self):
        folio = False
        for invoice in self:
            sale = self.env['sale.order'].search([('name', '=', invoice.origin)])
            if sale:
                folio = self.env['etourism.enterprise.folio'].search([('order_id', '=', sale[0].id)])
        return folio

    @api.multi
    def get_folio_products(self):
        folio_products = []
        for invoice in self:
            sale = self.env['sale.order'].search([('name', '=', invoice.origin)])
            if sale:
                for folio in self.env['etourism.enterprise.folio'].search([('order_id', '=', sale[0].id)]):
                    for line in folio.room_lines:
                        folio_products.append(line.product_id.id)
        return folio_products
        
    @api.multi
    def get_enterprise_nif(self,nif):
        v_nif = False
        if nif:
            v_nif = str(nif)
        return v_nif
