예제 #1
0
    def create(self, client_id, invoice_no, invoice_date, sale_date, currency_id = None, language_id = None):
        '''
            Create a new invoice
        '''
        self._invoice_items = []
        
        client = ClientManager.find_by_id(client_id)
        
        if currency_id is None:
            currency = client.default_currency
        else:
            currency = CurrencyManager.find_by_id(currency_id)
        
        if language_id is None:
            language = client.default_language
        else:
            language = LanguageManager.find_by_id(language_id)
        
        self._invoice = InvoiceEntity.create(
                                       user = self._user,
                                       client = client,
                                       currency = currency,
                                       language = language,
                                       invoice_no = invoice_no,
                                       invoice_date = invoice_date,
                                       sale_date = sale_date
                                    )

        return self._invoice
예제 #2
0
 def find_invoice_by_id(self, invoice_id):
     """ Find an invoice entity by its id """
     invoice = InvoiceEntity.get_by_id(invoice_id)
     if invoice is not None:
         # If the invoice belongs to another user, set the result to None
         if invoice.user.key() != self._user.key():
             invoice = None
 
     return invoice