def ObjectModifiedEventHandler(instance, event):
    """ Various types need automation on edit.
    """
    if not hasattr(instance, 'portal_type'):
        return

    if instance.portal_type == 'Pricelist':
        """ Create price list line items
        """
        # Remove existing line items
        instance.pricelist_lineitems = []
        for p in instance.portal_catalog(portal_type=instance.getType(),
                                         is_active=True):
            obj = p.getObject()
            itemDescription = None
            itemAccredited = False
            if instance.getType() == "LabProduct":
                print_detail = ""
                if obj.getVolume():
                    print_detail = print_detail + str(obj.getVolume())
                if obj.getUnit():
                    print_detail = print_detail + str(obj.getUnit())
                if obj.getVolume() or obj.getUnit():
                    print_detail = " (" + print_detail + ")"
                    itemTitle = obj.Title() + print_detail
                else:
                    itemTitle = obj.Title()
                cat = None
                if obj.getPrice():
                    price = float(obj.getPrice())
                    totalprice = float(obj.getTotalPrice())
                    vat = totalprice - price
                else:
                    price = 0
                    totalprice = 0
                    vat = 0
            elif instance.getType() == "AnalysisService":

                if str(obj.getUnit()):
                    print_detail = " (" + str(obj.getUnit()) + ")"
                    itemTitle = obj.Title() + print_detail
                else:
                    itemTitle = obj.Title()
                itemAccredited = obj.getAccredited()

                cat = obj.getCategoryTitle()
                if instance.getBulkDiscount():
                    price = float(obj.getBulkPrice())
                    vat = get_vat_amount(price, obj.getVAT())
                    totalprice = price + vat
                else:
                    if instance.getBulkPrice():
                        discount = instance.getBulkPrice()
                        price = float(obj.getPrice())
                        price = apply_discount(price, discount)
                        vat = get_vat_amount(price, obj.getVAT())
                        totalprice = price + vat
                    elif obj.getPrice():
                        price = float(obj.getPrice())
                        vat = get_vat_amount(price, obj.getVAT())
                        totalprice = price + vat
                    else:
                        totalprice = 0
                        price = 0
                        vat = 0

            if instance.getDescriptions():
                itemDescription = obj.Description()

            li = PricelistLineItem()
            li["title"] = itemTitle
            li["ItemDescription"] = itemDescription
            li["CategoryTitle"] = cat
            li["Accredited"] = itemAccredited
            li["Subtotal"] = "%0.2f" % price
            li["VATAmount"] = "%0.2f" % vat
            li["Total"] = "%0.2f" % totalprice
            instance.pricelist_lineitems.append(li)
def ObjectModifiedEventHandler ( instance , event ) : if not hasattr ( instance , 'portal_type' ) : return if instance . portal_type == 'Pricelist' : instance . pricelist_lineitems = [ ] for p in instance . portal_catalog ( portal_type = instance . getType ( ) , is_active = True ) : obj = p . getObject ( ) itemDescription = None itemAccredited = False if instance . getType ( ) == "LabProduct" : print_detail = "" if obj . getVolume ( ) : print_detail = print_detail + str ( obj . getVolume ( ) ) if obj . getUnit ( ) : print_detail = print_detail + str ( obj . getUnit ( ) ) if obj . getVolume ( ) or obj . getUnit ( ) : print_detail = " (" + print_detail + ")" itemTitle = obj . Title ( ) + print_detail else : itemTitle = obj . Title ( ) cat = None if obj . getPrice ( ) : price = float ( obj . getPrice ( ) ) totalprice = float ( obj . getTotalPrice ( ) ) vat = totalprice - price else : price = 0 totalprice = 0 vat = 0 elif instance . getType ( ) == "AnalysisService" : if str ( obj . getUnit ( ) ) : print_detail = " (" + str ( obj . getUnit ( ) ) + ")" itemTitle = obj . Title ( ) + print_detail else : itemTitle = obj . Title ( ) itemAccredited = obj . getAccredited ( ) cat = obj . getCategoryTitle ( ) if instance . getBulkDiscount ( ) : price = float ( obj . getBulkPrice ( ) ) vat = get_vat_amount ( price , obj . getVAT ( ) ) totalprice = price + vat else : if instance . getBulkPrice ( ) : discount = instance . getBulkPrice ( ) price = float ( obj . getPrice ( ) ) price = apply_discount ( price , discount ) vat = get_vat_amount ( price , obj . getVAT ( ) ) totalprice = price + vat elif obj . getPrice ( ) : price = float ( obj . getPrice ( ) ) vat = get_vat_amount ( price , obj . getVAT ( ) ) totalprice = price + vat else : totalprice = 0 price = 0 vat = 0 if instance . getDescriptions ( ) : itemDescription = obj . Description ( ) li = PricelistLineItem ( ) li [ "title" ] = itemTitle li [ "ItemDescription" ] = itemDescription li [ "CategoryTitle" ] = cat li [ "Accredited" ] = itemAccredited li [ "Subtotal" ] = "%0.2f" % price li [ "VATAmount" ] = "%0.2f" % vat li [ "Total" ] = "%0.2f" % totalprice instance . pricelist_lineitems . append ( li )
Various types need automation on edit.