当前位置: 首页>>代码示例>>Python>>正文


Python base.Document类代码示例

本文整理汇总了Python中pyavatax.base.Document的典型用法代码示例。如果您正苦于以下问题:Python Document类的具体用法?Python Document怎么用?Python Document使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Document类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_return

def test_return():
    random_doc_code = uuid.uuid4().hex  # you can't post/cancel the same doc code over and over
    api = get_api()
    doc = Document.new_sales_invoice(DocCode=random_doc_code, DocDate=datetime.date.today(), CustomerCode='[email protected]')
    to_address = Address(Line1="435 Ericksen Avenue Northeast", Line2="#250", PostalCode="98110")
    from_address = Address(Line1="100 Ravine Lane NE", Line2="#220", PostalCode="98110")
    doc.add_from_address(from_address)
    doc.add_to_address(to_address)
    line = Line(Amount=10.00)
    doc.add_line(line)
    tax = api.post_tax(doc)
    assert tax.is_success
    assert tax.total_tax > 0
    # and return invoice
    doc = Document.new_return_invoice(DocCode=random_doc_code, DocDate=datetime.date.today(), CustomerCode='[email protected]')
    to_address = Address(Line1="435 Ericksen Avenue Northeast", Line2="#250", PostalCode="98110")
    from_address = Address(Line1="100 Ravine Lane NE", Line2="#220", PostalCode="98110")
    doc.add_from_address(from_address)
    doc.add_to_address(to_address)
    line = Line(Amount=-10.00)
    doc.add_line(line)
    tax_date = datetime.date.today() - datetime.timedelta(days=5)
    doc.add_override(TaxOverrideType=TaxOverride.OVERRIDE_DATE, TaxDate=tax_date, Reason="Tax Date change",)
    tax = api.post_tax(doc)
    assert tax.is_success
    assert float(tax.total_tax) < 0
开发者ID:activefrequency,项目名称:pyavatax,代码行数:26,代码来源:test_avalara.py

示例2: test_timeout

def test_timeout():
    api = get_api(timeout=0.00001)
    lat = 47.627935
    lng = -122.51702
    line = Line(Amount=10.00)
    doc = Document()
    doc.add_line(line)
    try:
        api.get_tax(lat, lng, doc)
    except AvalaraServerNotReachableException:
        assert True
    else:
        assert False
开发者ID:activefrequency,项目名称:pyavatax,代码行数:13,代码来源:test_avalara.py

示例3: test_gettax

def test_gettax():
    api = get_api()
    # A Lat/Long from Avalara's documentation
    lat = 47.627935
    lng = -122.51702
    line = Line(Amount=10.00)
    doc = Document()
    doc.add_line(line)
    tax = api.get_tax(lat, lng, doc)
    assert tax.is_success is True
    assert tax.Tax > 0
    assert tax.total_tax == tax.Tax
    tax = api.get_tax(lat, lng, None, sale_amount=10.00)
    assert tax.is_success is True
    assert tax.Tax > 0
    assert tax.total_tax == tax.Tax
开发者ID:activefrequency,项目名称:pyavatax,代码行数:16,代码来源:test_avalara.py

示例4: post_tax

 def post_tax(self, doc, commit=False):
     """Performs a HTTP POST to tax/get/   If commit=True we will 
     update the document's Commit flag to True, and we will check 
     the document type to make sure it is capable of being Commited.
     XXXXXOrder is not capable of being commited. We will change it 
     to XXXXXXXInvoice, which is capable of being committed"""
     if isinstance(doc, dict):
         doc = Document.from_data(doc)
     elif not isinstance(doc, Document):
         raise AvalaraTypeException(AvalaraException.CODE_BAD_DOC, 'Please pass a document or a dictionary to create a Document')
     stem = '/'.join([self.VERSION, 'tax', 'get'])
     doc.update(CompanyCode=self.company_code)
     if commit:
         doc.update(Commit=True)
         self.logger.debug('%s setting Commit=True' % doc.DocCode)
         # need to change doctype if order, to invoice, otherwise commit does nothing
         new_doc_type = {
             Document.DOC_TYPE_SALE_ORDER: Document.DOC_TYPE_SALE_INVOICE,
             Document.DOC_TYPE_RETURN_ORDER: Document.DOC_TYPE_RETURN_INVOICE,
             Document.DOC_TYPE_PURCHASE_ORDER: Document.DOC_TYPE_PURCHASE_INVOICE,
             Document.DOC_TYPE_INVENTORY_ORDER: Document.DOC_TYPE_INVENTORY_INVOICE
         }.get(doc.DocType, None)
         if new_doc_type:
             self.logger.debug('%s updating DocType from %s to %s' % (doc.DocCode, doc.DocType, new_doc_type))
             doc.update(DocType=new_doc_type)
     data = doc.todict()
     resp = self._post(stem, data)
     tax_resp = PostTaxResponse(resp)
     self.logger.info('"POST", %s, %s%s with: %s' % (getattr(doc, 'DocCode', None), self.url, stem, data))
     if not hasattr(doc, 'DocCode'):
         doc.update_doc_code_from_response(tax_resp)
     self.recorder.success(doc)
     return tax_resp
开发者ID:TheBlackTuxCorp,项目名称:pyavatux,代码行数:33,代码来源:api.py

示例5: cancel_tax

 def cancel_tax(self, doc, reason=None, doc_id=None):
     """Performs a HTTP POST to tax/cancel/"""
     if isinstance(doc, dict):
         doc = Document.from_data(doc)
     elif not isinstance(doc, Document):
         raise AvalaraTypeException(AvalaraException.CODE_BAD_DOC, 'Please pass a document or a dictionary to create a Document')
     if reason and (not reason in Document.CANCEL_CODES):
         raise AvalaraValidationException(AvalaraException.CODE_BAD_CANCEL, "Please pass a valid cancel code")
     stem = '/'.join([self.VERSION, 'tax', 'cancel'])
     data = {
         'CompanyCode': doc.CompanyCode,
         'DocType': doc.DocType,
     }
     if reason:
         data.update({'CancelCode': reason})
     if hasattr(doc, 'DocCode'):
         data.update({'DocCode': doc.DocCode})
     _doc_id = None
     if hasattr(doc, 'DocId'):
         _doc_id = doc.DocId
     if doc_id:
         _doc_id = doc_id
     if _doc_id:
         data.update({'DocId': _doc_id})
     resp = self._post(stem, data)
     self.logger.info('"POST", %s, %s%s with: %s' % (getattr(doc, 'DocCode', None), self.url, stem, data))
     self.recorder.success(doc)
     return CancelTaxResponse(resp)
开发者ID:TheBlackTuxCorp,项目名称:pyavatux,代码行数:28,代码来源:api.py

示例6: test_posttax

def test_posttax():
    with LogCapture('pyavatax.api') as l:
        api = get_api()
        # dont pass a doccode
        doc = Document.new_sales_order(DocDate=datetime.date.today(), CustomerCode='[email protected]')
        to_address = Address(Line1="435 Ericksen Avenue Northeast", Line2="#250", PostalCode="98110")
        from_address = Address(Line1="100 Ravine Lane NE", Line2="#220", PostalCode="98110")
        doc.add_from_address(from_address)
        doc.add_to_address(to_address)
        line = Line(Amount=10.00)
        doc.add_line(line)
        # make sure i don't have a doccode
        try:
            doc.DocCode
        except AttributeError:
            assert True
        else:
            assert False
        tax = api.post_tax(doc)
    assert tax.is_success is True
    assert tax.TotalTax > 0
    assert len(tax.TaxAddresses) == 2
    assert len(tax.TaxLines) == 1
    assert len(tax.TaxLines[0].TaxDetails) > 0
    assert tax.DocCode
    assert doc.DocCode  # make sure the doccode moved over
    l.check(
        ('pyavatax.api', 'DEBUG', 'None setting default from address code'),
        ('pyavatax.api', 'DEBUG', 'None setting default to address code'),
        ('pyavatax.api', 'DEBUG', 'None inserting LineNo 1'),
        ('pyavatax.api', 'DEBUG', 'None setting origin code %s' % Address.DEFAULT_FROM_ADDRESS_CODE),
        ('pyavatax.api', 'DEBUG', 'None setting destination code %s' % Address.DEFAULT_TO_ADDRESS_CODE),
        ('pyavatax.api', 'INFO', '"POST", %s, %s%s' % (None, api.url, '/'.join([API.VERSION, 'tax', 'get']))),
        ('pyavatax.api', 'DEBUG', 'AvaTax assigned %s as DocCode' % doc.DocCode)
    )
开发者ID:kgrinberg,项目名称:pyavatax,代码行数:35,代码来源:test_avalara.py

示例7: test_recorder

def test_recorder():
    try:
        from pyavatax.models import AvaTaxRecord
    except ImportError:  # no django
        pytest.mark.xfail('This can only be run inside a django environment')
        return
    random_doc_code = uuid.uuid4().hex  # you can't post/cancel the same doc code over and over
    api = get_api()
    doc = Document.new_sales_invoice(DocCode=random_doc_code, DocDate=datetime.date.today(), CustomerCode='[email protected]')
    to_address = Address(Line1="435 Ericksen Avenue Northeast", Line2="#250", PostalCode="98110")
    from_address = Address(Line1="100 Ravine Lane NE", Line2="#220", PostalCode="98110")
    doc.add_from_address(from_address)
    doc.add_to_address(to_address)
    line = Line(Amount=10.00)
    doc.add_line(line)
    setattr(doc, '_testing_ignore_validate', True)  # passthrough I put in to allow this test, never actually use this
    orig_doc_type = doc.DocType
    doc.DocType = 'DoesntExist'  # forcing error
    tax = api.post_tax(doc)
    assert tax.is_success == False
    assert 1 == AvaTaxRecord.failures.filter(doc_code=random_doc_code).count()
    assert 0 == AvaTaxRecord.successes.filter(doc_code=random_doc_code).count()
    doc.DocType = orig_doc_type
    tax = api.post_tax(doc, commit=True)
    assert tax.is_success == True
    assert 0 == AvaTaxRecord.failures.filter(doc_code=random_doc_code).count()
    assert 1 == AvaTaxRecord.successes.filter(doc_code=random_doc_code).count()
    tax = api.post_tax(doc, commit=True)
    assert tax.is_success == False
    assert 1 == AvaTaxRecord.failures.filter(doc_code=random_doc_code).count()
    assert 1 == AvaTaxRecord.successes.filter(doc_code=random_doc_code).count()
开发者ID:activefrequency,项目名称:pyavatax,代码行数:31,代码来源:test_avalara.py

示例8: test_timeout

def test_timeout():
    with LogCapture('pyavatax.api') as l:
        api = get_api(timeout=0.00001)
        lat = 47.627935
        lng = -122.51702
        line = Line(Amount=10.00)
        doc = Document()
        doc.add_line(line)
        try:
            api.get_tax(lat, lng, doc)
        except AvalaraServerNotReachableException:
            assert True
        else:
            assert False
    l.check(
        ('pyavatax.api', 'DEBUG', 'None inserting LineNo 1'),
        ('pyavatax.api', 'WARNING', "HTTPSConnectionPool(host='development.avalara.net', port=443): Request timed out. (timeout=1e-05)")
    )
开发者ID:lionheart,项目名称:pyavatax,代码行数:18,代码来源:test_avalara.py

示例9: test_discount

def test_discount():
    api = get_api()
    # dont pass a doccode
    amount = 10.00
    doc = Document.new_sales_order(DocDate=datetime.date.today(), CustomerCode='[email protected]', Discount=amount)
    doc.add_from_address(Line1="100 Ravine Lane NE", Line2="#220", PostalCode="98110")
    doc.add_to_address(Line1="435 Ericksen Avenue Northeast", Line2="#250", PostalCode="98110")
    doc.add_line(Amount=amount, Discounted=True)
    tax = api.post_tax(doc)
    assert tax.is_success is True
    assert float(tax.TotalTax) == 0
    assert float(tax.TotalAmount) == amount
    assert float(tax.TotalDiscount) == amount
开发者ID:activefrequency,项目名称:pyavatax,代码行数:13,代码来源:test_avalara.py

示例10: get_tax

 def get_tax(self, lat, lng, doc, sale_amount=None):
     """Performs a HTTP GET to tax/get/"""
     if isinstance(doc, dict):
         doc = Document.from_data(doc)
     elif not isinstance(doc, Document) and sale_amount == None:
         raise AvalaraException('Please pass a document or a dictionary to create a Document')
     try:
         stem = '/'.join([self.VERSION, 'tax', '%.6f,%.6f' % (lat, lng), 'get'])
     except TypeError:
         raise AvalaraException('Please pass lat and lng as floats, or Decimal')
     data = {'saleamount': sale_amount} if sale_amount else {'saleamount': doc.total}
     resp = self._get(stem, data)
     self.logger.info('"GET" %s%s' % (self.url, stem))
     self.recorder.success(doc)
     return GetTaxResponse(resp)
开发者ID:kgrinberg,项目名称:pyavatax,代码行数:15,代码来源:api.py

示例11: test_posttax_commit_exempt

def test_posttax_commit_exempt():
    random_doc_code = uuid.uuid4().hex  # you can't post/cancel the same doc code over and over
    api = get_api()
    # G = resale, which means exempt from tax
    doc = Document.new_sales_order(DocCode=random_doc_code, DocDate=datetime.date.today(), CustomerCode='[email protected]', CustomerUsageType='G')
    to_address = Address(Line1="435 Ericksen Avenue Northeast", Line2="#250", PostalCode="98110")
    from_address = Address(Line1="100 Ravine Lane NE", Line2="#220", PostalCode="98110")
    doc.add_from_address(from_address)
    doc.add_to_address(to_address)
    line = Line(Amount=10.00, Qty=2)
    doc.add_line(line)
    doc.add_line(TaxCode='FR', Amount='12.00')
    tax = api.post_tax(doc, commit=True)
    assert doc.Commit
    assert doc.DocType == Document.DOC_TYPE_SALE_INVOICE  # make sure the doc type changes with commit
    assert tax.is_success is True
    assert tax.TotalTax == '0'
    assert len(tax.TaxAddresses) == 2
    assert len(tax.TaxLines) == 2
开发者ID:activefrequency,项目名称:pyavatax,代码行数:19,代码来源:test_avalara.py

示例12: test_override

def test_override():
    import uuid
    random_doc_code = uuid.uuid4().hex  # you can't post/cancel the same doc code over and over
    api = get_api()
    doc = Document.new_sales_invoice(DocCode=random_doc_code, DocDate=datetime.date.today(), CustomerCode='[email protected]')
    to_address = Address(Line1="435 Ericksen Avenue Northeast", Line2="#250", PostalCode="98110")
    from_address = Address(Line1="100 Ravine Lane NE", Line2="#220", PostalCode="98110")
    doc.add_from_address(from_address)
    doc.add_to_address(to_address)
    line = Line(Amount=10.00)
    doc.add_line(line)
    tax = api.post_tax(doc)
    assert tax.is_success
    assert tax.total_tax > 0
    # now the soap part
    soap_api = get_soap_api()
    tax_date = datetime.date.today() - datetime.timedelta(days=5)
    tax = soap_api.tax_override(doc, tax_date=tax_date, tax_amt=0, reason="Tax Date change", override_type='TaxDate')
    assert tax.is_success
    assert tax.total_tax > 0
开发者ID:kgrinberg,项目名称:pyavatax,代码行数:20,代码来源:test_avalara.py

示例13: test_posttax

def test_posttax():
    with LogCapture('pyavatax.api') as l:
        api = get_api()
        # dont pass a doccode
        doc = Document.new_sales_order(DocDate=datetime.date.today(), CustomerCode='[email protected]')
        doc.add_from_address(Line1="100 Ravine Lane NE", Line2="#220", PostalCode="98110")
        doc.add_to_address(Line1="435 Ericksen Avenue Northeast", Line2="#250", PostalCode="98110")
        doc.add_line(Amount=10.00)
        doc.add_line(Amount=10.00)
        doc.add_line(TaxCode='FR', Amount='12.00')
        # make sure i don't have a doccode
        try:
            doc.DocCode
        except AttributeError:
            assert True
        else:
            assert False
        tax = api.post_tax(doc)
    assert tax.is_success is True
    assert tax.TotalTax > 0
    assert len(tax.TaxAddresses) == 2
    assert len(tax.TaxLines) == 3
    assert len(tax.TaxLines[0].TaxDetails) > 0
    assert tax.DocCode
    assert doc.DocCode  # make sure the doccode moved over
    docdate = datetime.date.today().strftime('%Y-%m-%d')
    l.check(
        ('pyavatax.api', 'DEBUG', 'None setting default from address code'),
        ('pyavatax.api', 'DEBUG', 'None setting default to address code'),
        ('pyavatax.api', 'DEBUG', 'None inserting LineNo 1'),
        ('pyavatax.api', 'DEBUG', 'None inserting LineNo 2'),
        ('pyavatax.api', 'DEBUG', 'None inserting LineNo 3'),
        ('pyavatax.api', 'DEBUG', 'None setting origin code %s' % Address.DEFAULT_FROM_ADDRESS_CODE),
        ('pyavatax.api', 'DEBUG', 'None setting destination code %s' % Address.DEFAULT_TO_ADDRESS_CODE),
        ('pyavatax.api', 'DEBUG', 'None setting origin code %s' % Address.DEFAULT_FROM_ADDRESS_CODE),
        ('pyavatax.api', 'DEBUG', 'None setting destination code %s' % Address.DEFAULT_TO_ADDRESS_CODE),
        ('pyavatax.api', 'DEBUG', 'None setting origin code %s' % Address.DEFAULT_FROM_ADDRESS_CODE),
        ('pyavatax.api', 'DEBUG', 'None setting destination code %s' % Address.DEFAULT_TO_ADDRESS_CODE),
        ('pyavatax.api', 'INFO', '"POST", %s, %s%s with: %s' % (None, api.url, '/'.join([API.VERSION, 'tax', 'get']), '{\'Addresses\': [{\'PostalCode\': \'98110\', \'AddressCode\': \'1\', \'Line2\': \'#220\', \'Line1\': \'100 Ravine Lane NE\'}, {\'PostalCode\': \'98110\', \'AddressCode\': \'2\', \'Line2\': \'#250\', \'Line1\': \'435 Ericksen Avenue Northeast\'}], \'DocDate\': \'' + docdate + '\', \'Lines\': [{\'DestinationCode\': \'2\', \'Amount\': 10.0, \'Qty\': 1, \'LineNo\': 1, \'OriginCode\': \'1\'}, {\'DestinationCode\': \'2\', \'Amount\': 10.0, \'Qty\': 1, \'LineNo\': 2, \'OriginCode\': \'1\'}, {\'TaxCode\': \'FR\', \'DestinationCode\': \'2\', \'Qty\': 1, \'Amount\': 12.0, \'LineNo\': 3, \'OriginCode\': \'1\'}], \'DocType\': \'SalesOrder\', \'Discount\': 0, \'CustomerCode\': \'[email protected]\', \'PaymentDate\': None, \'CompanyCode\': \'PYAVATEST\'}')),
        ('pyavatax.api', 'DEBUG', 'AvaTax assigned %s as DocCode' % doc.DocCode)
    )
开发者ID:activefrequency,项目名称:pyavatax,代码行数:41,代码来源:test_avalara.py

示例14: test_override_failure

def test_override_failure():
    try:
        from pyavatax.models import AvaTaxRecord
    except ImportError:  # no django
        pytest.mark.xfail('This can only be run inside a django environment')
        return
    random_doc_code = uuid.uuid4().hex  # you can't post/cancel the same doc code over and over
    api = get_api()
    doc = Document.new_sales_invoice(DocCode=random_doc_code, DocDate=datetime.date.today(), CustomerCode='[email protected]')
    to_address = Address(Line1="435 Ericksen Avenue Northeast", Line2="#250", PostalCode="98110")
    from_address = Address(Line1="100 Ravine Lane NE", Line2="#220", PostalCode="98110")
    doc.add_from_address(from_address)
    doc.add_to_address(to_address)
    line = Line(Amount=10.00)
    doc.add_line(line)
    doc.DocType = 'FooBar'  # forcing error
    tax_date = datetime.date.today() - datetime.timedelta(days=5)
    doc.add_override(TaxOverrideType=TaxOverride.OVERRIDE_DATE, TaxDate=tax_date, Reason="Tax Date change",)
    tax = api.post_tax(doc)
    assert tax.is_success == False
    assert 1 == AvaTaxRecord.failures.filter(doc_code=random_doc_code).count()
    assert 0 == AvaTaxRecord.successes.filter(doc_code=random_doc_code).count()
开发者ID:activefrequency,项目名称:pyavatax,代码行数:22,代码来源:test_avalara.py

示例15: test_posttax_commit_cancel

def test_posttax_commit_cancel():
    random_doc_code = uuid.uuid4().hex  # you can't post/cancel the same doc code over and over
    api = get_api()
    doc = Document.new_sales_order(DocCode=random_doc_code, DocDate=datetime.date.today(), CustomerCode='[email protected]')
    to_address = Address(Line1="435 Ericksen Avenue Northeast", Line2="#250", PostalCode="98110")
    from_address = Address(Line1="100 Ravine Lane NE", Line2="#220", PostalCode="98110")
    doc.add_from_address(from_address)
    doc.add_to_address(to_address)
    line = Line(Amount=10.00, Qty=2)
    doc.add_line(line)
    tax = api.post_tax(doc, commit=True)
    assert doc.Commit
    assert doc.DocType == Document.DOC_TYPE_SALE_INVOICE  # make sure the doc type changes with commit
    assert tax.is_success is True
    assert tax.TotalTax > 0
    assert tax.total_tax == tax.TotalTax
    assert len(tax.TaxAddresses) == 2
    assert len(tax.TaxLines) == 1
    assert len(tax.TaxLines[0].TaxDetails) > 0
    cancel = api.cancel_tax(doc)
    assert cancel.is_success is True
    assert cancel.CancelTaxResult
开发者ID:activefrequency,项目名称:pyavatax,代码行数:22,代码来源:test_avalara.py


注:本文中的pyavatax.base.Document类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。