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)),
        ]
Example #2
0
    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)),
        ]
Example #3
0
    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)),
        ]
Example #4
0
    def _populate_factories(self):
        company_ids = self.env.registry.populated_models["res.company"]

        return [
            ("company_id", populate.iterate(company_ids)),
            ("name",
             populate.iterate(["A little {counter}", "A lot {counter}"])),
        ]
Example #5
0
    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))
        ]
Example #6
0
    def _populate_factories(self):

        location_ids = self.env.registry.populated_models['lunch.location']
        partner_ids = self.env.registry.populated_models['res.partner']
        user_ids = self.env.registry.populated_models['res.users']

        def get_location_ids(random=None, **kwargs):
            nb_locations = random.randint(0, len(location_ids))
            return [(6, 0, random.choices(location_ids, k=nb_locations))]

        return [
            ('active', populate.cartesian([True, False])),
            ('send_by', populate.cartesian(['phone', 'mail'])),
            ('delivery', populate.cartesian(['delivery', 'no_delivery'])),
            ('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])),
            ('available_location_ids',
             populate.iterate([[], [(6, 0, location_ids)]],
                              then=populate.compute(get_location_ids))),
            ('partner_id', populate.randomize(partner_ids)),
            ('responsible_id', populate.randomize(user_ids)),
            ('moment', populate.iterate(['am', 'pm'])),
            ('automatic_email_time', populate.randfloat(0, 12)),
        ]
Example #7
0
    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)),
        ]
Example #8
0
    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)),
        ]
Example #9
0
    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)),
        ]
Example #10
0
    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, 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)),
        ]
Example #11
0
 def _populate_factories(self):
     return [('active', populate.cartesian([False, True], [0.1, 0.9])),
             ('name',
              populate.cartesian(
                  [False, 'Industry name', 'Industry name {counter}'],
                  [0.08, 0.01, 0.9])),
             ('full_name',
              populate.iterate([False, 'Industry full name %s']))]
Example #12
0
    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])),
        ]
Example #13
0
    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])),
        ]
Example #14
0
    def _populate_factories(self):
        def get_name(values, counter, **kwargs):
            return f"{str.capitalize(values['alarm_type'])} - {values['duration']} {values['interval']} (#{counter})."

        return [
            *((field_name, populate.iterate(*zip(*data.calendar_alarm[field_name].items())))
              for field_name in ["alarm_type", "duration", "interval"]),
            ('name', populate.compute(get_name)),
        ]
Example #15
0
    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)),
        ]
Example #16
0
    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))),
        ]
Example #17
0
    def _populate_factories(self):
        # TODO: tree of product by company to be more closer to the reality
        boms = self.env['mrp.bom'].search(
            [('id', 'in', self.env.registry.populated_models['mrp.bom'])],
            order='sequence, product_id, 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_ids = list(product_manu_ids)
        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_id(values, counter, random):
            bom = self.env['mrp.bom'].browse(values['bom_id'])
            last_product_bom = bom.product_id if bom.product_id else bom.product_tmpl_id.product_variant_ids[
                -1]
            # TODO: index in list is in O(n) can be avoid by a cache dict (if performance issue)
            index_prod = product_manu_ids.index(last_product_bom.id)
            # Always choose a product futher in the recordset `product_manu` to avoid any loops
            # Or used a product in the `product_no_manu`

            sparsity = 0.4  # Increase the sparsity will decrease the density of the BoM trees => smaller Tree

            len_remaining_manu = len(product_manu_ids) - index_prod - 1
            len_no_manu = len(product_no_manu_ids)
            threshold = len_remaining_manu / (len_remaining_manu +
                                              sparsity * len_no_manu)
            if random.random() <= threshold:
                # TODO: avoid copy the list (if performance issue)
                return random.choice(product_manu_ids[index_prod + 1:])
            else:
                return random.choice(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)),
            ('sequence', populate.randint(1, 1000)),
            ('product_id', populate.compute(get_product_id)),
            ('product_uom_id', populate.compute(get_product_uom_id)),
            ('product_qty', populate.randint(1, 10)),
        ]
Example #18
0
    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)),
        ]
Example #19
0
    def _populate_factories(self):
        # Take a subset (70%) of bom to have some of then without any operation
        random = populate.Random('operation_subset_bom')
        boms_ids = self.env.registry.populated_models['mrp.bom']
        boms_ids = random.sample(boms_ids, int(len(boms_ids) * 0.7))

        # Valid workcenters by company_id (the workcenter without company can be used by any operation)
        workcenters_by_company = defaultdict(OrderedSet)
        for workcenter in self.env['mrp.workcenter'].browse(
                self.env.registry.populated_models['mrp.workcenter']):
            workcenters_by_company[workcenter.company_id.id].add(workcenter.id)
        workcenters_by_company = {
            company_id: self.env['mrp.workcenter'].browse(workcenters)
            for company_id, workcenters in workcenters_by_company.items()
        }
        workcenters_by_company = {
            company_id: workcenters
            | workcenters_by_company.get(False, self.env['mrp.workcenter'])
            for company_id, workcenters in workcenters_by_company.items()
        }

        def get_company_id(values, counter, random):
            bom = self.env['mrp.bom'].browse(values['bom_id'])
            return bom.company_id.id

        def get_workcenter_id(values, counter, random):
            return random.choice(
                workcenters_by_company[values['company_id']]).id

        return [
            ('bom_id', populate.iterate(boms_ids)),
            ('company_id', populate.compute(get_company_id)),
            ('workcenter_id', populate.compute(get_workcenter_id)),
            ('name', populate.constant("OP-{counter}")),
            ('sequence', populate.randint(1, 1000)),
            ('time_mode', populate.iterate(['auto', 'manual'])),
            ('time_mode_batch', populate.randint(1, 100)),
            ('time_cycle_manual', populate.randomize([1.0, 15.0, 60.0,
                                                      1440.0])),
        ]
Example #20
0
    def _populate_factories(self):
        def get_tracking(values, counter, random):
            if values['type'] == 'product':
                return random.choices(['none', 'lot', 'serial'],
                                      [0.7, 0.2, 0.1])[0]
            else:
                return 'none'

        res = super()._populate_factories()
        res.append(('type',
                    populate.iterate(['consu', 'service', 'product'],
                                     [0.3, 0.2, 0.5])))
        res.append(('tracking', populate.compute(get_tracking)))
        return res
    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['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))),
     ]
Example #23
0
    def _populate_factories(self):
        company_ids = self.env.registry.populated_models["res.company"]

        return [
            ("company_id",
             populate.iterate(company_ids +
                              [False for i in range(len(company_ids))])),
            ("name", populate.constant('product_pricelist_{counter}')),
            ("currency_id",
             populate.randomize(self.env["res.currency"].search([
                 ("active", "=", True)
             ]).ids)),
            ("sequence",
             populate.randomize([False] + [i for i in range(1, 101)])),
            ("discount_policy",
             populate.randomize(["with_discount", "without_discount"])),
            ("active", populate.randomize([True, False], [0.8, 0.2])),
        ]
Example #24
0
    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)),
        ]
Example #25
0
    def _populate_factories(self):

        inventories = self.env['stock.inventory'].browse(
            self.env.registry.populated_models['stock.inventory'])
        inventories = inventories.filtered(lambda i: i.state == 'confirm')

        def compute_product_location(iterator, field_name, model_name):
            random = populate.Random('compute_product_location')

            # To avoid create twice the same line inventory (avoid _check_no_duplicate_line) : product/location (limitation for lot)
            # Use generator to avoid cartisian product in memory
            generator_product_loc_dict = {}
            for inventory in inventories:
                # TODO: randomize cartesian product
                generator_product_loc_dict[inventory.id] = cartesian_product(
                    random.sample(inventory.location_ids,
                                  len(inventory.location_ids)),
                    random.sample(inventory.product_ids,
                                  len(inventory.product_ids)))

            for values in iterator:
                loc_id, product = next(
                    generator_product_loc_dict[values['inventory_id']])
                values['product_id'] = product.id
                values['location_id'] = loc_id.id
                yield values

        def get_product_qty(values, counter, random):
            product = self.env['product.product'].browse(values['product_id'])
            if product.tracking == 'serial':
                return 1.0
            else:
                return random.randint(5, 25)

        return [
            ('inventory_id', populate.iterate(inventories.ids)),
            ('_compute_product_location', compute_product_location),
            ('product_qty', populate.compute(get_product_qty)),
        ]
Example #26
0
    def _populate_factories(self):

        # cross dependant field in a sub generator, cartesian product of two fields
        dependant_factories = [
            ('dependant_field_1', populate.cartesian(['d1_1', 'd1_2'])),
            ('dependant_field_2',
             populate.cartesian(['d2_1', 'd2_2', 'd2_3_{counter}'])),
        ]

        def generate_dependant(iterator, *args):
            dependants_generator = populate.chain_factories(
                dependant_factories, self._name)
            for values in dependants_generator:
                dependant_values = next(iterator)
                yield {
                    **values,
                    **dependant_values, '__complete':
                    values['__complete'] and dependant_values['__complete']
                }

        def get_name(values=None, counter=0, **kwargs):
            active = 'active' if values['active'] else 'inactive'
            cat = 'filling' if values['__complete'] else 'corner'
            return '%s_%s_%s' % (active, cat, counter)

        category_ids = self.env.registry.populated_models[
            'test.populate.category']

        return [
            ('active', populate.cartesian([True, False], [3, 1])),
            ('state',
             populate.cartesian([False] + self.env['test.populate'].
                                _fields['state'].get_values(self.env))),
            ('some_ref', populate.iterate([False, 1, 2, 3, 4])),
            ('_dependant', generate_dependant),
            ('name', populate.compute(get_name)),
            ('category_id', populate.randomize([False] + category_ids)),
        ]
Example #27
0
File: hr.py Project: yustas147/odoo
    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)),
        ]
Example #28
0
    def _populate_factories(self):

        company_ids = self.env.registry.populated_models[
            'res.company'][:COMPANY_NB_WITH_STOCK]
        valid_locations = self.env['stock.location'].search([
            ('company_id', 'in', company_ids),
            ('usage', 'in', ['internal', 'transit'])
        ])
        locations_by_company = dict(
            groupby(valid_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()
        }
        products = self.env['product.product'].browse(
            self.env.registry.populated_models['product.product']).filtered(
                lambda p: p.type == 'product')

        def get_locations_ids(values, counter, random):
            location_ids_company = locations_by_company[values['company_id']]
            # We set locations to ease the creation of stock.inventory.line
            # Should be larger enough to avoid the emptiness of generator_product_loc_dict
            return random.sample(location_ids_company.ids,
                                 int(len(location_ids_company.ids) * 0.5))

        def get_product_ids(values, counter, random):
            # We set products to ease the creation of stock.inventory.line
            # Should be larger enough to avoid the emptiness of generator_product_loc_dict
            return random.sample(products.ids, int(len(products.ids) * 0.5))

        return [
            ('name', populate.constant("Inventory-Pop-{counter}")),
            ('company_id', populate.iterate(company_ids)),
            ('location_ids', populate.compute(get_locations_ids)),
            ('product_ids', populate.compute(get_product_ids)),
        ]
Example #29
0
    def _populate_factories(self):
        now = datetime.now()
        company_ids = self.env.registry.populated_models[
            'res.company'][:COMPANY_NB_WITH_STOCK]

        products = self.env['product.product'].browse(
            self.env.registry.populated_models['product.product'])
        product_ids = products.filtered(lambda product: product.type in
                                        ('product', 'consu')).ids

        boms = self.env['mrp.bom'].browse(
            self.env.registry.populated_models['mrp.bom'])
        boms_by_company = defaultdict(OrderedSet)
        for bom in boms:
            boms_by_company[bom.company_id.id].add(bom.id)
        boms_by_company = {
            company_id: self.env['mrp.bom'].browse(boms)
            for company_id, boms in boms_by_company.items()
        }
        boms_by_company = {
            company_id: boms | boms_by_company.get(False, self.env['mrp.bom'])
            for company_id, boms in boms_by_company.items()
        }

        def get_bom_id(values, counter, random):
            if random.random() > 0.7:  # 30 % of prototyping
                return False
            return random.choice(boms_by_company[values['company_id']]).id

        def get_consumption(values, counter, random):
            if not values['bom_id']:
                return 'flexible'
            return self.env['mrp.bom'].browse(values['bom_id']).consumption

        def get_product_id(values, counter, random):
            if not values['bom_id']:
                return random.choice(product_ids)
            bom = self.env['mrp.bom'].browse(values['bom_id'])
            return bom.product_id.id or random.choice(
                bom.product_tmpl_id.product_variant_ids.ids)

        def get_product_uom_id(values, counter, random):
            product = self.env['product.product'].browse(values['product_id'])
            return product.uom_id.id

        # Fetch all stock picking type and group then by company_id
        manu_picking_types = self.env['stock.picking.type'].search([
            ('code', '=', 'mrp_operation')
        ])
        manu_picking_types_by_company_id = defaultdict(OrderedSet)
        for picking_type in manu_picking_types:
            manu_picking_types_by_company_id[picking_type.company_id.id].add(
                picking_type.id)
        manu_picking_types_by_company_id = {
            company_id: list(picking_ids)
            for company_id, picking_ids in
            manu_picking_types_by_company_id.items()
        }

        def get_picking_type_id(values, counter, random):
            return random.choice(
                manu_picking_types_by_company_id[values['company_id']])

        def get_location_src_id(values, counter, random):
            # TODO : add some randomness
            picking_type = self.env['stock.picking.type'].browse(
                values['picking_type_id'])
            return picking_type.default_location_src_id.id

        def get_location_dest_id(values, counter, random):
            # TODO : add some randomness
            picking_type = self.env['stock.picking.type'].browse(
                values['picking_type_id'])
            return picking_type.default_location_dest_id.id

        def get_date_planned_start(values, counter, random):
            # 95.45 % of picking scheduled between (-10, 30) days and follow a gauss distribution (only +-15% picking is late)
            delta = random.gauss(10, 10)
            return now + timedelta(days=delta)

        return [
            ('company_id', populate.iterate(company_ids)),
            ('bom_id', populate.compute(get_bom_id)),
            ('consumption', populate.compute(get_consumption)),
            ('product_id', populate.compute(get_product_id)),
            ('product_uom_id', populate.compute(get_product_uom_id)),
            ('product_qty', populate.randint(1, 10)),
            ('picking_type_id', populate.compute(get_picking_type_id)),
            ('date_planned_start', populate.compute(get_date_planned_start)),
            ('location_src_id', populate.compute(get_location_src_id)),
            ('location_dest_id', populate.compute(get_location_dest_id)),
            ('priority', populate.iterate(['0', '1'], [0.95, 0.05])),
        ]
Example #30
0
 def _populate_factories(self):
     return super()._populate_factories() + [
         ('manufacture_steps',
          populate.iterate(['mrp_one_step', 'pbm', 'pbm_sam'],
                           [0.6, 0.2, 0.2]))
     ]