from System import *
from Kingdee.BOS import *
from Kingdee.BOS.DataEntity import *

def OnPrepareNotePrintData(e):
    if e.NotePrintTplId.Equals("e02063aa-b4b6-4095-8a9d-f569bdf3f90a"):
        if e.DataSourceId.Equals("FQUOTATIONENTRY",StringComparison.OrdinalIgnoreCase):
            seqKey = "FQUOTATIONENTRY" + "_" + "FSeq";
            materialKey = "FMaterialId_FNumber";
            if e.DataObjects == None or e.DataObjects.Length <= 0 or not e.DataObjects[0].DynamicObjectType.Properties.ContainsKey(materialKey):
                return;
            rowMaterialSeq = {};
            for index in range(len(e.DataObjects)):
                material = e.DataObjects[index][materialKey];
                if not rowMaterialSeq.has_key(material):
                    rowMaterialSeq[material] = e.DataObjects[index][seqKey];
            tempList = sorted(e.DataObjects,key =lambda x:(rowMaterialSeq[x[materialKey]], x[seqKey]));
            for index in range(len(tempList)):
                e.DataObjects[index] = tempList[index];
