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


Python Document.from_data方法代码示例

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


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

示例1: cancel_tax

# 需要导入模块: from pyavatax.base import Document [as 别名]
# 或者: from pyavatax.base.Document import from_data [as 别名]
 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,代码行数:30,代码来源:api.py

示例2: post_tax

# 需要导入模块: from pyavatax.base import Document [as 别名]
# 或者: from pyavatax.base.Document import from_data [as 别名]
 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,代码行数:35,代码来源:api.py

示例3: get_tax

# 需要导入模块: from pyavatax.base import Document [as 别名]
# 或者: from pyavatax.base.Document import from_data [as 别名]
 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,代码行数:17,代码来源:api.py


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