Set Invoice Date

Questions about and code samples for custom order rules and validation within Select.
Post Reply
bdutil
Posts: 121
Joined: Tue Jul 19, 2016 1:48 pm

Set Invoice Date

Post by bdutil »

Can't get this to work if the field it's looking to is blank. Should just run default rule but it's returning an 'Expected Int64, got NoneType' Error.

def Invoice_Date_Value(args):

invoice = args.Context
order = args.Context.Root

if not invoice:
return

# Get the value for the Custom Fields
AddRevDate = Date(IOrderItem.GetProperty(invoice, 'AddlRevDate_#'))


if IOrderItem.GetProperty(invoice, 'AddlRevDate_#') is not None:
args.Value = AddRevDate

else:
args.RunDefaultRule()
BobRichards
Posts: 1376
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: Set Invoice Date

Post by BobRichards »

The part generating the error was passing a None to Date(...). You got the AddRevDate from the custom field and that is what should have been in the if expression. Also, you never need to check if the Context is None - it can never be None.

Code: Select all

def Invoice_Date_Value(args):

    # Get the date from the Custom Field
    invoice = args.Context
    AddRevDate = IOrderItem.GetProperty(invoice, 'AddlRevDate_#')
    
    # If we got a date, use it.  Otherwise run Select rules.
    if AddRevDate is not None:
        args.Value = Date(AddRevDate)
    else:
        args.RunDefaultRule())
Bob Richards, Senior Software Developer, SoftPro
Post Reply