Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
1 Відповісти
21390 Переглядів

Hello,

I can create new module by inheriting other models and fields data saved in existing table but I want to create new module which data will save in new table in database.

can anyone help me or give me a sample model please.

Аватар
Відмінити
Найкраща відповідь

To create new module you must:

1. Create a folder in Addons

2. Create __init__.py

3. Create __openerp__.py

4. Create your module.py file

5. Create your module_view.xml file

6. Security folder and inside of this folder ir.model.access.csv where you can put some information about access etc

__init__.py should contain: import your_module/s_name/s

example:

# -*- coding: utf-8 -*-

import your_module_name


__openerp__.py should contain: a description of your module, dependencies, vews etc

example:

{

'name': 'Base',

'version': '1.3',

'category': 'Hidden',

'description': """

The kernel of OpenERP, needed for all installation.

===================================================

""",

'author': 'OpenERP SA',

'maintainer': 'OpenERP SA',

'website': 'http://www.openerp.com',

'depends': [],

'data': [

'base_data.xml',

'res/res_currency_data.xml',

'res/res_country_data.xml',

'security/base_security.xml',

'module/module_report.xml',

'module/wizard/base_module_update_view.xml',

'res/res_company_view.xml',

'res/res_security.xml',

'security/ir.model.access.csv',

],

'demo': [

'base_demo.xml',

'res/res_partner_demo.xml',

'res/res_partner_demo.yml',

'res/res_partner_image_demo.xml',

],

'test': [

'tests/base_test.yml',

'tests/test_osv_expression.yml',

'tests/test_ir_rule.yml', # <-- These tests modify/add/delete ir_rules.

],

'installable': True,

'auto_install': True,

}

your_module_view.xml should contain your_module_view_definition:

example:

<?xml version="1.0" encoding="utf-8"?>

<openerp>

<data>

<record model="ir.actions.act_window" id="base.action_res_groups">

<field name="name">Groups</field>

<field name="context">{'search_default_no_share': 1}</field>

</record>

<record id="view_groups_form_share" model="ir.ui.view">

<field name="name">res.groups.form</field>

<field name="model">res.groups</field>

<field name="inherit_id" ref="base.view_groups_form"/>

<field name="arch" type="xml">

<field name="users" position="attributes">

<attribute name="context">{'search_default_no_share':1}</attribute>

</field>

<field name="name" position="after">

<field name="share"/>

</field>

</field>

</record>

</data>

</openerp>

your_module.py should contain:

#class with _columns will create your table with your columns

class your_class(osv.osv):

_name = 'your.class'#your new table

_description = 'Your class description'

_columns = {

'your_field_1': fields.type_of_field('Field name'),

'your_field_2': fields.type_of_field('Field name'),

'your_field_3': fields.type_of_field('Field name'),

'your_field_4': fields.type_of_field('Field name'),

}

    def your_def(self, cr, uid, args, fields, context=None):#check manual in case you need some special args o kwargs etc

        do something

Of course it's just a basics but .... that's all you need to build your own module. :)


Аватар
Відмінити
Автор

Thank you so much Obx.... I appreciate your help.

Nice answer @Dr. Obx +1

Your'e welcome :)

While Dr Obx's answer is pretty thorough, might I point out: 1) it's missing the import statement in your_module.py 2) We should be helping new people learn the new API

@Anchal: The key to creating a new table is the line: '_name = your.class'.

Related Posts Відповіді Переглядів Дія
3
трав. 24
14465
1
черв. 16
2890
2
черв. 16
3206
0
трав. 16
2836
3
січ. 16
5457