pybill.lib.accounting package¶
pybill.lib.accounting package contains the classes used to generate the
accounting entries from the accounting documents processed by PyBill.
The accounting entries can be saved in an XML file in pycompta format. This
package uses lxml to generate and write the XML data.
The only public class that should be used outside of this package is the
EntriesGenerator class. This class is
imported and available in the namespace of this package. Some useful constants
used to designate account numbers are also imported and available in the
namespace of this package.
generator module¶
pybill.lib.accounting.generator module defines the class that can generate
accounting entries from the accounting documents (PyBill entities).
This class can be used to generate the accounting entries for several documents and then to save the entries into an XML file.
-
class
pybill.lib.accounting.generator.EntriesGenerator¶ Class that generates accounting entries from the accounting documents (PyBill entities).
This class generates a unique list of accounting entries from a set of accounting documents, each document generating a single entry. This list can be written to an XML file with the dedicated method.
The accounting entries are generated in pycompta format.
-
entries¶ Attribute containing a list of accounting entries generated from the accounting documents. When generating the entry for a new accounting document, it will be appended to this list.
This list is usually emptied after the entries have been written into an XML document.
type: list of
Entry
-
__init__()¶ Initializes the generator.
-
generate_entry(acc_doc)¶ Generates the accounting entry from the
acc_docdocument and adds it to the list in this class.Parameters: acc_doc ( GenericAccountingDoc) – Accounting document from which the accounting entry will be generated.
-
reset_entries()¶ Erases all the previously generated entries and starts with a new empty list of entries.
-
write_entries_in_xml(xml_file, encoding=u'UTF-8')¶ Exports the generated accounting entries in an XML file.
Parameters: - xml_file – Name of the file where the accounting entries will be exported to.
- encoding (
str) – Encoding used to write the XML file.
-
utils module¶
pybill.lib.accounting.utils module contains some useful constants and the
basic classes used in the accounting entries generation.
The constants are used to designate the various account numbers used in the accounting entries generation. These account numbers are stored in a dictionary defined in each PyBill accounting entity.
-
pybill.lib.accounting.utils.CLIENT= u'Client'¶ Constant used to designate, in the dictionaries, the account number of the Client account used for an accounting document.
type:
unicode
-
pybill.lib.accounting.utils.CLIENT_HOLDBACK= u'Client Holdback'¶ Constant used to designate, in the dictionaries, the account number of the Client Holdback account used for an accounting document.
type:
unicode
-
pybill.lib.accounting.utils.PRODUCT= u'Product'¶ Constant used to designate, in the dictionaries, the account number of the Product account used for an accounting document.
type:
unicode
-
pybill.lib.accounting.utils.VAT= u'VAT'¶ Constant used to designate, in the dictionaries, the account number of the VAT account used for an accounting document.
type:
unicode
The basic class describes an accounting entry.
-
class
pybill.lib.accounting.utils.Entry(date, explanation)¶ Little class representing an accounting entry.
This entry is quite basic and contains only a date, an explanation, a list of debits and a list of credits.
-
date¶ Attribute containing the date of the entry.
type:
datetime.date
-
explanation¶ Attribute containing the explanation of the entry.
type:
unicode
-
credits¶ Attribute containing a dictionary of account numbers (dictionary keys) associated with the amounts (floats) that must be credited on these accounts.
type: dictionary of
floatindexed byunicodekeys
-
debits¶ Attribute containing a dictionary of account numbers (dictionary keys) associated with the amounts (floats) that must be debited on these accounts.
type: dictionary of
floatindexed byunicodekeys
-
__init__(date, explanation)¶ Initializes a new accounting entry.
Parameters: - date (
datetime.date) – Date of the entry. - explanation (
unicode) – Explanation of the entry
- date (
-
add_movement(account_number, amount)¶ Adds a movement of
amounton the account whose number isaccount_number.If the amount is positive, the account will be credited, else the account will be debited.
Parameters: - account_number (
unicode) – Number of the accounting account that will be credited or debited in this entry. - amount (
float) – Amount of the movement on the accountaccount_number. If the amount is positive, the account is credited, else it is debited.
- account_number (
-
check()¶ Checks the accounting entry.
That’s to say, checks if the sum of the debits is equal to the sum of the credits. Raises an exception if it’s not the case.
-