groups are related to security and access rights in Odoo. Everything difined for this group will be visible to users that are members of this one.
How it works ?
it starts with module category which should contain groups grouped by module

Code taken from ../odoo/addons/base/module/module_data.xml : ("Sales" category)
<record model="ir.module.category" id="module_category_sales_management">
<field name="name">Sales</field>
<field name="description">Helps you handle your quotations, sale orders and invoicing.</field>
<field name="sequence">1</field>
</record>
Code taken from ../addons/sales_team/security : ("User: Own Documents Only" group)
<record id="group_sale_salesman" model="res.groups">
<field name="name">User: Own Documents Only</field>
<field name="category_id" ref="base.module_category_sales_management"/>
<field name="implied_ids" eval="[(4, ref('base.group_user'))]"/>
<field name="comment">the user will have access to his own data in the sales application.</field>
</record>
<field name="implied_ids" eval="[(4, ref('base.group_user'))]"/> line says that everybody on the group group_sale_salesman is a part of group_user group two.
Then, you can create a rule that can for example limit data given to a user in the group in a specific model (model : sale.order referenced by ref="model_sale_order" in following code)
Also, in the following code the data given from sale.order is filtered so that the user gets only his own created orders or orders with no user_id defined.
Code taken from ../addons/sale/security :
<record id="sale_order_personal_rule" model="ir.rule">
<field name="name">Personal Orders</field>
<field ref="model_sale_order" name="model_id"/>
<field name="domain_force">['|',('user_id','=',user.id),('user_id','=',False)]</field>
<field name="groups" eval="[(4, ref('sales_team.group_sale_salesman'))]"/>
</record>
ir.model.access
You can also, in a csv file, create group access rights for a model for reading, writing, creating and deleting records, like in ../addons/account_analytic_default/security/ir.model.access.csv
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_account_analytic_default_salesman,account.analytic.default.salesman,model_account_analytic_default,sales_team.group_sale_salesman,1,1,1,1
in python code
In python code, you can, for example, check if the user executing the method is a part of certain group, like in ../addons/sale/models/product_product.py
@api.multi
def _sales_count(self):
r = {}
if not self.user_has_groups('sales_team.group_sale_salesman'):
return r
domain = [
('state', 'in', ['sale', 'done']),
('product_id', 'in', self.ids),
]
for group in self.env['sale.report'].read_group(domain, ['product_id', 'product_uom_qty'], ['product_id']):
r[group['product_id'][0]] = group['product_uom_qty']
for product in self:
product.sales_count = r.get(product.id, 0)
return r
And finally as @Charif DZ answered
groups is a syntax sugar to quickly add access rights to the menu, you
can do this not just in menu also in fields definition in py File, any
tag that can be used in the view,
groups="goup1_xml_id1,goup1_xml_id2,..."
And If you want to remove a group from predefined field in another Module use - before the
XML-ID of the group:
field_name = fields.TypeOfField(groups="-some_xml_group_id")