Beispiel #1
0
 def test_parses_basic_format(self):
     xml_string = '<root><kiddie><value>2008-06-21T10:36:12</value></kiddie></root>'
     xml = objectify.fromstring(xml_string)
     field = xml_models.DateField(xpath='/root/kiddie/value')
     response = field.parse(xml, None)
     date = datetime.datetime(2008, 6, 21, 10, 36, 12)
     self.assertEquals(date, response)
Beispiel #2
0
 def test_allows_custom_date_fromat(self):
     xml_string = '<root><kiddie><value>20080621-10:36:12</value></kiddie></root>'
     xml = objectify.fromstring(xml_string)
     field = xml_models.DateField(xpath='/root/kiddie/value',
                                  date_format="%Y%m%d-%H:%M:%S")
     response = field.parse(xml, None)
     date = datetime.datetime(2008, 6, 21, 10, 36, 12)
     self.assertEquals(date, response)
Beispiel #3
0
    def test_handles_utc_offset(self):
        import pytz

        xml_string = '<root><kiddie><value>2008-06-21T10:36:12-06:00</value></kiddie></root>'
        xml = objectify.fromstring(xml_string)
        field = xml_models.DateField(xpath='/root/kiddie/value')
        response = field.parse(xml, None)
        date = pytz.UTC.localize(datetime.datetime(2008, 6, 21, 16, 36, 12))
        self.assertEquals(date, response)
Beispiel #4
0
class InventoryListItem(xml_models.Model):
    """ Inventory List Item Entity """

    uid = xml_models.IntField(xpath="/inventoryItem/@uid", default=0)
    lastUpdatedUid = xml_models.CharField(
        xpath="/inventoryItem/@lastUpdatedUid")
    utcFirstCreated = xml_models.CharField(
        xpath="/inventoryItem/utcFirstCreated")
    utcLastModified = xml_models.CharField(
        xpath="/inventoryItem/utcLastModified")

    code = xml_models.CharField(xpath="/inventoryItem/code")
    description = xml_models.CharField(xpath="/inventoryItem/description")
    isActive = xml_models.BoolField(xpath="/inventoryItem/isActive",
                                    default=True)
    isInventoried = xml_models.BoolField(xpath="/inventoryItem/isInventoried",
                                         default=False)

    assetAccountUid = xml_models.IntField(
        xpath="/inventoryItem/assetAccountUid", default=0)
    stockOnHand = xml_models.IntField(xpath="/inventoryItem/stockOnHand",
                                      default=0)
    currentValue = xml_models.IntField(xpath="/inventoryItem/currentValue",
                                       default=0)
    quantityOnOrder = xml_models.IntField(
        xpath="/inventoryItem/quantityOnOrder", default=0)
    quantityCommited = xml_models.IntField(
        xpath="/inventoryItem/quantityCommited", default=0)

    isBought = xml_models.BoolField(xpath="/inventoryItem/isBought",
                                    default=False)

    purchaseExpenseAccountUid = xml_models.IntField(
        xpath="/inventoryItem/purchaseExpenseAccountUid", default=0)
    minimumStockLevel = xml_models.IntField(
        xpath="/inventoryItem/minimumStockLevel", default=0)
    primarySupplierContactUid = xml_models.IntField(
        xpath="/inventoryItem/primarySupplierContactUid", default=0)
    defaultReOrderQuantity = xml_models.IntField(
        xpath="/inventoryItem/defaultReOrderQuantity", default=0)

    isSold = xml_models.BoolField(xpath="/inventoryItem/isSold", default=True)

    saleIncomeAccountUid = xml_models.IntField(
        xpath="/inventoryItem/saleIncomeAccountUid", default=0)
    saleTaxCode = xml_models.CharField(xpath="/inventoryItem/saleTaxCode")
    saleCoSAccountUid = xml_models.IntField(
        xpath="/inventoryItem/saleCoSAccountUid", default=0)
    sellingPrice = xml_models.FloatField(xpath="/inventoryItem/sellingPrice",
                                         default=0)

    isSellingPriceIncTax = xml_models.BoolField(
        xpath="/inventoryItem/isSellingPriceIncTax", default=True)
    buyingPrice = xml_models.FloatField(xpath="/inventoryItem/buyingPrice",
                                        default=0)
    isBuyingPriceIncTax = xml_models.BoolField(
        xpath="/inventoryItem/isBuyingPriceIncTax", default=True)
    isVoucher = xml_models.BoolField(xpath="/inventoryItem/isVoucher",
                                     default=False)

    validFrom = xml_models.DateField(xpath="/inventoryItem/validFrom",
                                     date_format="%Y-%m-%d")
    validTo = xml_models.DateField(xpath="/inventoryItem/validTo",
                                   date_format="%Y-%m-%d")

    isVirtual = xml_models.BoolField(xpath="/inventoryItem/isVirtual",
                                     default=True)
    isVisible = xml_models.BoolField(xpath="/inventoryItem/isVisisble",
                                     default=False)
Beispiel #5
0
class InventoryItem(BaseModel):
    """ Inventory Item Entity """

    __model__ = 'InventoryItem'

    # Required for update.
    uid = xml_models.IntField(
        xpath="/inventoryItemResponse/inventoryItem/@uid", default=0)
    # Required for update.
    lastUpdatedUid = xml_models.CharField(
        xpath="/inventoryItemResponse/inventoryItem/@lastUpdatedUid")
    # Inventory item code. Must be unique.
    code = xml_models.CharField(
        xpath="/inventoryItemResponse/inventoryItem/code")
    # Inventory item description.
    # Multi-line description is supported. Use the pipe (|) to indicate newline.
    description = xml_models.CharField(
        xpath="/inventoryItemResponse/inventoryItem/description")
    # Default: True
    isActive = xml_models.BoolField(
        xpath="/inventoryItemResponse/inventoryItem/isActive", default=True)
    notes = xml_models.CharField(
        xpath="/inventoryItemResponse/inventoryItem/notes")
    isInventoried = xml_models.BoolField(
        xpath="/inventoryItemResponse/inventoryItem/isInventoried",
        default=False)

    # Required only if IsInventoried is set to true. Accounts used must be of type Asset.
    assetAccountUid = xml_models.IntField(
        xpath="/inventoryItemResponse/inventoryItem/assetAccountUid",
        default=0)
    # How many stocks on hand? This element is only used when you retrieve an Inventory Item from your File.
    # This value is ignored on insert and update.
    stockOnHand = xml_models.IntField(
        xpath="/inventoryItemResponse/inventoryItem/stockOnHand", default=0)
    # Current stock value. This element is only used when you retrieve an Inventory Item from your File.
    # This value is ignored on insert and update.
    currentValue = xml_models.IntField(
        xpath="/inventoryItemResponse/inventoryItem/currentValue", default=0)
    # Specifies if this item can be bought or not. Default: false (cannot be bought).
    isBought = xml_models.BoolField(
        xpath="/inventoryItemResponse/inventoryItem/isBought", default=False)
    # Expense Account for tracking purchase.
    # Required only if the Inventory Item is not inventoried and item can be bought (isInventoried == false && isBought == true).
    # Accounts used must be of type Expense.
    purchaseExpenseAccountUid = xml_models.IntField(
        xpath="/inventoryItemResponse/inventoryItem/purchaseExpenseAccountUid",
        default=0)
    # Default tax code when the inventory item is purchased.
    purchaseTaxCode = xml_models.CharField(
        xpath="/inventoryItemResponse/inventoryItem/purchaseTaxCode")
    # Minimum stock level used for re-stocking alert report.
    minimumStockLevel = xml_models.IntField(
        xpath="/inventoryItemResponse/inventoryItem/minimumStockLevel",
        default=0)

    # The primary supplier for this Inventory Item.
    primarySupplierContactUid = xml_models.IntField(
        xpath="/inventoryItemResponse/inventoryItem/primarySupplierContactUid",
        default=0)
    # The primary supplier’s item code for this Inventory Item.
    primarySupplierItemCode = xml_models.CharField(
        xpath="/inventoryItemResponse/inventoryItem/primarySupplierItemCode")
    # Default re-order quantity for re-stocking alert report.
    defaultReOrderQuantity = xml_models.IntField(
        xpath="/inventoryItemResponse/inventoryItem/defaultReOrderQuantity",
        default=0)
    # Default buying price for the item. Only applicable if the Inventory Item is marked as bought.
    buyingPrice = xml_models.FloatField(
        xpath="/inventoryItemResponse/inventoryItem/buyingPrice", default=0)
    # A flag specifying whether the buying price includes/excludes tax.
    isBuyingPriceIncTax = xml_models.BoolField(
        xpath="/inventoryItemResponse/inventoryItem/isBuyingPriceIncTax",
        default=True)
    # Specifies whether the Inventory Item can be sold or not. Default: false (cannot be sold).
    isSold = xml_models.BoolField(
        xpath="/inventoryItemResponse/inventoryItem/isSold", default=True)
    # Account for tracking sales. Only required if the item can be sold (isSold == true). Accounts used must be of type Income.
    saleIncomeAccountUid = xml_models.IntField(
        xpath="/inventoryItemResponse/inventoryItem/saleIncomeAccountUid",
        default=0)
    # Default tax code for sale.
    saleTaxCode = xml_models.CharField(
        xpath="/inventoryItemResponse/inventoryItem/saleTaxCode")
    # Accounts for tracking cost of sales. Required only if Inventory Item is inventoried & for sale.
    # Accounts used must be of type Cost of Sales.
    saleCoSAccountUid = xml_models.IntField(
        xpath="/inventoryItemResponse/inventoryItem/saleCoSAccountUid",
        default=0)
    # The default selling price for this Inventory Item. Only applicable if the Inventory Item is marked as sold.
    sellingPrice = xml_models.FloatField(
        xpath="/inventoryItemResponse/inventoryItem/sellingPrice", default=0)
    isSellingPriceIncTax = xml_models.BoolField(
        xpath="/inventoryItemResponse/inventoryItem/isSellingPriceIncTax",
        default=True)

    # A flag that indicates this is an item you sell, that you haven’t bought or assembled as stock to make available for sale.
    isVirtual = xml_models.BoolField(
        xpath="/inventoryItemResponse/inventoryItem/isVirtual", default=True)
    # The type if this item is marked as virtual.
    vType = xml_models.CharField(
        xpath="/inventoryItemResponse/inventoryItem/vType")
    # A flag to set the Item to visible, for an example this can be
    # used in your database so that Item is flagged to be displayed in your ecommerce product listings.
    isVisible = xml_models.BoolField(
        xpath="/inventoryItemResponse/inventoryItem/isVisisble", default=False)
    # A flag specifying whether this item is treated as a voucher.
    isVoucher = xml_models.BoolField(
        xpath="/inventoryItemResponse/inventoryItem/isVoucher", default=False)

    # When the voucher becomes effective.
    validFrom = xml_models.DateField(
        xpath="/inventoryItemResponse/inventoryItem/validFrom",
        date_format="%Y-%m-%d")
    # When the voucher expires.
    validTo = xml_models.DateField(
        xpath="/inventoryItemResponse/inventoryItem/validTo",
        date_format="%Y-%m-%d")

    finders = {
        (uid, ): DEFAULT_GET_URL % __model__ + "&uid=%s",
    }
Beispiel #6
0
 def test_returns_none_when_the_node_is_empty(self):
     xml_string = '<root><kiddie><value></value></kiddie></root>'
     xml = objectify.fromstring(xml_string)
     field = xml_models.DateField(xpath='/root/kiddie/value')
     response = field.parse(xml, None)
     self.assertEquals(None, response)
Beispiel #7
0
    def test_uses_base(self, mock_base):
        mock_base.return_value = None
        field = xml_models.DateField(xpath='/root/kiddie/bools/@many')
        response = field.parse(XML, None)

        self.assertTrue(mock_base.called)
Beispiel #8
0
class ServiceInvoice(BaseModel):
    """ Service Invoice Entity """

    __model__ = 'Invoice'
    template_name = 'saasu_client/serviceinvoice_model.xml'

    uid = xml_models.IntField(xpath="/invoiceResponse/invoice/@uid", default=0) 
    lastUpdatedUid = xml_models.CharField(xpath="/invoiceResponse/invoice/@lastUpdatedUid")
    # Either S for Sale or P for Purchase.
    transactionType = xml_models.CharField(xpath="/invoiceResponse/invoice/transactionType", default="S")
    # The invoice date.
    date = xml_models.DateField(xpath="/invoiceResponse/invoice/date", date_format="%Y-%m-%d") 
    # The contact for this invoice. 0 means no contact.
    contactUid = xml_models.IntField(xpath="/invoiceResponse/invoice/contactUid", default=0) 
    # The shipping contact for this invoice. Not specifying or 0 means no shipping contact.
    shipToContactUid = xml_models.IntField(xpath="/invoiceResponse/invoice/shipToContactUid", default=0) 
    # Separate multiple tags by comma. Max length for each tag is 35 characters.
    tags = xml_models.CharField(xpath="/invoiceResponse/invoice/tags", default='')
    # Don’t set this value in invoice because this field is not accessible from the UI.
    reference = xml_models.CharField(xpath="/invoiceResponse/invoice/reference", default='')
    # Brief summary of the invoice
    summary = xml_models.CharField(xpath="/invoiceResponse/invoice/summary", default='')
    # The currency of the particular invoice transaction.
    ccy = xml_models.CharField(xpath="/invoiceResponse/invoice/ccy", default='')
    # Indicates whether the FX rate for the invoice was set automatically.
    autoPopulateFxRate = xml_models.BoolField(xpath="/invoiceResponse/invoice/autoPopulateFxRate", default=False) 

    # The Foreign Currency(FC) to Base Currency(BC) FX Rate. If you are setting the FX rate manually, and only have the BC to FC FX
    # rate, then you should calculate the fcToBcFxRate for posting the transaction. For an example, if your base currency is AUD and 1
    # AUD = 0.89 USD, get the inverse by 1/0.89. So your fcToBcFxRate = 1.1235.
    fcToBcFxRate = xml_models.FloatField(xpath="/invoiceResponse/invoice/fcToBcFxRate", default=0) 
    notes = xml_models.CharField(xpath="/invoiceResponse/invoice/notes", default='')
    # Notes to be displayed on pdf.
    externalNotes = xml_models.CharField(xpath="/invoiceResponse/invoice/externalNotes", default='')
    requiresFollowUp = xml_models.BoolField(xpath="/invoiceResponse/invoice/requiresFollowUp", default=False) 
    # Invoice and/or order due date or quote expiry date.
    dueOrExpiryDate = xml_models.DateField(xpath="/invoiceResponse/invoice/dueOrExpiryDate", date_format="%Y-%m-%d") 

    # The invoice layout. Either S (Service) or I (Item)
    layout = xml_models.CharField(xpath="/invoiceResponse/invoice/layout", default='S')
    # Invoice status. Either Q (Quote), O (Order) or I (Invoice).
    status = xml_models.CharField(xpath="/invoiceResponse/invoice/status", default='I')
    # The sale invoice number. When inserting a sale, set to <Auto Number> to let the system generates the invoice number based on the preferences you set.
    invoiceNumber = xml_models.CharField(xpath="/invoiceResponse/invoice/invoiceNumber", default='')
    # The purchase order number (PO #). When inserting a purchase, set to <Auto Number> to let the system generates the PO# based on the preferences you set.
    purchaseOrderNumber = xml_models.CharField(xpath="/invoiceResponse/invoice/purchaseOrderNumber", default='')

    # TODO: Complete this part
    # quickPayment	 	 	 	Payment to be applied to this invoice.
    # payments	 	 	 	   All payments associated with this particular invoice, if incpayments is set to ‘true’ in the query string.

    # Indicates if the invoice has been sent/emailed to contact. This flag will be set to true automatically if the Invoice is sent successfully through the WSAPI.
    isSent = xml_models.BoolField(xpath="/invoiceResponse/invoice/isSent", default=False) 

    # You can include unlimited number of invoice items. For service invoice, use <ServiceInvoiceItem>?
    # For item invoice: use <ItemInvoiceItem>. You cannot mix the content of invoice items (i.e. having both <ServiceInvoiceItem> and <ItemInvoiceItem>).
    invoiceItems = CollectionField(ServiceInvoiceItem, xpath='/invoiceResponse/invoice/invoiceItems/serviceInvoiceItem')	 	 	 

    finders = {
        ('uid',): DEFAULT_GET_URL % __model__ + "&uid=%s",
        }
Beispiel #9
0
class ContactListItem(xml_models.Model):
    """ Contact List Item Entity """

    contactUid = xml_models.IntField(xpath="/contactListItem/contactUid")
    utcFirstCreated = xml_models.CharField(
        xpath="/contactListItem/utcFirstCreated")
    utcLastModified = xml_models.CharField(
        xpath="/contactListItem/utcLastModified")
    lastUpdatedUid = xml_models.CharField(
        xpath="/contactListItem/lastUpdatedUid")
    salutation = xml_models.CharField(xpath="/contactListItem/salutation")
    givenName = xml_models.CharField(xpath="/contactListItem/givenName")
    middleInitials = xml_models.CharField(
        xpath="/contactListItem/middleInitials")
    familyName = xml_models.CharField(xpath="/contactListItem/familyName")
    dateOfBirth = xml_models.DateField(xpath="/contactListItem/dateOfBirth",
                                       date_format="%Y-%m-%d")

    organisation = xml_models.CharField(xpath="/contactListItem/organisation")
    organisationName = xml_models.CharField(
        xpath="/contactListItem/organisationName")
    organisationAbn = xml_models.CharField(
        xpath="/contactListItem/organisationAbn")
    abn = xml_models.CharField(xpath="/contactListItem/abn")

    organizationWebsite = xml_models.CharField(
        xpath="/contactListItem/organizationWebsite")
    organizationPosition = xml_models.CharField(
        xpath="/contactListItem/organizationPosition")
    emailAddress = xml_models.CharField(xpath="/contactListItem/emailAddress")
    websiteUrl = xml_models.CharField(xpath="/contactListItem/websiteUrl")
    isActive = xml_models.BoolField(xpath="/contactListItem/isActive",
                                    default=True)

    mainPhone = xml_models.CharField(xpath="/contactListItem/mainPhone")
    homePhone = xml_models.CharField(xpath="/contactListItem/homePhone")
    mobilePhone = xml_models.CharField(xpath="/contactListItem/mobilePhone")
    otherPhone = xml_models.CharField(xpath="/contactListItem/otherPhone")
    fax = xml_models.CharField(xpath="/contactListItem/fax")

    street = xml_models.CharField(xpath="/contactListItem/street")
    city = xml_models.CharField(xpath="/contactListItem/city")
    state = xml_models.CharField(xpath="/contactListItem/state")
    postCode = xml_models.CharField(xpath="/contactListItem/postCode")
    country = xml_models.CharField(xpath="/contactListItem/country")

    otherStreet = xml_models.CharField(xpath="/contactListItem/otherStreet")
    otherCity = xml_models.CharField(xpath="/contactListItem/otherCity")
    otherState = xml_models.CharField(xpath="/contactListItem/otherState")
    otherPostCode = xml_models.CharField(
        xpath="/contactListItem/otherPostCode")

    contactID = xml_models.CharField(xpath="/contactListItem/contactID")

    acceptDirectDeposit = xml_models.BoolField(
        xpath="/contactListItem/acceptDirectDeposit")
    directDepositAccountName = xml_models.CharField(
        xpath="/contactListItem/directDepositAccountName")
    directDepositBsb = xml_models.CharField(
        xpath="/contactListItem/directDepositBsb")
    directDepositAccountNumber = xml_models.CharField(
        xpath="/contactListItem/directDepositAccountNumber")

    acceptCheque = xml_models.BoolField(xpath="/contactListItem/acceptCheque")
    chequePayableTo = xml_models.CharField(
        xpath="/contactListItem/chequePayableTo")

    # Separate multiple tags by comma. Max. length per tag is 35 characters.
    tags = xml_models.CharField(xpath="/contactListItem/tags")

    customField1 = xml_models.CharField(xpath="/contactListItem/customField1")
    customField2 = xml_models.CharField(xpath="/contactListItem/customField2")