示例#1
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))
        ]
示例#2
0
    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))
        ]
示例#3
0
 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]))
     ]
示例#4
0
    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 ??
        ]
示例#5
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)),
        ]
示例#6
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))),
        ]
示例#7
0
    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}")),
        ]
示例#8
0
    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)),
        ]
示例#9
0
 def _populate_factories(self):
     project_ids = self.env.registry.populated_models["project.project"]
     stage_ids = self.env.registry.populated_models["project.task.type"]
     def get_project_id(random, **kwargs):
         return random.choice([False, False, False] + project_ids)
     def get_stage_id(random, **kwargs):
         return random.choice([False, False] + stage_ids)
     return [
         ("name", populate.constant('project_task_{counter}')),
         ("sequence", populate.randomize([False] + [i for i in range(1, 101)])),
         ("active", populate.randomize([True, False], [0.8, 0.2])),
         ("color", populate.randomize([False] + [i for i in range(1, 7)])),
         ("kanban_state", populate.randomize(['normal', 'done', 'blocked'])),
         ("project_id", populate.compute(get_project_id)),
         ("stage_id", populate.compute(get_stage_id)),
     ]
示例#10
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)),
        ]
示例#11
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
        ]