[IMP] stock,mrp: improve populate
- Add BoM byproduct populate - small improvement for populate of stock location
This commit is contained in:
@@ -224,6 +224,43 @@ class MrpRoutingWorkcenter(models.Model):
|
||||
]
|
||||
|
||||
|
||||
class MrpBomByproduct(models.Model):
|
||||
_inherit = 'mrp.bom.byproduct'
|
||||
|
||||
_populate_sizes = {'small': 50, 'medium': 1_000, 'large': 5_000}
|
||||
_populate_dependencies = ['mrp.bom.line', 'mrp.routing.workcenter']
|
||||
|
||||
def _populate_factories(self):
|
||||
# Take a subset (50%) of bom to have some of then without any operation
|
||||
random = populate.Random('byproduct_subset_bom')
|
||||
boms_ids = self.env.registry.populated_models['mrp.bom']
|
||||
boms_ids = random.sample(boms_ids, int(len(boms_ids) * 0.5))
|
||||
|
||||
boms = self.env['mrp.bom'].search([('id', 'in', self.env.registry.populated_models['mrp.bom'])], order='sequence, product_id')
|
||||
|
||||
product_manu_ids = OrderedSet()
|
||||
for bom in boms:
|
||||
if bom.product_id:
|
||||
product_manu_ids.add(bom.product_id.id)
|
||||
else:
|
||||
for product_id in bom.product_tmpl_id.product_variant_ids:
|
||||
product_manu_ids.add(product_id.id)
|
||||
product_manu = self.env['product.product'].browse(product_manu_ids)
|
||||
# product_no_manu is products which don't have any bom (leaves in the BoM trees)
|
||||
product_no_manu = self.env['product.product'].browse(self.env.registry.populated_models['product.product']) - product_manu
|
||||
product_no_manu_ids = product_no_manu.ids
|
||||
|
||||
def get_product_uom_id(values, counter, random):
|
||||
return self.env['product.product'].browse(values['product_id']).uom_id.id
|
||||
|
||||
return [
|
||||
('bom_id', populate.iterate(boms_ids)),
|
||||
('product_id', populate.randomize(product_no_manu_ids)),
|
||||
('product_uom_id', populate.compute(get_product_uom_id)),
|
||||
('product_qty', populate.randint(1, 10)),
|
||||
]
|
||||
|
||||
|
||||
class MrpProduction(models.Model):
|
||||
_inherit = 'mrp.production'
|
||||
|
||||
|
||||
@@ -90,11 +90,11 @@ class Location(models.Model):
|
||||
depth = 1
|
||||
else:
|
||||
# Scenario 3 : one company with high depth location tree
|
||||
depth = 20
|
||||
depth = 10
|
||||
|
||||
nb_by_level = int(math.log(nb_loc_to_take, depth)) + 1 if depth > 1 else nb_loc_to_take # number of loc to put by level
|
||||
|
||||
_logger.info("Create locations (%d) tree for one warehouse - depth : %d, width : %d" % (nb_loc_to_take, depth, nb_by_level))
|
||||
_logger.info("Create locations (%d) tree for a warehouse (%s) - depth : %d, width : %d" % (nb_loc_to_take, warehouse.code, depth, nb_by_level))
|
||||
|
||||
# Root is the lot_stock_id of warehouse
|
||||
root = warehouse.lot_stock_id
|
||||
@@ -109,7 +109,7 @@ class Location(models.Model):
|
||||
children.append(loc_ids_by_company[company_id].pop())
|
||||
|
||||
child_locations = self.env['stock.location'].concat(*children)
|
||||
child_locations.location_id = parent
|
||||
child_locations.location_id = parent # Quite slow, because the ORM flush each time
|
||||
for child in child_locations:
|
||||
link_next_locations(child, level + 1)
|
||||
|
||||
@@ -119,7 +119,7 @@ class Location(models.Model):
|
||||
# Change 20 % the usage of some no-leaf location into 'view' (instead of 'internal')
|
||||
to_views = locations_sample.filtered_domain([('child_ids', '!=', [])]).ids
|
||||
random = populate.Random('stock_location_views')
|
||||
self.browse(random.sample(to_views, int(len(to_views) * 0.2))).usage = 'view'
|
||||
self.browse(random.sample(to_views, int(len(to_views) * 0.1))).usage = 'view'
|
||||
|
||||
return locations
|
||||
|
||||
|
||||
Reference in New Issue
Block a user