def _populate_factories(self): purchase_order_ids = self.env.registry.populated_models[ 'purchase.order'] product_ids = self.env.registry.populated_models['product.product'] def get_product_uom(values, counter, random): product = self.env['product.product'].browse(values['product_id']) return product.uom_id.id def get_date_planned(values, counter, random): po = self.env['purchase.order'].browse(values['order_id']) return po.date_planned return [ ('order_id', populate.iterate(purchase_order_ids)), ('name', populate.constant("PO-line-{counter}")), ('product_id', populate.randomize(product_ids)), ('product_uom', populate.compute(get_product_uom)), ('taxes_id', populate.constant(False) ), # to avoid slow _prepare_add_missing_fields ('date_planned', populate.compute(get_date_planned)), ('product_qty', populate.randint(1, 10)), ('price_unit', populate.randint(10, 100)), ]
def _populate_factories(self): company_ids = self.env.registry.populated_models[ 'res.company'][:COMPANY_NB_WITH_STOCK] resource_calendar_no_company = self.env.ref( 'resource.resource_calendar_std').copy({'company_id': False}) def get_resource_calendar_id(values, counter, random): if not values['company_id']: return resource_calendar_no_company.id return self.env['res.company'].browse( values['company_id']).resource_calendar_id.id return [ ('name', populate.constant("Workcenter - {counter}")), ('company_id', populate.iterate(company_ids + [False])), ('resource_calendar_id', populate.compute(get_resource_calendar_id)), ('active', populate.iterate([True, False], [0.9, 0.1])), ('code', populate.constant("W/{counter}")), ('capacity', populate.iterate([0.5, 1.0, 2.0, 5.0], [0.2, 0.4, 0.2, 0.2])), ('sequence', populate.randint(1, 1000)), ('color', populate.randint(1, 12)), ('costs_hour', populate.randint(5, 25)), ('time_start', populate.iterate([0.0, 2.0, 10.0], [0.6, 0.2, 0.2])), ('time_stop', populate.iterate([0.0, 2.0, 10.0], [0.6, 0.2, 0.2])), ('oee_target', populate.randint(80, 99)), ]
def _populate_factories(self): company_ids = self.env.registry.populated_models['res.company'] return [('name', populate.constant('lunch_location_{counter}')), ('address', populate.constant('lunch_address_location_{counter}')), ('company_id', populate.randomize(company_ids))]
def _populate_factories(self): def generate_partner_id(iterator, *args): partner_factories = self.env['res.partner']._populate_factories() partner_generator = populate.chain_factories( partner_factories, self._name) for dependant_values in partner_generator: values = next(iterator) yield { **dependant_values, **values, '__complete': values['__complete'] } def get_company_ids(values, **kwargs): return [(6, 0, [values['company_id']])] return [ ('active', populate.cartesian([True, False], [0.9, 0.1])), ('partner_id', generate_partner_id), ('company_id', populate.randomize( self.env.registry.populated_models['res.company'])), ('company_ids', populate.compute(get_company_ids)), ('login', populate.constant('user_login_{counter}')), ('name', populate.constant('user_{counter}')), ]
def _populate_factories(self): location_ids = self.env.registry.populated_models['lunch.location'] def get_location_ids(random=None, **kwargs): nb_max = len(location_ids) start = random.randint(0, nb_max) end = random.randint(start, nb_max) return location_ids[start:end] return [ ('active', populate.cartesian([True, False])), ('recipients', populate.cartesian( ['everyone', 'last_week', 'last_month', 'last_year'])), ('mode', populate.iterate(['alert', 'chat'])), ('mon', populate.iterate([True, False], [0.9, 0.1])), ('tue', populate.iterate([True, False], [0.9, 0.1])), ('wed', populate.iterate([True, False], [0.9, 0.1])), ('thu', populate.iterate([True, False], [0.9, 0.1])), ('fri', populate.iterate([True, False], [0.9, 0.1])), ('sat', populate.iterate([False, True], [0.9, 0.1])), ('sun', populate.iterate([False, True], [0.9, 0.1])), ('name', populate.constant('alert_{counter}')), ('message', populate.constant('<strong>alert message {counter}</strong>')), ('notification_time', populate.randfloat(0, 12)), ('notification_moment', populate.iterate(['am', 'pm'])), ('until', populate.randdatetime(relative_before=relativedelta(years=-2), relative_after=relativedelta(years=2))), ('location_ids', populate.compute(get_location_ids)) ]
def _populate_factories(self): address_id = self.env.ref('base.main_partner').id return [ ('name', populate.constant('work_location_{counter}')), ('address_id', populate.constant(address_id)), ]
def _populate_factories(self): return [ ("name", populate.constant('product_product_name_{counter}')), ("description", populate.constant('product_product_description_{counter}')), ("default_code", populate.constant('PP-{counter}')), ("barcode", populate.constant('BARCODE-PP-{counter}')), ] + self._populate_get_product_factories()
def _populate_factories(self): return [("name", populate.constant('stage_{counter}')), ("sequence", populate.randomize([False] + [i for i in range(1, 101)])), ("description", populate.constant('project_stage_description_{counter}')), ("active", populate.randomize([True, False], [0.8, 0.2])), ("fold", populate.randomize([True, False], [0.9, 0.1]))]
def _populate_factories(self): return [ ("name", populate.constant('product_template_name_{counter}')), ("sequence", populate.randomize([False] + [i for i in range(1, 101)])), ("description", populate.constant('product_template_description_{counter}')), ("default_code", populate.constant('product_default_code_{counter}')), ("active", populate.randomize([True, False], [0.8, 0.2])), ]
def _populate_factories(self): company_ids = self.env.registry.populated_models[ 'res.company'][:COMPANY_NB_WITH_STOCK] removal_strategies = self.env['product.removal'].search([]) return [ ('name', populate.constant("Loc-{counter}")), ('usage', populate.constant('internal')), ('removal_strategy_id', populate.randomize(removal_strategies.ids + [False])), ('company_id', populate.iterate(company_ids)), ]
def _populate_factories(self): # remaining: paperformat_id, parent_id, partner_id, favicon, font, report_header, external_report_layout_id, report_footer ref = self.env.ref def get_name(values=None, counter=0, **kwargs): return 'company_%s_%s' % (counter, self.env['res.currency'].browse( values['currency_id']).name) return [ ('name', populate.constant('company_{counter}')), ('sequence', populate.randint(0, 100)), ('company_registry', populate.iterate([False, 'company_registry_{counter}'])), ('base_onboarding_company_state', populate.iterate([False] + [ e[0] for e in type(self).base_onboarding_company_state.selection ])), ('primary_color', populate.iterate([False, '', '#ff7755'])), ('secondary_color', populate.iterate([False, '', '#ffff55'], seed='primary_color')), ('currency_id', populate.iterate([ ref('base.EUR').id, ref('base.USD').id, ref('base.CHF').id, ref('base.CHF').id ])), # add more? ('name', populate.compute(get_name)), ]
def _populate_factories(self): department_ids = self.env.registry.populated_models['hr.department'] return [ ('name', populate.constant('job_{counter}')), ('department_id', populate.randomize(department_ids)), ]
def _populate_factories(self): random = populate.Random('product_with_supplierinfo') company_ids = self.env.registry.populated_models[ 'res.company'][:COMPANY_NB_WITH_STOCK] + [False] partner_ids = self.env.registry.populated_models['res.partner'] product_templates_ids = self.env['product.product'].browse( self.env.registry.populated_models['product.product'] ).product_tmpl_id.ids product_templates_ids += self.env.registry.populated_models[ 'product.template'] product_templates_ids = random.sample( product_templates_ids, int(len(product_templates_ids) * 0.95)) def get_company_id(values, counter, random): partner = self.env['res.partner'].browse(values['name']) if partner.company_id: return partner.company_id.id return random.choice(company_ids) def get_delay(values, counter, random): # 5 % with huge delay (between 5 month and 6 month), otherwise between 1 and 10 days if random.random() > 0.95: return random.randint(150, 210) return random.randint(1, 10) return [ ('name', populate.randomize(partner_ids)), ('company_id', populate.compute(get_company_id)), ('product_tmpl_id', populate.iterate(product_templates_ids)), ('product_name', populate.constant("SI-{counter}")), ('sequence', populate.randint(1, 10)), ('min_qty', populate.randint(0, 10)), ('price', populate.randint(10, 100)), ('delay', populate.compute(get_delay)), ]
def _populate_factories(self): category_ids = self.env.registry.populated_models[ 'lunch.product.category'] category_records = self.env['lunch.product.category'].browse( category_ids) category_by_company = { k: list(v) for k, v in groupby(category_records, key=lambda rec: rec['company_id'].id) } supplier_ids = self.env.registry.populated_models['lunch.supplier'] company_by_supplier = { rec.id: rec.company_id.id for rec in self.env['lunch.supplier'].browse(supplier_ids) } def get_category(random=None, values=None, **kwargs): company_id = company_by_supplier[values['supplier_id']] return random.choice(category_by_company[company_id]).id return [ ('active', populate.iterate([True, False], [0.9, 0.1])), ('name', populate.constant('lunch_product_{counter}')), ('price', populate.randfloat(0.1, 50)), ('supplier_id', populate.randomize(supplier_ids)), ('category_id', populate.compute(get_category)), ]
def _populate_factories(self): company_ids = self.env.registry.populated_models["res.company"] stage_ids = self.env.registry.populated_models["project.task.type"] def get_company_id(random, **kwargs): return random.choice(company_ids) # user_ids from company.user_ids ? # Also add a partner_ids on res_company ? def get_stage_ids(random, **kwargs): return [(6, 0, [ random.choice(stage_ids) for i in range(random.choice([j for j in range(1, 10)])) ])] return [ ("name", populate.constant('project_{counter}')), ("sequence", populate.randomize([False] + [i for i in range(1, 101)])), ("active", populate.randomize([True, False], [0.8, 0.2])), ("company_id", populate.compute(get_company_id)), ("type_ids", populate.compute(get_stage_ids)), ('color', populate.randomize([False] + [i for i in range(1, 7)])), # TODO user_id but what about multi-company coherence ?? ]
def _populate_factories(self): company_ids = self.env.registry.populated_models[ 'res.company'][:COMPANY_NB_WITH_STOCK] warehouses = self.env['stock.warehouse'].browse( self.env.registry.populated_models['stock.warehouse']) internal_locations = self.env['stock.location'].search([ ('company_id', 'in', company_ids), ('usage', '=', 'internal') ]) in_warehouse_locations = self.env['stock.location'].search([ ('id', 'child_of', warehouses.lot_stock_id.ids) ]) internal_locations &= in_warehouse_locations def get_name(values, counter, random): return "%d-%s-%d" % (values['company_id'], values['code'], counter) def _compute_default_locations(iterator, field_name, model_name): random = populate.Random('_compute_default_locations') locations_by_company = dict( groupby(internal_locations, key=lambda loc: loc.company_id.id)) locations_by_company = { company_id: self.env['stock.location'].concat(*locations) for company_id, locations in locations_by_company.items() } for values in iterator: locations_company = locations_by_company[values['company_id']] inter_location = random.choice(locations_company) values['warehouse_id'] = inter_location.warehouse_id.id if values['code'] == 'internal': values['default_location_src_id'] = inter_location.id values['default_location_dest_id'] = random.choice( locations_company - inter_location).id elif values['code'] == 'incoming': values['default_location_dest_id'] = inter_location.id elif values['code'] == 'outgoing': values['default_location_src_id'] = inter_location.id yield values def get_show_operations(values, counter, random): return values['code'] != 'incoming' # Simulate onchange of form def get_show_reserved(values, counter, random): return values['show_operations'] and values[ 'code'] != 'incoming' # Simulate onchange of form return [ ('company_id', populate.iterate(company_ids)), ('code', populate.iterate(['incoming', 'outgoing', 'internal'], [0.3, 0.3, 0.4])), ('name', populate.compute(get_name)), ('sequence_code', populate.constant("PT{counter}")), ('_compute_default_locations', _compute_default_locations), ('show_operations', populate.compute(get_show_operations)), ('show_reserved', populate.compute(get_show_reserved)), ]
def _populate_factories(self): return [ ('name', populate.constant("SC-{counter}")), ('max_weight', populate.iterate([10, 100, 500, 1000])), ('allow_new_product', populate.randomize(['empty', 'same', 'mixed'], [0.1, 0.1, 0.8])), ]
def _populate_factories(self): company_ids = self.env['res.company'].search([ ('chart_template_id', '!=', False), ('id', 'in', self.env.registry.populated_models['res.company']), ]) return [ ('company_id', populate.cartesian(company_ids.ids)), ('type', populate.cartesian( ['sale', 'purchase', 'cash', 'bank', 'general'])), ('currency_id', populate.randomize(self.env['res.currency'].search([ ('active', '=', True), ]).ids + [False])), ('name', populate.constant("Journal {values[type]} {counter}")), ('code', populate.constant("{values[type]:.2}{counter}")), ]
def _populate_factories(self): return [ ("name", populate.constant('PA_{counter}')), ("sequence", populate.randomize([False] + [i for i in range(1, 101)])), ("create_variant", populate.randomize(["always", "dynamic", "no_variant"])), ]
def _populate_factories(self): attribute_ids = self.env.registry.populated_models["product.attribute"] return [ ("name", populate.constant('PAV_{counter}')), ("sequence", populate.randomize([False] + [i for i in range(1, 101)])), ("attribute_id", populate.randomize(attribute_ids)), ]
def _populate_factories(self): company_ids = self.env['res.company'].browse( self.env.registry.populated_models['res.company']) company_calendars = {} for company_id in company_ids: company_calendars[ company_id. id] = company_id.resource_calendar_ids.filtered_domain([ ('name', 'not like', 'Standard') ]).ids department_ids = self.env.registry.populated_models['hr.department'] job_ids = self.env.registry.populated_models['hr.job'] work_location_ids = self.env.registry.populated_models[ 'hr.work.location'] tag_ids = self.env.registry.populated_models['hr.employee.category'] user_ids = self.env['res.users'].browse( self.env.registry.populated_models['res.users']) def _compute_user_and_company(iterator, *args): # First users for values, user_id in zip(iterator, user_ids): yield { 'company_id': user_id.company_id.id, 'user_id': user_id.id, **values } # then as many as required non - users for values in iterator: yield { 'company_id': populate.random.choice(company_ids).id, 'user_id': False, **values } def get_resource_calendar_id(values, random, **kwargs): return random.choice(company_calendars[values['company_id']]) def get_tag_ids(values, counter, random): return [ (6, 0, [random.choice(tag_ids) for i in range(random.randint(0, 6))]) ] return [ ('active', populate.iterate([True, False], [0.9, 0.1])), ('name', populate.constant("employee_{counter}")), ('_user_and_company', _compute_user_and_company), ('department_id', populate.randomize(department_ids)), ('job_id', populate.randomize(job_ids)), ('work_location_id', populate.randomize(work_location_ids)), ('category_ids', populate.compute(get_tag_ids)), ('resource_calendar_id', populate.compute(get_resource_calendar_id)), ]
def _populate_factories(self): location_ids = self.env.registry.populated_models['lunch.location'] def get_notification_time(random=None, **kwargs): return random.randint(0, 120) / 10 def get_until_date(random=None, **kwargs): delta = random.randint(-731, 731) return datetime(2020, 1, 1) + timedelta(days=delta) def get_location_ids(random=None, **kwargs): nb_max = len(location_ids) start = random.randint(0, nb_max) end = random.randint(start, nb_max) return location_ids[start:end] return [ ('active', populate.cartesian([True, False])), ('recipients', populate.cartesian( ['everyone', 'last_week', 'last_month', 'last_year'])), ('mode', populate.iterate(['alert', 'chat'])), ('recurrency_monday', populate.iterate([True, False], [0.9, 0.1])), ('recurrency_tuesday', populate.iterate([True, False], [0.9, 0.1])), ('recurrency_wednesday', populate.iterate([True, False], [0.9, 0.1])), ('recurrency_thursday', populate.iterate([True, False], [0.9, 0.1])), ('recurrency_friday', populate.iterate([True, False], [0.9, 0.1])), ('recurrency_saturday', populate.iterate([False, True], [0.9, 0.1])), ('recurrency_sunday', populate.iterate([False, True], [0.9, 0.1])), ('name', populate.constant('alert_{counter}')), ('message', populate.constant('<strong>alert message {counter}</strong>')), ('notification_time', populate.compute(get_notification_time)), ('notification_moment', populate.iterate(['am', 'pm'])), ('until', populate.compute(get_until_date)), ('location_ids', populate.compute(get_location_ids)) ]
def _populate_factories(self): company_ids = self.env.registry.populated_models[ 'res.company'][:COMPANY_NB_WITH_STOCK] removal_strategies = self.env['product.removal'].search([]) storage_category_ids = self.env.registry.populated_models[ 'stock.storage.category'] def get_storage_category_id(values, counter, random): if random.random() > 0.5: return random.choice(storage_category_ids) return False return [ ('name', populate.constant("Loc-{counter}")), ('usage', populate.constant('internal')), ('removal_strategy_id', populate.randomize(removal_strategies.ids + [False])), ('company_id', populate.iterate(company_ids)), ('storage_category_id', populate.compute(get_storage_category_id)), ]
def _populate_factories(self): # TODO topping_ids_{1,2,3}, toppping_label_{1,2,3}, topping_quantity{1,2,3} company_ids = self.env.registry.populated_models['res.company'] return [ ('name', populate.constant('lunch_product_category_{counter}')), ('company_id', populate.iterate( [False, self.env.ref('base.main_company').id] + company_ids, [1, 1] + [2 / (len(company_ids) or 1)] * len(company_ids))), ]
def _populate_factories(self): company_ids = self.env.registry.populated_models['res.company'] return [ ('name', populate.constant('leave_type_{counter}')), ('company_id', populate.randomize(company_ids)), ('requires_allocation', populate.randomize(['yes', 'no'], [0.3, 0.7])), ('employee_requests', populate.randomize(['yes', 'no'], [0.2, 0.8])), ('request_unit', populate.randomize(['hour', 'day'], [0.2, 0.8])), ]
def _populate_factories(self): partner_ids = list(self.env.registry.populated_models["res.partner"]) def get_partner_id(random=None, **kwargs): partner_id = random.choice(partner_ids) partner_ids.remove(partner_id) return partner_id return [ ("active", populate.cartesian([True, False], [0.9, 0.1])), ("partner_id", populate.compute(get_partner_id)), ("login", populate.constant("user_login_{counter}")), ]
def _populate_factories(self): company_id = self.env.ref('base.main_company').id department_ids = self.env.registry.populated_models['hr.department'] job_ids = self.env.registry.populated_models['hr.job'] work_location_ids = self.env.registry.populated_models[ 'hr.work.location'] tag_ids = self.env.registry.populated_models['hr.employee.category'] def get_tag_ids(values, counter, random): return [ (6, 0, [random.choice(tag_ids) for i in range(random.randint(0, 6))]) ] return [ ('active', populate.iterate([True, False], [0.9, 0.1])), ('company_id', populate.constant(company_id)), ('name', populate.constant("employee_{counter}")), ('department_id', populate.randomize(department_ids)), ('job_id', populate.randomize(job_ids)), ('work_location_id', populate.randomize(work_location_ids)), ('category_ids', populate.compute(get_tag_ids)), ]
def _populate_factories(self): company_ids = self.env['res.company'].search([ ('chart_template_id', '!=', False), ('id', 'in', self.env.registry.populated_models['res.company']), ]) journal_ids = self.env['account.journal'].search([ ('company_id', 'in', company_ids.ids), ('type', 'in', ('cash', 'bank')), ]).ids return [ ('journal_id', populate.iterate(journal_ids)), ('name', populate.constant('statement_{counter}')), ('date', populate.randdatetime(relative_before=relativedelta(years=-4))), ]
def _populate_factories(self): # TODO topping_ids_{1,2,3}, topping_label_{1,3}, topping_quantity_{1,3} user_ids = self.env.registry.populated_models['res.users'] product_ids = self.env.registry.populated_models['lunch.product'] company_ids = self.env.registry.populated_models['res.company'] return [ ('active', populate.cartesian([True, False])), ('state', populate.cartesian(['new', 'confirmed', 'ordered', 'cancelled'])), ('product_id', populate.randomize(product_ids)), ('user_id', populate.randomize(user_ids)), ('note', populate.constant('lunch_note_{counter}')), ('company_id', populate.randomize(company_ids)), ('quantity', populate.randint(0, 10)), ]
def _populate_factories(self): company_ids = self.env.registry.populated_models[ 'res.company'][:COMPANY_NB_WITH_STOCK] def get_name(values, counter, random): return "WH-%d-%d" % (values['company_id'], counter) return [ ('company_id', populate.iterate(company_ids)), ('name', populate.compute(get_name)), ('code', populate.constant("W{counter}")), ('reception_steps', populate.iterate(['one_step', 'two_steps', 'three_steps'], [0.6, 0.2, 0.2])), ('delivery_steps', populate.iterate(['ship_only', 'pick_ship', 'pick_pack_ship'], [0.6, 0.2, 0.2])), ]