예제 #1
0
    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)),
        ]
예제 #2
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_email_time(random=None, **kwargs):
            return random.randint(0, 120) / 10

        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'])),
            ('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])),
            ('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.compute(get_email_time)),
        ]
예제 #3
0
    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))
        ]
예제 #4
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']))]
예제 #5
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))),
        ]
예제 #6
0
    def _populate_factories(self):

        def get_price(random=None, **kwargs):
            return random.randint(1, 500) / 10

        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.compute(get_price)),
            ('supplier_id', populate.randomize(supplier_ids)),
            ('category_id', populate.compute(get_category)),
        ]
예제 #7
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)),
                ('sequence', populate.randint(1, 10))]
예제 #8
0
    def _populate_factories(self):

        # example of more complex generator composed of multiple sub generators
        # this define one subgenerator per "country"
        address_factories_groups = [
            [  # Falsy, 2 records
                ('street', populate.iterate([False, ''])),
                ('street2', populate.iterate([False, ''])),
                ('city', populate.iterate([False, ''])),
                ('zip', populate.iterate([False, ''])),
                ('country_id', populate.iterate([False])),
            ],
            [  # BE, 1 record
                ('street', populate.iterate(['Boulevard Tintin {counter}'])),
                ('city', populate.iterate(['Brussels'])),
                ('zip', populate.iterate([1020])),
                ('country_id', populate.iterate([self.env.ref('base.be').id])),
            ],
            [  # US, 3 records
                ('street',
                 populate.iterate(
                     ['Main street', '3th street {counter}', False])),
                ('street2',
                 populate.iterate([False, '', 'Behind the tree {counter}'],
                                  [90, 5, 5])),
                ('city',
                 populate.randomize(
                     ['Sans Fransisco', 'Los Angeles', '', False])),
                ('zip', populate.iterate([False, '', '50231'])),
                ('country_id', populate.iterate([self.env.ref('base.us').id])),
            ],
            [  # IN, 2 records
                ('street',
                 populate.iterate(['Main Street', 'Some Street {counter}'])),
                ('city', populate.iterate(['ગાંધીનગર (Gandhinagar)'])),
                ('zip', populate.randomize(['382002', '382008'])),
                ('country_id', populate.randomize([self.env.ref('base.in').id
                                                   ])),
            ],
            [  # other corner cases, 4 records
                ('street',
                 populate.iterate([
                     '万泉寺村', 'საბჭოს სკვერი {counter}', '10th Street {counter}'
                 ])),
                ('city', populate.iterate(['北京市', 'თბილისი', 'دبي'])),
                ('zip', populate.iterate([False, 'UF47', '0', '10201'])),
                ('country_id',
                 populate.randomize([False] +
                                    self.env['res.country'].search([]).ids)),
            ]
        ]

        def generate_address(iterator, *args):
            address_generators = [
                populate.chain_factories(address_factories, self._name)
                for address_factories in address_factories_groups
            ]
            # first, exhaust all address_generators
            for adress_generator in address_generators:
                for adress_values in adress_generator:
                    if adress_values['__complete']:
                        break
                    values = next(
                        iterator)  # only consume main iterator if usefull
                    yield {**values, **adress_values}

            # then, go pseudorandom between generators
            r = populate.Random('res.partner+address_generator_selector')
            for values in iterator:
                adress_generator = r.choice(address_generators)
                adress_values = next(adress_generator)
                yield {**adress_values, **values}

        # state based on country
        states = self.env['res.country.state'].search([])
        states_per_country = collections.defaultdict(list)
        for state in states:
            states_per_country[state.country_id.id].append(state.id)

        def get_state(values=None, random=None, **kwargs):
            country_id = values['country_id']
            if not country_id:
                return False
            return random.choice([False] + states_per_country[country_id])

        def get_name(values=None, counter=0, **kwargs):
            is_company = values['is_company']
            complete = values['__complete']
            return '%s_%s_%s' % ('company' if is_company else 'partner',
                                 int(complete), counter)

        industry_ids = self.env.registry.populated_models[
            'res.partner.industry']
        company_ids = self.env.registry.populated_models['res.company']

        # not defined fields: vat, partner_longitude, date, partner_latitude, color, company_name, employee, lang, user_id
        return [
            ('active', populate.cartesian([True, False], [0.9, 0.1])),
            ('employee', populate.cartesian([True, False], [0.1, 0.9])),
            ('email',
             populate.iterate([
                 False, '', 'email{counter}@example.com',
                 '<contact 万> contact{counter}@anotherexample.com',
                 'invalid_email'
             ])),
            (
                'type', populate.constant('contact')
            ),  # todo add more logic, manage 'invoice', 'delivery', 'other', 'private'
            ('is_company', populate.iterate([True, False], [0.05, 0.95])),
            ('_address', generate_address),
            ('state_id', populate.compute(get_state)),
            ('phone',
             populate.randomize(
                 [False, '', '+3212345678', '003212345678', '12345678'])),
            ('mobile',
             populate.randomize(
                 [False, '', '+32412345678', '0032412345678', '412345678'])),
            ('title',
             populate.randomize(self.env['res.partner.title'].search([]).ids)),
            ('function',
             populate.randomize([
                 False, '', 'President of Sales', 'Senior Consultant',
                 'Product owner', 'Functional Consultant',
                 'Chief Executive Officer'
             ], [50, 10, 2, 20, 5, 10, 1])),
            ('tz',
             populate.randomize([
                 tz for tz in self.env['res.partner']._fields['tz'].get_values(
                     self.env)
             ])),
            ('website',
             populate.randomize([False, '', 'http://www.example.com'])),
            ('credit_limit',
             populate.randomize([False, 0, 500, 2500, 5000, 10000],
                                [50, 30, 5, 5, 5, 5])),
            ('name', populate.compute(get_name)),  # keep after is_company
            ('ref',
             populate.randomize([False, '', '{counter}', 'p-{counter}'],
                                [10, 10, 30, 50])),
            ('industry_id',
             populate.randomize(
                 [False] + industry_ids, [0.5] +
                 ([0.5 / (len(industry_ids) or 1)] * len(industry_ids)))),
            ('comment',
             populate.iterate([False, '', 'This is a partner {counter}'])),
            ('company_id',
             populate.iterate(
                 [False, self.env.ref('base.main_company').id] + company_ids,
                 [1, 1] + [1 / (len(company_ids) or 1)] * len(company_ids))),
            ('parent_id',
             populate.constant(False)),  # will be setted in _populate override
        ]
예제 #9
0
 def _populate_factories(self):
     return super()._populate_factories() + [
         ('additionnal_field', populate.iterate(['V1', 'V2', 'V3'])),
     ]