def buyer(self):
     '''
     Gets the buyer.
     @return: Buyer
     '''
     buyer_uri = (self._get_attribute("buyer") or {}).get("uri")
     return self.client.seller.buyers[extract_id_from_uri(buyer_uri)]
 def company(self):
     """
     Gets the seller's company info.
     @return: greendizer.resources.Company
     """
     company_id = extract_id_from_uri(self._get_attribute("companyURI"))
     return Company(self.__email, company_id)
 def seller(self):
     """
     Gets the seller who sent the invoice.
     @return: Seller
     """
     seller_id = extract_id_from_uri(self._get_attribute("sellerURI"))
     return Seller(self.email, seller_id)
    def __create_transaction(self, trans_type, **data):
        '''
        Creates a transaction to perform a payment or a withdrawal.
        @param trans_type:str Transaction type.
        @return: Transaction
        '''
        request = http.Request(self.balance.client, method="POST", uri=self.uri,
                          data=data)

        response = request.get_response()
        if response.get_status_code() == 201:
            transaction_id = extract_id_from_uri(response["Location"])
            transaction = self[transaction_id]
            transaction.sync(response.data, response["Etag"])
            return transaction
    def add(self, payment_date, method, amount=None):
        '''
        Records a payment.
        @param payment_date:datetime date of the payment.
        @param method:str Payment method.
        @param amount:float (optional) Amount to transfer.
        @returns: Payment
        '''
        amount = amount or self.invoice.total

        request = http.Request(self.invoice.client, method="POST", uri=self.uri,
                          data={'date': payment_date, 'method': method,
                                'amount': amount})

        response = request.get_response()
        if response.get_status_code() == 201:
            payment_id = extract_id_from_uri(response["Location"])
            payment = self[payment_id]
            payment.sync(response.data, response["Etag"])
            self.invoice.load()
            return payment