<commit_before>from bika.lims.exportimport.dataimport import SetupDataSetList as SDL
from bika.lims.idserver import renameAfterCreation
from bika.lims.interfaces import ISetupDataSetList
from Products.CMFPlone.utils import safe_unicode, _createObjectByType
from bika.lims.utils import tmpID, to_unicode
from bika.lims.utils import to_utf8
from bika.lims import bikaMessageFactory as _
from bika.lims.utils import t
from Products.CMFCore.utils import getToolByName
from bika.lims import logger
from zope.interface import implements
from pkg_resources import resource_filename

import re
import transaction


def lookup(context, portal_type, **kwargs):
    at = getToolByName(context, 'archetype_tool')
    catalog = at.catalog_map.get(portal_type, [None])[0] or 'portal_catalog'
    catalog = getToolByName(context, catalog)
    kwargs['portal_type'] = portal_type
    return catalog(**kwargs)[0].getObject()


def check_for_required_columns(name, data, required):
    for column in required:
        if not data[column]:
            message = _("{0} has no '{1}' column." % (name, column))
            raise Exception(t(message))


def create_supply_order_item(context, product_title, quantity):
    # Lookup the product
    product = lookup(
        context.bika_setup.bika_labproducts,
        'LabProduct',
        Title=product_title,
    )
    # Create an item in the supply order
    obj = _createObjectByType('SupplyOrderItem', context, tmpID())
    obj.edit(
        Product=product,
        Quantity=quantity,
    )
    # Rename the new item
    renameAfterCreation(obj)


def Float(thing):
    try:
        f = float(thing)
    except ValueError:
        f = 0.0
    return f


class SetupDataSetList(SDL):

    implements(ISetupDataSetList)
<commit_msg>Added price and vat setting for SupplyOrderItems on import<commit_after>from bika.lims.exportimport.dataimport import SetupDataSetList as SDL
from bika.lims.idserver import renameAfterCreation
from bika.lims.interfaces import ISetupDataSetList
from Products.CMFPlone.utils import safe_unicode, _createObjectByType
from bika.lims.utils import tmpID, to_unicode
from bika.lims.utils import to_utf8
from bika.lims import bikaMessageFactory as _
from bika.lims.utils import t
from Products.CMFCore.utils import getToolByName
from bika.lims import logger
from zope.interface import implements
from pkg_resources import resource_filename

import re
import transaction


def lookup(context, portal_type, **kwargs):
    at = getToolByName(context, 'archetype_tool')
    catalog = at.catalog_map.get(portal_type, [None])[0] or 'portal_catalog'
    catalog = getToolByName(context, catalog)
    kwargs['portal_type'] = portal_type
    return catalog(**kwargs)[0].getObject()


def check_for_required_columns(name, data, required):
    for column in required:
        if not data[column]:
            message = _("{0} has no '{1}' column." % (name, column))
            raise Exception(t(message))


def create_supply_order_item(context, product_title, quantity):
    # Lookup the product
    product = lookup(
        context.bika_setup.bika_labproducts,
        'LabProduct',
        Title=product_title,
    )
    # Create an item in the supply order
    obj = _createObjectByType('SupplyOrderItem', context, tmpID())
    obj.edit(
        Product=product,
        Quantity=quantity,
        Price=product.getPrice(),
        VAT=product.getVAT(),
    )
    # Rename the new item
    renameAfterCreation(obj)


def Float(thing):
    try:
        f = float(thing)
    except ValueError:
        f = 0.0
    return f


class SetupDataSetList(SDL):

    implements(ISetupDataSetList)

{'fraction_non_alphanumeric': 0.08468518009348364, 'fraction_numerical': 0.00384932636788562, 'mean_word_length': 3.8313413014608235, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7477086', 'n_tokens_mistral': 1109, 'n_tokens_neox': 1101, 'n_words': 294}