<commit_before>ASSOCIATIONS =
    uom_choices: { collection: "Uom", options: ->
        with: {for_sku_loc: @sku_loc_id}, query: {}
    }
    sku_choices: { collection: "Sku", options: ->
        with: {in_location: @location_id}, query: {}
        include: ['sku_locs', 'uoms']
    }
    sku:         { model: "Sku"    }
    uom:         { model: "Uom"    }
    sku_loc:     { model: "SkuLoc" }


DERIVED =
    total:  deps: ['qty', 'price'], fn: ->
        @qty ||= 0
        @price  ||= 0
        _.bigDecimal(@qty * @price)

Skr.Models.Mixins.SkuLine = {

    included: (klass) ->
        _.extend( klass::derived ||= {},      DERIVED)
        _.extend( klass::associations ||= {}, ASSOCIATIONS)

    initialize: ->
        @on('change:sku', @onSkuChange)
        @on('change:uom', @onUomChange)
        @on('change:location_id', @onLocationChange)
        @uom_choices.on("add", @onUomsLoad, this)
        @uom.size = @uom_size
        @uom.code = @uom_code

    onLocationChange: ->
        if @location_id
            @sku_choices.options.with.in_location = @location_id

    onUomsLoad: ->
        uom = this.uom_choices.findWhere(size: @uom_size, code: @uom_code)
        this.uom.set( uom.serialize() ) if uom

    onSkuChange: ->
        return unless @sku
        sl = @sku.sku_locs.findWhere(sku_id: @sku.id)
        if sl<commit_msg>set uom attributes before adding event listener<commit_after>ASSOCIATIONS =
    uom_choices: { collection: "Uom", options: ->
        with: {for_sku_loc: @sku_loc_id}, query: {}
    }
    sku_choices: { collection: "Sku", options: ->
        with: {in_location: @location_id}, query: {}
        include: ['sku_locs', 'uoms']
    }
    sku:         { model: "Sku"    }
    uom:         { model: "Uom"    }
    sku_loc:     { model: "SkuLoc" }


DERIVED =
    total:  deps: ['qty', 'price'], fn: ->
        @qty ||= 0
        @price  ||= 0
        _.bigDecimal(@qty * @price)

Skr.Models.Mixins.SkuLine = {

    included: (klass) ->
        _.extend( klass::derived ||= {},      DERIVED)
        _.extend( klass::associations ||= {}, ASSOCIATIONS)

    initialize: ->
        @uom.size = @uom_size
        @uom.code = @uom_code
        @on('change:sku', @onSkuChange)
        @on('change:uom', @onUomChange)
        @on('change:location_id', @onLocationChange)
        @uom_choices.on("add", @onUomsLoad, this)

    onLocationChange: ->
        if @location_id
            @sku_choices.options.with.in_location = @location_id

    onUomsLoad: ->
        uom = this.uom_choices.findWhere(size: @uom_size, code: @uom_code)
        this.uom.set( uom.serialize() ) if uom

    onSkuChange: ->
        return unless @sku
        sl = @sku.sku_locs.findWhere(sku_id: @sku.id)
        if sl
{'fraction_non_alphanumeric': 0.15762463343108504, 'fraction_numerical': 0.001466275659824047, 'mean_word_length': 2.2449464922711058, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6873878', 'n_tokens_mistral': 1042, 'n_tokens_neox': 1023, 'n_words': 181}