<commit_before>from netsuite.client import client
from netsuite.service import (
    Address,
    CashSale,
    CashSaleItem,
    CashSaleItemList,
    RecordRef
)
from netsuite.api.customer import get_or_create_customer
from netsuite.test_data import prepare_address, prepare_customer_data
from datetime import datetime


def get_item_reference(item):
    return RecordRef(
        internalId=item.internal_id,
        type='inventoryItem'
    )


def create_cashsale(data):
    addressee = '%s %s' % (data.first_name, data.last_name)
    shipping_address = prepare_address(addressee, data.shipping_address)
    billing_address = prepare_address(addressee, data.billing_address)

    raw_item = [
        CashSaleItem(
            item=get_item_reference(item),
            quantity=item.quantity
        ) for item in data.line_items
    ]
    item_list = CashSaleItemList(item=raw_item)
    #import ipdb;ipdb.set_trace()
    customer = get_or_create_customer(prepare_customer_data(data))
    print('****************customer**********', customer)
    cash_sale_data = {
        'itemList': item_list,
        'entity': RecordRef(internalId=customer.internalId),
        'email': data.email,
        'shippingAddress': Address(**shipping_address),
        'billingAddress': Address(**billing_address),
        'ccExpireDate': datetime(
            int(data.expiration_date_year),
            int(data.expiration_date_month),
            1
        ),
        'ccNumber': data.credit_card_number,
        'ccName': data.credit_card_owner,
        'ccSecurityCode': data.cvc2,
        'shippingCost': data.shipping_cost

    }
    cash_sale = CashSale(**cash_sale_data)
    from lxml import etree
    print(etree.tostring(client.service._binding.create_message('add', cash_sale)))
    response = client.service.add(cash_sale)
    r = response.body.writeResponse
    print(r)
    if r.status.isSuccess:
        return r<commit_msg>Added soap headers to cashsale request<commit_after>from netsuite.client import client, passport, app_info
from netsuite.service import (
    Address,
    CashSale,
    CashSaleItem,
    CashSaleItemList,
    RecordRef
)
from netsuite.api.customer import get_or_create_customer
from netsuite.test_data import prepare_address, prepare_customer_data
from datetime import datetime


def get_item_reference(item):
    return RecordRef(
        internalId=item.internal_id,
        type='inventoryItem'
    )


def create_cashsale(data):
    addressee = '%s %s' % (data.first_name, data.last_name)
    shipping_address = prepare_address(addressee, data.shipping_address)
    billing_address = prepare_address(addressee, data.billing_address)

    raw_item = [
        CashSaleItem(
            item=get_item_reference(item),
            quantity=item.quantity
        ) for item in data.line_items
    ]
    item_list = CashSaleItemList(item=raw_item)
    customer = get_or_create_customer(prepare_customer_data(data))
    print('****************customer**********', customer)
    cash_sale_data = {
        'itemList': item_list,
        'entity': RecordRef(internalId=customer.internalId),
        'email': data.email,
        'shippingAddress': Address(**shipping_address),
        'billingAddress': Address(**billing_address),
        'ccExpireDate': datetime(
            int(data.expiration_date_year),
            int(data.expiration_date_month),
            1
        ),
        'ccNumber': data.credit_card_number,
        'ccName': data.credit_card_owner,
        'ccSecurityCode': data.cvc2,
        'shippingCost': data.shipping_cost

    }
    cash_sale = CashSale(**cash_sale_data)
    response = client.service.add(cash_sale, _soapheaders={
        'passport': passport,
        'applicationInfo': app_info
    })
    print(etree.tostring(client.service._binding.create_message('add', cash_sale, _soapheaders={
        'passport': passport,
        'applicationInfo': app_info
    })))
    r = response.body.writeResponse
    print(r)
    if r.status.isSuccess:
        return r
{'fraction_non_alphanumeric': 0.1078187250996016, 'fraction_numerical': 0.00099601593625498, 'mean_word_length': 3.2962566844919787, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 1}, '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': '2939306', 'n_tokens_mistral': 1270, 'n_tokens_neox': 1229, 'n_words': 212}