# Copyright (C) 2015 Chintalagiri Shashank
#
# This file is part of Tendril.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
Electronics Sourcing module documentation (:mod:`sourcing.electronics`)
=======================================================================
"""
import copy
import importlib
from tendril.utils import config
from tendril.utils import log
logger = log.get_logger(__name__, log.DEFAULT)
[docs]def init_vendors():
vlist = []
vdatalist = copy.copy(config.VENDORS_DATA)
for vendor in vdatalist:
vtype = vendor.get('vtype', None)
if not vtype:
logger.error('Vendor Type not defined for {0}'
''.format(vendor['name']))
continue
module_name = '.{0}'.format(vtype.lower())
module = importlib.import_module(module_name, __package__)
class_name = 'Vendor{0}'.format(vtype)
cls = getattr(module, class_name)
logger.info("Adding Vendor : {0}".format(vendor['dname']))
vendor_obj = cls(**vendor)
if vendor_obj:
vlist.append(vendor_obj)
else:
logger.error('Vendor Handlers not found for vendor : ' +
vendor['name'])
return vlist
[docs]class SourcingException(Exception):
pass
vendor_list = init_vendors()
[docs]def get_eff_acq_price(vsinfo):
return vsinfo.oqty * vsinfo.effprice.unit_price.native_value
[docs]def get_vendor_by_name(name):
for vendor in vendor_list:
if vendor._name == name:
return vendor
return None