This question has been flagged
5 Replies
2606 Views

Hello,


Ive been using a cost distribution module for landing costs and it results in an incorrect final cost.  Ive determined that the problem is not its calculation of the landed cost but rather the part where it combines that new landed cost with the existing cost in inventory.  This is the function that does that but Im not sure what some variables refer to.  Specifically I mean:

1. qty_available = product.product_tmpl_id.qty_available = does this refer to the entering qty, existing qty or something else?

2. Why would it subtract the move.product_qty from the qty_available? Oh so the above is the total qty available because the PO has already been processed so if we had 5 and bought 10, the qty_available is already 15!  So qty_available is total in new inventory such that product_avail is the existing stock.

3. So if existing stock is <= 0, then it just sets the new landed cost, else it must merge the values

4. what does variant._sum_remaining_values()[0] refer to?  Obviously its a function that returns all array elements starting a 0 for each product in variant ids.  But what does _remaining_values refer to?  It would have to be qty*actual cost, right?

5. The new_std_price = (current inventory value+(incoming inventory))/qty_available)


def _product_price_update(self, move, new_price):

        if (move.location_id.usage == 'supplier' and move.product_id.cost_method == 'average'):

            product = move.product_id

            qty_available = product.product_tmpl_id.qty_available

            product_avail = qty_available - move.product_qty

            if product_avail <= 0:

                new_std_price = new_price

            else:

                # current_valuation = sum([variant._sum_remaining_values()[0] for variant in product.product_tmpl_id.product_variant_ids])

                # new_std_price = ((current_valuation + new_price * move.product_qty) / qty_available)

                new_std_price = new_price

            product.sudo().write({'standard_price': new_std_price})


Please help with these variables.

Avatar
Discard
Author

for some reason i get 403 forbidden error if i use the "code" format around the code

Author

Yes I know it's possible and I did that but when I try to post I get a forbidden error. It only let's me post if I don't have code format

Maybe you don't have enough "Karma" or xp to do that. The workings of this forum can be a bit mysterious.

Author

I have 296 xp and quite a few badges