Skip to Content
Menu
This question has been flagged
I need help, I have the sale_order_lot_selection module installed in Odoo 12 Community, but I want to make it filter the lot stock in the location, the module already filters the lots by location but when capturing the name of the lot it shows an amount that is the total amount in that batch of all the locations, I want to be able to filter that information, I created a new field product_qty_2 in the model stock_production_lot for this purpose, but I can't manage to send the location to it

from odoo import api, fields, models

classSaleOrderLine(models.Model):   
    _inherit = 'sale.order.line'
    lot_id = fields.Many2one('stock.production.lot', 'Lot', domain="[('x_estado', '=', '1')]", copy=False)
   
    @api.multi   
    @api.onchange('product_id')   
    defproduct_id_change(self):       
        super(SaleOrderLine, self).product_id_change()
        self.lot_id = False

    @api.onchange('product_id')
    def_onchange_product_id_set_lot_domain(self):
        available_lot_ids = []
        ifself.order_id.warehouse_id andself.product_id:
            location = self.order_id.warehouse_id.lot_stock_id
            quants = self.env['stock.quant'].read_group([
                ('product_id', '=', self.product_id.id),
                ('location_id', 'child_of', location.id),
                ('quantity', '>', 0),
                ('lot_id', '!=', False),
            ], ['lot_id'], 'lot_id')
            available_lot_ids = [quant['lot_id'][0] forquantinquants]
        self.lot_id = False
        return {
            'domain': {'lot_id': [('id', 'in', available_lot_ids)]}
        }

    @api.onchange('lot_id')
    def_onchange_lot_id_set_lot_domain(self):
        available_lot_ids = []
        ifself.order_id.warehouse_id andself.product_id:
            location = self.order_id.warehouse_id.lot_stock_id
            quants = self.env['stock.quant'].read_group([
                ('product_id', '=', self.product_id.id),
                ('location_id', 'child_of', location.id),
                ('quantity', '>', 0),
                ('lot_id', '!=', False),
            ], ['lot_id'], 'lot_id')
            available_lot_ids = [quant['lot_id'][0] forquantinquants]
        return {
            'domain': {'lot_id': [('id', 'in', available_lot_ids)]}
        }

classstock_production_lot(models.Model):
    _inherit = 'stock.production.lot'

    product_qty_2 = fields.Float('Quantity', compute='_product_qty_2')

    @api.one
    def_product_qty_2(self):
        # We only care for the quants in internal or transit locations.
       quants = self.quant_ids.filtered(lambdaq: q.location_id.usage in ['internal', 'transit'])
        self.product_qty_2 = sum(quants.mapped('quantity'))
   
    @api.multi
    defname_get(self):
        res = []
        forrecordinself:
            lot_name = record.name or''
            lot_with_qty = lot_name + "- [" + str(record.product_qty) + " "+record.product_uom_id.name + "]"
             res.append((record.id, lot_with_qty))
        returnres
and thanks for all the help you can give me

.


Avatar
Discard
Related Posts Replies Views Activity
2
Nov 24
477
4
Feb 24
10165
1
Jan 24
370
0
May 23
831
4
Apr 23
38327