
Odoo CLI helps Database Inhabitants.
This text provides an outline of how we are able to work with the Database Inhabitants in Odoo as a developer.
Earlier than beginning this tutorial, you must have a primary thought of CLI in Odoo. In addition to, For those who don’t have primary data of Odoo CLI, learn a newbie information to Odoo CLI.
Why do we’d like a Database Inhabitants in Odoo CLI?
You may take a look at your modules within the database by computerized information era of the mannequin’s information
Earlier than transferring forward, try our Odoo growth providers & an in depth vary of high quality Odoo Apps.
How does Database Inhabitants work in Odoo CLI?
Syntax:-
odoo-bin populate –-models product.class,product.template –-size small -d demo –-db_user odoo --db_password=webkul
Output for higher command


Parameters:-
– -models
listing of fashions for which the database ought to be crammed.
– -size(small | medium | giant)
The full variety of the information to be created is will depend on the mannequin’s populate_size attribute
The generated information content material is specified by the _populate_factories() technique of a given mannequin.
-d
Title of the db
–db_user
Title of the DB Consumer
–db_password
Password for the DB Consumer
Implement Options on a Given Mannequin
Outline the next strategies and attributes to populate a given mannequin:-
i) Mannequin._populate_sizes
The default inhabitants sizes are:
Small: 10
Medium: 100
Giant: 1000
populate sizes are the variety of information that _populate() ought to create.
ii) Mannequin._populate_dependencies
Return the listing of fashions which should be populated earlier than the present one.
iii) Mannequin._populate(dimension)
Create information to populate this mannequin.
iv) Mannequin._populate_factories()
Generates a manufacturing facility for the totally different fields of the mannequin.
manufacturing facility
is a generator of values (dict of area values).
Manufacturing unit skeleton:
def generator(iterator, field_name, model_name): for counter, values in enumerate(iterator): # values.replace(dict()) yield values
Word*: You must outline at the least _populate() or _populate_factories() on the mannequin to allow database inhabitants.
Instance:
from odoo.instruments import populate class WebkulModel(fashions.Mannequin) _inherit = "webkul.some_model" _populate_sizes = {"small": 100, "medium": 2000, "giant": 10000} _populate_dependencies = ["webkul.some_other_model"] def _populate_factories(self): # Report ids of beforehand populated fashions are accessible within the registry some_other_ids = self.env.registry.populated_models["webkul.some_other_model"] def get_some_field(values=None, random=None, **kwargs): """ Select a price for some_field relying on different fields values. :param dict values: :param random: seeded :class:`random.Random` object """ field_1 = values['field_1'] if field_1 in [value2, value3]: return random.alternative(some_field_values) return False return [ ("field_1", populate.randomize([value1, value2, value3])), ("field_2", populate.randomize([value_a, value_b], [0.5, 0.5])), ("some_other_id", populate.randomize(some_other_ids)), ("some_field", populate.compute(get_some_field, seed="some_field")), ('lively', populate.cartesian([True, False])), ] def _populate(self, dimension): information = tremendous()._populate(dimension) # If you wish to replace the generated information # E.g setting the parent-child relationships information.do_something() return information
Inhabitants Instruments
A number of inhabitants instruments can be found to simply create the wanted information turbines.
i) odoo.instruments.populate.cartesian(vals, weights=None, seed=False, formatter=<operate format_str>, then=None)
Return a manufacturing facility for an iterator of values dicts that mixes all vals
for the sector with the opposite area values in enter.
Parameters:
- vals (listing) – listing through which a price will likely be chosen, relying on
weights
- weights (listing) – listing of probabilistic weights
- seed – non-obligatory initialization of the random quantity generator
- formatter (operate) – (val, counter, values) –> formatted_value
- then (operate) – if outlined, manufacturing facility used when vals has been consumed.
Returns: operate of the shape (iterator, field_name, model_name) -> values
Return sort: operate (iterator, str, str) -> dict
ii) odoo.instruments.populate.compute(operate, seed=None)
Return a manufacturing facility for an iterator of values dictionary (dicts) that computes the sector worth as a operate (values, counter, random), the place values are the opposite area worth, counter is an integer, and random
is a pseudo-random quantity generator.
Parameters:
- operate (callable) – (values, counter, random) –> field_values
- seed – non-obligatory initialization of the random quantity generator
Returns: operate of the shape (iterator, field_name, model_name) -> values
Return sort: operate (iterator, str, str) -> dict
iii) odoo.instruments.populate.fixed(val, formatter=<operate format_str>)
Return a manufacturing facility for an iterator of values dicts that units the sector to the given worth in every enter dict.
Returns: operate of the shape (iterator, field_name, model_name) -> values
Return sort: operate (iterator, str, str) -> dict
iv) odoo.instruments.populate.iterate(vals, weights=None, seed=False, formatter=<operate format_str>, then=None).
Return a manufacturing facility for an iterator of values dicts that picks a price amongst vals
for every enter. As soon as all vals
have been used as soon as, resume as then
or as a randomize
generator.
Parameters:
- vals (listing) – listing through which a price will likely be chosen, relying on
weights
- weights (listing) – listing of probabilistic weights
- seed – non-obligatory initialization of the random quantity generator
- formatter (operate) – (val, counter, values) –> formatted_value
- then (operate) – if outlined, manufacturing facility used when vals has been consumed.
Returns: operate of the shape (iterator, field_name, model_name) -> values
Return sort: operate (iterator, str, str) -> dict
v) odoo.instruments.populate.randint(a, b, seed=None)
Return a manufacturing facility for an iterator of values dicts that units the sector to a random integer between a and b included in every enter dict.
Parameters:
- a (int) – minimal random worth
- b (int) – maximal random worth
- seed (int) –
Returns: operate of the shape (iterator, field_name, model_name) -> values
Return sort: operate (iterator, str, str) -> dict
vi) odoo.instruments.populate.randomize(vals, weights=None, seed=False, formatter=<operate format_str>, counter_offset=0)
Return a manufacturing facility for an iterator of values dicts with pseudo-randomly chosen values (amongst vals
) for a area.
Parameters:
- vals (listing) – listing through which a price will likely be chosen, relying on
weights
- weights (listing) – listing of probabilistic weights
- seed – non-obligatory initialization of the random quantity generator
- formatter (operate) – (val, counter, values) –> formatted_value
- counter_offset (int) –
Returns: operate of the shape (iterator, field_name, model_name) -> values
Return sort: operate (iterator, str, str) -> dict
NEED HELP?
Hope you discover the information useful! Please be happy to share your suggestions within the feedback beneath.
For those who nonetheless have any points/queries relating to the identical, please elevate a ticket on the UV Desk.
For any doubt, contact us at our assist mail.

Odoo CLI helps Database Inhabitants.
This text provides an outline of how we are able to work with the Database Inhabitants in Odoo as a developer.
Earlier than beginning this tutorial, you must have a primary thought of CLI in Odoo. In addition to, For those who don’t have primary data of Odoo CLI, learn a newbie information to Odoo CLI.
Why do we’d like a Database Inhabitants in Odoo CLI?
You may take a look at your modules within the database by computerized information era of the mannequin’s information
Earlier than transferring forward, try our Odoo growth providers & an in depth vary of high quality Odoo Apps.
How does Database Inhabitants work in Odoo CLI?
Syntax:-
odoo-bin populate –-models product.class,product.template –-size small -d demo –-db_user odoo --db_password=webkul
Output for higher command


Parameters:-
– -models
listing of fashions for which the database ought to be crammed.
– -size(small | medium | giant)
The full variety of the information to be created is will depend on the mannequin’s populate_size attribute
The generated information content material is specified by the _populate_factories() technique of a given mannequin.
-d
Title of the db
–db_user
Title of the DB Consumer
–db_password
Password for the DB Consumer
Implement Options on a Given Mannequin
Outline the next strategies and attributes to populate a given mannequin:-
i) Mannequin._populate_sizes
The default inhabitants sizes are:
Small: 10
Medium: 100
Giant: 1000
populate sizes are the variety of information that _populate() ought to create.
ii) Mannequin._populate_dependencies
Return the listing of fashions which should be populated earlier than the present one.
iii) Mannequin._populate(dimension)
Create information to populate this mannequin.
iv) Mannequin._populate_factories()
Generates a manufacturing facility for the totally different fields of the mannequin.
manufacturing facility
is a generator of values (dict of area values).
Manufacturing unit skeleton:
def generator(iterator, field_name, model_name): for counter, values in enumerate(iterator): # values.replace(dict()) yield values
Word*: You must outline at the least _populate() or _populate_factories() on the mannequin to allow database inhabitants.
Instance:
from odoo.instruments import populate class WebkulModel(fashions.Mannequin) _inherit = "webkul.some_model" _populate_sizes = {"small": 100, "medium": 2000, "giant": 10000} _populate_dependencies = ["webkul.some_other_model"] def _populate_factories(self): # Report ids of beforehand populated fashions are accessible within the registry some_other_ids = self.env.registry.populated_models["webkul.some_other_model"] def get_some_field(values=None, random=None, **kwargs): """ Select a price for some_field relying on different fields values. :param dict values: :param random: seeded :class:`random.Random` object """ field_1 = values['field_1'] if field_1 in [value2, value3]: return random.alternative(some_field_values) return False return [ ("field_1", populate.randomize([value1, value2, value3])), ("field_2", populate.randomize([value_a, value_b], [0.5, 0.5])), ("some_other_id", populate.randomize(some_other_ids)), ("some_field", populate.compute(get_some_field, seed="some_field")), ('lively', populate.cartesian([True, False])), ] def _populate(self, dimension): information = tremendous()._populate(dimension) # If you wish to replace the generated information # E.g setting the parent-child relationships information.do_something() return information
Inhabitants Instruments
A number of inhabitants instruments can be found to simply create the wanted information turbines.
i) odoo.instruments.populate.cartesian(vals, weights=None, seed=False, formatter=<operate format_str>, then=None)
Return a manufacturing facility for an iterator of values dicts that mixes all vals
for the sector with the opposite area values in enter.
Parameters:
- vals (listing) – listing through which a price will likely be chosen, relying on
weights
- weights (listing) – listing of probabilistic weights
- seed – non-obligatory initialization of the random quantity generator
- formatter (operate) – (val, counter, values) –> formatted_value
- then (operate) – if outlined, manufacturing facility used when vals has been consumed.
Returns: operate of the shape (iterator, field_name, model_name) -> values
Return sort: operate (iterator, str, str) -> dict
ii) odoo.instruments.populate.compute(operate, seed=None)
Return a manufacturing facility for an iterator of values dictionary (dicts) that computes the sector worth as a operate (values, counter, random), the place values are the opposite area worth, counter is an integer, and random
is a pseudo-random quantity generator.
Parameters:
- operate (callable) – (values, counter, random) –> field_values
- seed – non-obligatory initialization of the random quantity generator
Returns: operate of the shape (iterator, field_name, model_name) -> values
Return sort: operate (iterator, str, str) -> dict
iii) odoo.instruments.populate.fixed(val, formatter=<operate format_str>)
Return a manufacturing facility for an iterator of values dicts that units the sector to the given worth in every enter dict.
Returns: operate of the shape (iterator, field_name, model_name) -> values
Return sort: operate (iterator, str, str) -> dict
iv) odoo.instruments.populate.iterate(vals, weights=None, seed=False, formatter=<operate format_str>, then=None).
Return a manufacturing facility for an iterator of values dicts that picks a price amongst vals
for every enter. As soon as all vals
have been used as soon as, resume as then
or as a randomize
generator.
Parameters:
- vals (listing) – listing through which a price will likely be chosen, relying on
weights
- weights (listing) – listing of probabilistic weights
- seed – non-obligatory initialization of the random quantity generator
- formatter (operate) – (val, counter, values) –> formatted_value
- then (operate) – if outlined, manufacturing facility used when vals has been consumed.
Returns: operate of the shape (iterator, field_name, model_name) -> values
Return sort: operate (iterator, str, str) -> dict
v) odoo.instruments.populate.randint(a, b, seed=None)
Return a manufacturing facility for an iterator of values dicts that units the sector to a random integer between a and b included in every enter dict.
Parameters:
- a (int) – minimal random worth
- b (int) – maximal random worth
- seed (int) –
Returns: operate of the shape (iterator, field_name, model_name) -> values
Return sort: operate (iterator, str, str) -> dict
vi) odoo.instruments.populate.randomize(vals, weights=None, seed=False, formatter=<operate format_str>, counter_offset=0)
Return a manufacturing facility for an iterator of values dicts with pseudo-randomly chosen values (amongst vals
) for a area.
Parameters:
- vals (listing) – listing through which a price will likely be chosen, relying on
weights
- weights (listing) – listing of probabilistic weights
- seed – non-obligatory initialization of the random quantity generator
- formatter (operate) – (val, counter, values) –> formatted_value
- counter_offset (int) –
Returns: operate of the shape (iterator, field_name, model_name) -> values
Return sort: operate (iterator, str, str) -> dict
NEED HELP?
Hope you discover the information useful! Please be happy to share your suggestions within the feedback beneath.
For those who nonetheless have any points/queries relating to the identical, please elevate a ticket on the UV Desk.
For any doubt, contact us at our assist mail.