def withdraw_from_member_account_update(self, member, updated_amount, refs, date=None): tx = Transaction.objects.get_by_reference(refs).get(kind=GasAccountingProxy.GAS_WITHDRAWAL) if tx: # WARNING: if you update a transaction, you will lose old transaction info. Use with care! update_transaction(tx, amount=updated_amount, date=date) return True return False
def pay_supplier_order(self, order, amount, refs=None, descr=None, date=None, multiple=None): """ Register the payment of a supplier order. 1 Control if not yet exist a payment for this order 2 Control if Total amounted for Members are equal or not. If not compense the difference automaticaly? Ask to the comunity. For the moment do nothing. """ # Specifically, such registration is a two-step process: # 1. First, the GAS withdraws from each member's account an amount of money corresponding # to the total cost of products (s)he bought during this order # (price & quantity are as recorded by the invoice!) # 2. Then, the GAS collects this money amounts and transfers them to the supplier's account # If the given supplier order hasn't been fully withdrawn by GAS members yet, raise ``MalformedTransaction``. # from gasistafelice.gas.models import GASSupplierOrder # # FIXME: adapt to "Gasista Felice"'s workflow model # if order.status == GASSupplierOrder.WITHDRAWN: # ## bill members for their orders to the GAS # # only members participating to this order need to be billed # for member in order.purchasers: # # calculate amount to bill to this GAS member for orders (s)he issued # # w.r.t. the given supplier order # member_order_bill = 0 # issued_member_orders = member.issued_orders.filter(ordered_product__order=order) # for member_order in issued_member_orders: # price = member_order.ordered_product.delivered_price # quantity = member_order.withdrawn_amount # member_order_bill += price * quantity # self.withdraw_from_member_account(member, member_order_bill) ## pay supplier # self.pay_supplier(pact=order.pact, amount=order.total_amount) # else: # raise MalformedTransaction("Only fully withdrawn supplier orders are eligible to be payed") #retrieve existing payment if not refs: refs = [order] yet_payed, description, date_payed = self.get_supplier_order_data(order, refs) #Insolute aggregated payment contain many orders that are payed in simultaneous. Refs must be a list of each order that are relative to this unique transaction if yet_payed <= 0: # pay supplier self.pay_supplier(order=order, amount=amount, refs=refs, descr=descr, date=date, multiple=multiple) elif yet_payed != amount: tx = self.get_supplier_order_transaction(order, refs) if tx: #FIXME: something wrong. The old transaction is deleted and the new one loose refs #simple accounting: transaction.ledger_entries.delete() but do not recreate the link to the original refs that permit to retrieve the transaction itself finding by order. see: get_supplier_order_data update_transaction(tx, amount=amount)
def withdraw_from_member_account_update(self, member, updated_amount, refs, date=None): """ WARNING: if you use this method you lose history of updates """ tx = Transaction.objects.get_by_reference(refs).get( kind=GasAccountingProxy.GAS_WITHDRAWAL) if tx: # WARNING: if you update a transaction, you will lose old transaction info. Use with care! update_transaction(tx, amount=updated_amount, date=date) return True return False
def pay_supplier_order(self, order, amount, refs=None, descr=None, date=None, multiple=None): """ Register the payment of a supplier order. 1 Control if not yet exist a payment for this order 2 Control if Total amounted for Members are equal or not. If not compense the difference automaticaly? Ask to the comunity. For the moment do nothing. """ # Specifically, such registration is a two-step process: # 1. First, the GAS withdraws from each member's account an amount of money corresponding # to the total cost of products (s)he bought during this order # (price & quantity are as recorded by the invoice!) # 2. Then, the GAS collects this money amounts and transfers them to the supplier's account # If the given supplier order hasn't been fully withdrawn by GAS members yet, raise ``MalformedTransaction``. # from gf.gas.models import GASSupplierOrder # # FIXME: adapt to "Gasista Felice"'s workflow model # if order.status == GASSupplierOrder.WITHDRAWN: # ## bill members for their orders to the GAS # # only members participating to this order need to be billed # for member in order.purchasers: # # calculate amount to bill to this GAS member for orders (s)he issued # # w.r.t. the given supplier order # member_order_bill = 0 # issued_member_orders = member.issued_orders.filter(ordered_product__order=order) # for member_order in issued_member_orders: # price = member_order.ordered_product.delivered_price # quantity = member_order.withdrawn_amount # member_order_bill += price * quantity # self.withdraw_from_member_account(member, member_order_bill) ## pay supplier # self.pay_supplier(pact=order.pact, amount=order.total_amount) # else: # raise MalformedTransaction("Only fully withdrawn supplier orders are eligible to be payed") #retrieve existing payment if not refs: refs = [order] yet_payed, description, date_payed = self.get_supplier_order_data( order, refs) #Insolute aggregated payment contain many orders that are payed in simultaneous. Refs must be a list of each order that are relative to this unique transaction if yet_payed <= 0: # pay supplier self.pay_supplier(order=order, amount=amount, refs=refs, descr=descr, date=date, multiple=multiple) elif yet_payed != amount: tx = self.get_supplier_order_transaction(order, refs) if tx: #FIXME: something wrong. The old transaction is deleted and the new one loose refs #simple accounting: transaction.ledger_entries.delete() but do not recreate the link to the original refs that permit to retrieve the transaction itself finding by order. see: get_supplier_order_data update_transaction(tx, amount=amount)