I was looking at an example Rule that set the Invoice Number based on the Order Number and the str(args.Context.Position). The only issue with this is that the Invoice Number will change if an invoice is deleted causing the position to change.
One possibility is to condition the rule to return before changing the Invoice Number if the Number is already set.
Code: Select all
def Invoice_Number_Value(args): # Run Default Rules ifn Invoice Number already set. if args.Context.Number is not None: args.RunDefaultRule() return # Set the Invoice Number based on the Order Nubmer and Position of the invoice. args.Value = args.Context.Root.Number + '-' + str(args.Context.Position)
What I was hoping we might be able to do is as follows:
1. Add a Hidden Custom Field to the Order Context that will be used to store the last Sequence Number Assigned for each invoice. (Each time a new invoice is created this value will be increased by one.) "Order.LastInvoiceSeq##"
2. Also, add a Custom Field to the Invoice Context that will be used to store the Sequence Number generated and assigned to each Invoice created. A rule will be created for the Invoice Level Custom Field, that hopefully can call a Static Method defined in a Class, to first increment the Order.LastInvoiceSeq## by one, when the Invoice Level field is empty and then store this value in the Invoice Level Custom Field. "Order.Invoices.InvoiceSeq##" Because the rule would be conditioned to not run when a value is assigned, it would remain the same value no matter what position it became.
3. Then the rule used to assign the Invoice Number would be designed to use the "Order.Invoices.InvoiceSeq##" instead of the Invoice Position.
In theory, this should provide unique Invoice Numbering that does not reset based on the position of the invoice and would retain the sequence number assigned to it even if the user messes with the invoice number field.
I am just not sure how to wrap the change of the Overall Order.LastInvoiceSeq## field up in a Class that is only called when the Invoice Level Custom Field is Empty.
Code: Select all
def Invoice_Number_Value(args): # Run Default Rules if Invoice Number already set. if args.Context.Number is not None: args.RunDefaultRule() return order = args.Context.Root # Set the Invoice Number using Order Nubmer and Next Invoice Sequence args.Value = args.Context.Root.Number + '-' + IOrderItem.GetProperty(order, 'LastInvoiceSeq##') def Invoice_InvoiceSeq_Value(args): """ Set InvoiceSeq## Custom Field based on Custom Field LastInvoiceSeq## """ args.Value = ClassName.GetNextInvoiceNubmer() # This would be the class and method the returns the value from the Master Seqence. # Redefine Custom Field Rule names Invoice_InvoiceSeq_Value.__name__ = "Order_Invoice_InvoiceSeq##_Value"
Thank you for any information you may be able to provide.