def do_recharge(self, gas, amount, note="", date=None): """ Do a recharge of amount ``amount`` to the corresponding member account in the GAS ``gas``. If this person is not a member of GAS ``gas``, or if ``amount`` is a negative number a ``MalformedTransaction`` exception is raised. """ person = self.subject.instance if amount < 0: raise MalformedTransaction(ugettext("Amount of a recharge must be non-negative")) elif not person.has_been_member(gas): raise MalformedTransaction(ugettext("A person can't make an account recharge for a GAS that (s)he is not member of")) else: source_account = self.system['/wallet'] exit_point = self.system['/expenses/gas/' + gas.uid + '/recharges'] entry_point = gas.accounting.system['/incomes/recharges'] target_account = gas.accounting.system['/members/' + person.uid] description = unicode(person.report_name) issuer = self.subject if not date: date = datetime.now() #_date.today transaction = register_transaction(source_account, exit_point, entry_point, target_account, amount, description, issuer, date, 'RECHARGE' ) transaction.add_references([person, gas])
def do_recharge(self, gas, amount): """ Do a recharge of amount ``amount`` to the corresponding member account in the GAS ``gas``. If this person is not a member of GAS ``gas``, or if ``amount`` is a negative number, a ``MalformedTransaction`` exception is raised. """ person = self.subject.instance if amount < 0: raise MalformedTransaction( "Amount of a recharge must be non-negative") elif not person.is_member(gas): raise MalformedTransaction( "A person can't make an account recharge for a GAS that (s)he is not member of" ) else: source_account = self.system['/wallet'] exit_point = self.system['/expenses/gas/' + gas.uid + '/recharges'] entry_point = gas.accounting.system['/incomes/recharges'] target_account = gas.accounting.system['/members/' + person.uid] description = "GAS member account recharge" issuer = person transaction = register_transaction(source_account, exit_point, entry_point, target_account, amount, description, issuer, kind='RECHARGE') transaction.add_references([person, gas])
def pay_supplier(self, pact, amount, refs=None): """ Transfer a given (positive) amount ``amount`` of money from the GAS's cash to a supplier for which a solidal pact is currently active. If ``amount`` is negative, a ``MalformedTransaction`` exception is raised (supplier-to-GAS money transfers should be treated as "refunds"). References for this transaction may be passed as the ``refs`` argument (e.g. a list of supplier orders this payment is related to). """ if amount < 0: raise MalformedTransaction("Payment amounts must be non-negative") gas = self.subject.instance supplier = pact.supplier source_account = self.system['/cash'] exit_point = self.system['/expenses/suppliers/' + supplier.uid] entry_point = supplier.accounting.system['/incomes/gas/' + gas.uid] target_account = supplier.accounting.system['/wallet'] description = "Payment from GAS %(gas)s to supplier %(supplier)s" % { 'gas': gas, 'supplier': supplier, } issuer = gas transaction = register_transaction(source_account, exit_point, entry_point, target_account, amount, description, issuer, kind='PAYMENT') if refs: transaction.add_references(refs)
def pay_membership_fee(self, gas, year): """ Pay the annual membership fee for a GAS this person is member of. Fee amount is determined by the ``gas.membership_fee`` attribute. If this person is not a member of GAS ``gas``, a ``MalformedTransaction`` exception is raised. """ person = self.subject.instance if not person.is_member(gas): raise MalformedTransaction( "A person can't pay membership fees to a GAS that (s)he is not member of" ) source_account = self.system['/wallet'] exit_point = self.system['/expenses/gas/' + gas.uid + '/fees'] entry_point = gas.accounting.system['/incomes/fees'] target_account = gas.accounting.system['/cash'] amount = gas.membership_fee description = "Membership fee for year %(year)s" % { 'year': year, } issuer = person transaction = register_transaction(source_account, exit_point, entry_point, target_account, amount, description, issuer, kind='MEMBERSHIP_FEE') transaction.add_references([person, gas])
def pay_supplier(self, order, amount, refs=None, descr=None, date=None, multiple=None): """ Transfer a given (positive) amount ``amount`` of money from the GAS's cash to a supplier for which a solidal pact is currently active. If ``amount`` is negative, a ``MalformedTransaction`` exception is raised (supplier-to-GAS money transfers should be treated as "refunds"). References for this transaction may be passed as the ``refs`` argument (e.g. a list of supplier orders this payment is related to). """ if amount < 0: raise MalformedTransaction(ugettext(u"Payment amounts must be non-negative")) gas = self.subject.instance supplier = order.supplier source_account = self.system['/cash'] exit_point = self.system['/expenses/suppliers/' + supplier.uid] entry_point = supplier.accounting.system['/incomes/gas/' + gas.uid] target_account = supplier.accounting.system['/wallet'] if multiple: description = "Ord. %s" % multiple description += " %(pact)s" % {'pact': order.pact,} else: description = order.common_name if descr: description += ". %s" % descr.replace(description + ". ", "") issuer = self.subject transaction = register_transaction(source_account, exit_point, entry_point, target_account, amount, description, issuer, date, 'PAYMENT' ) if refs: transaction.add_references(refs)
def do_recharge(self, gas, amount, note="", date=None): """ Do a recharge of amount ``amount`` to the corresponding member account in the GAS ``gas``. If this person is not a member of GAS ``gas``, or if ``amount`` is a negative number a ``MalformedTransaction`` exception is raised. """ person = self.subject.instance if amount < 0: raise MalformedTransaction( ugettext("Amount of a recharge must be non-negative")) elif not person.has_been_member(gas): raise MalformedTransaction( ugettext( "A person can't make an account recharge for a GAS that (s)he is not member of" )) else: source_account = self.system['/wallet'] exit_point = self.system['/expenses/gas/' + gas.uid + '/recharges'] entry_point = gas.accounting.system['/incomes/recharges'] target_account = gas.accounting.system['/members/' + person.uid] description = unicode(person.report_name) issuer = self.subject if not date: date = datetime.now() #_date.today transaction = register_transaction(source_account, exit_point, entry_point, target_account, amount, description, issuer, date, 'RECHARGE') transaction.add_references([person, gas])
def refund_gas(self, gas, amount, refs=None): """ Refund a given ``amount`` of money to a GAS for which a solidal pact is currently active. If GAS ``gas`` doesn't have an active solidal pact with this supplier, or if ``amount`` is negative, raise a ``MalformedTransaction`` exception. References for this transaction may be passed as the ``refs`` argument (e.g. a list of supplier orders this refund is related to). """ if amount < 0: raise MalformedTransaction("Refund amounts must be non-negative") supplier = self.subject.instance if supplier not in gas.suppliers: msg = "An active solidal pact must be in place between a supplier and the GAS (s)he is refunding" raise MalformedTransaction(msg) source_account = self.system['/wallet'] exit_point = self.system['/incomes/gas/' + gas.uid] entry_point = gas.accounting.system['/expenses/suppliers/' + supplier.uid] target_account = gas.accounting.system['/cash'] description = "Refund from supplier %(supplier)s to GAS %(gas)s" % {'gas': gas, 'supplier': supplier,} issuer = supplier transaction = register_transaction(source_account, exit_point, entry_point, target_account, amount, description, issuer, kind='REFUND') if refs: transaction.add_references(refs)
def extra_operation(self, gas, amount, target, causal, date): """ Another account operation for this subject For a GASMEMBER the target operation can be income or expense operation The operation can implicate a GAS economic change """ if amount < 0: raise MalformedTransaction(ugettext("Payment amounts must be non-negative")) person = self.subject.instance if not person.has_been_member(gas): raise MalformedTransaction(ugettext("A person can't pay membership fees to a GAS that (s)he is not member of")) gas_acc = gas.accounting gas_system = gas.accounting.system kind = GASMEMBER_GAS if target == INCOME: #Correction for gasmember: +gasmember -GAS source_account = gas_system['/cash'] exit_point = gas_system['/expenses/member'] entry_point = gas_system['/incomes/recharges'] target_account = gas_system['/members/' + person.uid] elif target == EXPENSE: #Correction for GAS: +GAS -gasmember source_account = gas_system['/members/' + person.uid] exit_point = gas_system['/expenses/gas'] entry_point = gas_system['/incomes/member'] target_account = gas_system['/cash'] elif target == ASSET: #Detraction for Gasmember: -gasmember source_account = gas_system['/members/' + person.uid] exit_point = gas_system['/expenses/member'] entry_point = self.system['/incomes/other'] target_account = self.system['/wallet'] kind = ADJUST elif target == LIABILITY: #Addition for Gasmember: +gasmember source_account = self.system['/wallet'] exit_point = self.system['/expenses/other'] entry_point = gas_system['/incomes/recharges'] target_account = gas_system['/members/' + person.uid] kind = ADJUST elif target == EQUITY: #Restitution for gasmember: empty container +gasmember -GAS source_account = gas_system['/cash'] exit_point = gas_system['/expenses/member'] entry_point = gas_system['/incomes/recharges'] target_account = gas_system['/members/' + person.uid] kind = RECYCLE else: raise MalformedTransaction(ugettext("Payment target %s not identified") % target) description = "%(gas)s %(target)s %(causal)s" % { 'gas': gas.id_in_des, 'target': target, 'causal': causal } issuer = self.subject if not date: date = datetime.now() #_date.today transaction = register_transaction(source_account, exit_point, entry_point, target_account, amount, description, issuer, date, kind)
def extra_operation(self, gas, pact, amount, target, causal, date): """ Another account operation for this subject For a Supplier the target operation can be income or expense operation with GAS """ if amount < 0: raise MalformedTransaction( _("Payment amounts must be non-negative")) if amount < 0: raise MalformedTransaction( _("Refund amounts must be non-negative")) supplier = self.subject.instance if supplier not in gas.suppliers: msg = _( "An active solidal pact must be in place between a supplier and the GAS (s)he is refunding" ) raise MalformedTransaction(msg) gas_acc = gas.accounting gas_system = gas.accounting.system #Correzione a favore del GAS: +GAS -fornitore if target == EXPENSE: #+GAS -Supplier #UGLY: remove me when done and executed one command that regenerate all missing accounts self.missing_accounts(gas) source_account = self.system['/wallet'] exit_point = self.system['/expenses/gas/' + gas.uid] entry_point = gas_system['/incomes/suppliers/' + supplier.uid] target_account = gas_system['/cash'] #Correzione a favore del fornitore: +fornitore -GAS elif target == INCOME: #+Supplier -GAS source_account = gas_system['/cash'] exit_point = gas_system['/expenses/suppliers/' + supplier.uid] entry_point = self.system['/incomes/gas/' + gas.uid] target_account = self.system['/wallet'] else: raise MalformedTransaction( _("Payment target %s not identified") % target) description = "%(pact)s %(target)s %(causal)s" % { 'pact': pact, 'target': target, 'causal': causal } issuer = self.subject kind = PACT_EXTRA if not date: date = datetime.now() #_date.today transaction = register_transaction(source_account, exit_point, entry_point, target_account, amount, description, issuer, date, kind)
def extra_operation(self, gas, pact, amount, target, causal, date): """ Another account operation for this subject For a Supplier the target operation can be income or expense operation with GAS """ if amount < 0: raise MalformedTransaction(_("Payment amounts must be non-negative")) if amount < 0: raise MalformedTransaction(_("Refund amounts must be non-negative")) supplier = self.subject.instance if supplier not in gas.suppliers: msg = _("An active solidal pact must be in place between a supplier and the GAS (s)he is refunding") raise MalformedTransaction(msg) gas_acc = gas.accounting gas_system = gas.accounting.system #Correzione a favore del GAS: +GAS -fornitore if target == EXPENSE: #+GAS -Supplier #UGLY: remove me when done and executed one command that regenerate all missing accounts self.missing_accounts(gas) source_account = self.system['/wallet'] exit_point = self.system['/expenses/gas/' + gas.uid] entry_point = gas_system['/incomes/suppliers/' + supplier.uid] target_account = gas_system['/cash'] #Correzione a favore del fornitore: +fornitore -GAS elif target == INCOME: #+Supplier -GAS source_account = gas_system['/cash'] exit_point = gas_system['/expenses/suppliers/' + supplier.uid] entry_point = self.system['/incomes/gas/' + gas.uid] target_account = self.system['/wallet'] else: raise MalformedTransaction(_("Payment target %s not identified") % target) description = "%(pact)s %(target)s %(causal)s" % { 'pact': pact, 'target': target, 'causal': causal } issuer = self.subject kind = PACT_EXTRA if not date: date = datetime.now() #_date.today transaction = register_transaction(source_account, exit_point, entry_point, target_account, amount, description, issuer, date, kind)
def extra_operation(self, amount, target, causal, date): """ Another account operation for this subject For a GAS the target operation can be income or expense operation """ if amount < 0: raise MalformedTransaction( ugettext("Payment amounts must be non-negative")) gas = self.subject.instance non_des = self.get_non_des_accounting() if not non_des: raise Person.DoesNotExist non_des_system = non_des.system if target == INCOME: source_account = non_des_system['/wallet'] exit_point, created = non_des_system.get_or_create_account( '/expenses', 'OutOfDES', account_type.expense) entry_point = self.system['/incomes/OutOfDES'] target_account = self.system[ '/cash'] #WAS gas.accounting.system['/cash'] elif target == EXPENSE: source_account = self.system['/cash'] exit_point = self.system['/expenses/OutOfDES'] entry_point, created = non_des_system.get_or_create_account( '/incomes', 'OutOfDES', account_type.income) target_account = non_des_system['/wallet'] else: #WAS raise MalformedTransaction(ugettext("Payment target %s not identified" % target)) #coercing to Unicode: need string or buffer, __proxy__ found raise MalformedTransaction( ugettext("Payment target %s not identified") % target) description = "%(gas)s %(target)s %(causal)s" % { 'gas': gas.id_in_des, 'target': target, 'causal': causal } #WAS raise description = ugettext("%(gas)s %(target)s %(causal)s") % { ... #WAS exceptions must be old-style classes or derived from BaseException, not unicode issuer = self.subject kind = GAS_EXTRA if not date: date = datetime.datetime.now() #_date.today # transaction = register_simple_transaction(source_account, target_account, amount, description, issuer, date=date, kind=kind) transaction = register_transaction(source_account, exit_point, entry_point, target_account, amount, description, issuer, date, kind)
def pay_supplier(self, order, amount, refs=None, descr=None, date=None, multiple=None): """ Transfer a given (positive) amount ``amount`` of money from the GAS's cash to a supplier for which a solidal pact is currently active. If ``amount`` is negative, a ``MalformedTransaction`` exception is raised (supplier-to-GAS money transfers should be treated as "refunds"). References for this transaction may be passed as the ``refs`` argument (e.g. a list of supplier orders this payment is related to). """ if amount < 0: raise MalformedTransaction( ugettext(u"Payment amounts must be non-negative")) gas = self.subject.instance supplier = order.supplier source_account = self.system['/cash'] exit_point = self.system['/expenses/suppliers/' + supplier.uid] entry_point = supplier.accounting.system['/incomes/gas/' + gas.uid] target_account = supplier.accounting.system['/wallet'] if multiple: description = "Ord. %s" % multiple description += " %(pact)s" % { 'pact': order.pact, } else: description = order.common_name if descr: description += ". %s" % descr.replace(description + ". ", "") issuer = self.subject transaction = register_transaction(source_account, exit_point, entry_point, target_account, amount, description, issuer, date, 'PAYMENT') if refs: transaction.add_references(refs)
def extra_operation(self, amount, target, causal, date): """ Another account operation for this subject For a GAS the target operation can be income or expense operation """ if amount < 0: raise MalformedTransaction(ugettext("Payment amounts must be non-negative")) gas = self.subject.instance non_des = self.get_non_des_accounting() if not non_des: raise Person.DoesNotExist non_des_system = non_des.system if target == INCOME: source_account = non_des_system['/wallet'] exit_point, created = non_des_system.get_or_create_account('/expenses', 'OutOfDES', account_type.expense) entry_point = self.system['/incomes/OutOfDES'] target_account = self.system['/cash'] #WAS gas.accounting.system['/cash'] elif target == EXPENSE: source_account = self.system['/cash'] exit_point = self.system['/expenses/OutOfDES'] entry_point, created = non_des_system.get_or_create_account('/incomes', 'OutOfDES', account_type.income) target_account = non_des_system['/wallet'] else: #WAS raise MalformedTransaction(ugettext("Payment target %s not identified" % target)) #coercing to Unicode: need string or buffer, __proxy__ found raise MalformedTransaction(ugettext("Payment target %s not identified") % target) description = "%(gas)s %(target)s %(causal)s" % { 'gas': gas.id_in_des, 'target': target, 'causal': causal } #WAS raise description = ugettext("%(gas)s %(target)s %(causal)s") % { ... #WAS exceptions must be old-style classes or derived from BaseException, not unicode issuer = self.subject kind = GAS_EXTRA if not date: date = datetime.datetime.now() #_date.today # transaction = register_simple_transaction(source_account, target_account, amount, description, issuer, date=date, kind=kind) transaction = register_transaction(source_account, exit_point, entry_point, target_account, amount, description, issuer, date, kind)
def pay_membership_fee(self, gas, year): """ Pay the annual membership fee for a GAS this person is member of. Fee amount is determined by the ``gas.membership_fee`` attribute. If this person is not a member of GAS ``gas``, a ``MalformedTransaction`` exception is raised. """ person = self.subject.instance if not person.is_member(gas): raise MalformedTransaction("A person can't pay membership fees to a GAS that (s)he is not member of") source_account = self.system['/wallet'] exit_point = self.system['/expenses/gas/' + gas.uid + '/fees'] entry_point = gas.accounting.system['/incomes/fees'] target_account = gas.accounting.system['/cash'] amount = gas.membership_fee description = "Membership fee for year %(year)s" % {'year': year,} issuer = person transaction = register_transaction(source_account, exit_point, entry_point, target_account, amount, description, issuer, kind='MEMBERSHIP_FEE') transaction.add_references([person, gas])
def do_recharge(self, gas, amount): """ Do a recharge of amount ``amount`` to the corresponding member account in the GAS ``gas``. If this person is not a member of GAS ``gas``, or if ``amount`` is a negative number, a ``MalformedTransaction`` exception is raised. """ person = self.subject.instance if amount < 0: raise MalformedTransaction("Amount of a recharge must be non-negative") elif not person.is_member(gas): raise MalformedTransaction("A person can't make an account recharge for a GAS that (s)he is not member of") else: source_account = self.system['/wallet'] exit_point = self.system['/expenses/gas/' + gas.uid + '/recharges'] entry_point = gas.accounting.system['/incomes/recharges'] target_account = gas.accounting.system['/members/' + person.uid] description = "GAS member account recharge" issuer = person transaction = register_transaction(source_account, exit_point, entry_point, target_account, amount, description, issuer, kind='RECHARGE') transaction.add_references([person, gas])
def refund_gas(self, gas, amount, refs=None): """ Refund a given ``amount`` of money to a GAS for which a solidal pact is currently active. If GAS ``gas`` doesn't have an active solidal pact with this supplier, or if ``amount`` is negative, raise a ``MalformedTransaction`` exception. References for this transaction may be passed as the ``refs`` argument (e.g. a list of supplier orders this refund is related to). """ if amount < 0: raise MalformedTransaction("Refund amounts must be non-negative") supplier = self.subject.instance if supplier not in gas.suppliers: msg = "An active solidal pact must be in place between a supplier and the GAS (s)he is refunding" raise MalformedTransaction(msg) source_account = self.system['/wallet'] exit_point = self.system['/incomes/gas/' + gas.uid] entry_point = gas.accounting.system['/expenses/suppliers/' + supplier.uid] target_account = gas.accounting.system['/cash'] description = "Refund from supplier %(supplier)s to GAS %(gas)s" % { 'gas': gas, 'supplier': supplier, } issuer = supplier transaction = register_transaction(source_account, exit_point, entry_point, target_account, amount, description, issuer, kind='REFUND') if refs: transaction.add_references(refs)
def pay_supplier(self, pact, amount, refs=None): """ Transfer a given (positive) amount ``amount`` of money from the GAS's cash to a supplier for which a solidal pact is currently active. If ``amount`` is negative, a ``MalformedTransaction`` exception is raised (supplier-to-GAS money transfers should be treated as "refunds"). References for this transaction may be passed as the ``refs`` argument (e.g. a list of supplier orders this payment is related to). """ if amount < 0: raise MalformedTransaction("Payment amounts must be non-negative") gas = self.subject.instance supplier = pact.supplier source_account = self.system['/cash'] exit_point = self.system['/expenses/suppliers/' + supplier.uid] entry_point = supplier.accounting.system['/incomes/gas/' + gas.uid] target_account = supplier.accounting.system['/wallet'] description = "Payment from GAS %(gas)s to supplier %(supplier)s" % {'gas': gas, 'supplier': supplier,} issuer = gas transaction = register_transaction(source_account, exit_point, entry_point, target_account, amount, description, issuer, kind='PAYMENT') if refs: transaction.add_references(refs)
def extra_operation(self, gas, amount, target, causal, date): """ Another account operation for this subject For a GASMEMBER the target operation can be income or expense operation The operation can implicate a GAS economic change """ if amount < 0: raise MalformedTransaction( ugettext("Payment amounts must be non-negative")) person = self.subject.instance if not person.has_been_member(gas): raise MalformedTransaction( ugettext( "A person can't pay membership fees to a GAS that (s)he is not member of" )) gas_acc = gas.accounting gas_system = gas.accounting.system kind = GASMEMBER_GAS #UGLY: remove me when done and executed one command that regenerate all missing accounts self.missing_accounts(gas) if target == INCOME: #Correction for gasmember: +gasmember -GAS source_account = gas_system['/cash'] exit_point = gas_system['/expenses/member'] entry_point = gas_system['/incomes/recharges'] target_account = gas_system['/members/' + person.uid] elif target == EXPENSE: #Correction for GAS: +GAS -gasmember source_account = gas_system['/members/' + person.uid] exit_point = gas_system['/expenses/gas'] entry_point = gas_system['/incomes/member'] target_account = gas_system['/cash'] elif target == ASSET: #Detraction for Gasmember: -gasmember source_account = gas_system['/members/' + person.uid] exit_point = gas_system['/expenses/member'] entry_point = self.system['/incomes/other'] target_account = self.system['/wallet'] kind = ADJUST elif target == LIABILITY: #Addition for Gasmember: +gasmember source_account = self.system['/wallet'] exit_point = self.system['/expenses/other'] entry_point = gas_system['/incomes/recharges'] target_account = gas_system['/members/' + person.uid] kind = ADJUST elif target == EQUITY: #Restitution for gasmember: empty container +gasmember -GAS source_account = gas_system['/cash'] exit_point = gas_system['/expenses/member'] entry_point = gas_system['/incomes/recharges'] target_account = gas_system['/members/' + person.uid] kind = RECYCLE else: raise MalformedTransaction( ugettext("Payment target %s not identified") % target) description = "%(gas)s %(target)s %(causal)s" % { 'gas': gas.id_in_des, 'target': target, 'causal': causal } issuer = self.subject if not date: date = datetime.now() #_date.today transaction = register_transaction(source_account, exit_point, entry_point, target_account, amount, description, issuer, date, kind)