# -*- coding: utf-8 -*-
###############################################################################
#
#    Tech-Receptives Solutions Pvt. Ltd.
#    Copyright (C) 2009-TODAY Tech-Receptives(<http://www.techreceptives.com>).
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU Lesser General Public License as
#    published by the Free Software Foundation, either version 3 of the
#    License, or (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU Lesser General Public License for more details.
#
#    You should have received a copy of the GNU Lesser General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
###############################################################################

from odoo.osv import expression
from odoo.tools.float_utils import float_round as round
from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT
from odoo.exceptions import UserError, ValidationError
from odoo import api, fields, models, _
from datetime import datetime

import odoo.addons.decimal_precision as dp

class EtourismProductPricelistItems(models.Model):
    _inherit = 'product.pricelist.item'
    _description = "Pricelist items"

    package_id = fields.Many2one('etourism.avt.package', 'Package')
    voucher_ids = fields.One2many('etourism.avt.voucher', 'price_item_id', 'Vouchers', copy=False)
    fixed_price_euros = fields.Float('Price (Euros)', digits=dp.get_precision('Price Euros'))

    @api.multi
    def validate_voucher(self,voucher_code):
        print "VOUCHER CODE: ", voucher_code
        print "VOUCHES: ",self.voucher_ids
        for voucher_id in self.voucher_ids:
            print "VOUCHER NAME: ",voucher_id.name
            if voucher_id.name == voucher_code:
                print "VOUCHER_ID: ",voucher_id
                return voucher_id

    @api.multi
    def name_get(self):
        result = []
        for pritem in self:
            if pritem.package_id:
                min = pritem.min_quantity if pritem.min_quantity else 0
                max = pritem.max_occupancy if pritem.max_occupancy else 0

                name = str(pritem.package_id.code if pritem.package_id.code else pritem.package_id.name)+' ' if pritem.package_id else ' '
                name+= '( '+str(min)+' - '+str(max)+' )'
            else:
                name = ' - '.join(filter(bool, [pritem.categ_id.name, pritem.booking_condition_id.name, str(pritem.fixed_price)]))
            result.append((pritem.id, name))
        return result



