Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

One module, two tables

By
Uillino
on 7/28/15, 9:05 AM 875 views

Maybe this is a silly question, but I don't know the answer.

I need a module that is able to split the input data into two different tables. I've understood that I have to create two different classes, but I don't know I can merge them into the same view.

I need only one form to put my data into and two tables with different attributes.

Thank you!

Please give proper example of what exactly you want to do.

Emipro Technologies Pvt. Ltd.
on 7/28/15, 9:28 AM
2

Axel Mendoza

--Axel Mendoza--
10238
| 7 7 8
Camaguey, Cuba
--Axel Mendoza--

DevOps - Full stack - Software Architect - Developer - Technology Integrator

I could help you to develop anything and solve complex problems based on technologies, integrations and tricky stuffs mostly in Python with OpenERP/Odoo, Zato, Django and many others frameworks programming languages and technologies.

I offers consulting services to anyone with an unanswered questions or needs for customizations. Think about it, maybe it's better to have an expert to solve your issues and projects than having a full time employee trying to understand what to do an how

Reach me at aekroft@gmail.com

Axel Mendoza
On 7/28/15, 11:43 AM

You can do this more simple using inheritance by delegation, using _inherits syntax in the model class. That way you could use in the view the fields of the other model like if they were declared in the same model and they will be saved in their own model table. You can have something like this:

 # -*- encoding: utf-8 -*-
from openerp.osv import fields, osv
from openerp import models

class mymodule_test(osv.osv):
    _name = 'mymodule.test'
    _description = 'mymodule
    
    _inherits = {'mymodule.2module': 'mod_id'}

    columns = {
        'name': fields.char('Name', size=128, help="Insert your name", required=True),
        'surname': fields.char('Surname', size=128, required=True),
        'mod_id': fields.many2one('mymodule.2module', string="mymodule"),
    }

class mymodule_2db(osv.osv):
    _name = 'mymodule.2module'
    _description = 'mymodule'
               
    _columns = {
        'select': fields.boolean('Select?', default=True),
    }

In the view:

 <?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>
        <record id="view_mymodule_tree" model="ir.ui.view">
         <field name="name">mymodule.test.tree</field>
         <field name="model">mymodule.test</field>
         <field name="arch" type="xml">
        <tree string="mymodule">
         <field name="name"/>
         <field name="surname"/>
<field name="select"/>
             </tree>
            </field>
        </record>
    </data>
</openerp>

more clean this way

0
Uillino
On 7/28/15, 9:52 AM

This is my original view:

<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="view_mymodule_tree" model="ir.ui.view">
<field name="name">mymodule.test.tree</field>
<field name="model">mymodule.test</field>
<field name="arch" type="xml">
<tree string="mymodule">
<field name="name"/>
<field name="surname"/>
     </tree>
</field>
</record>
</data>
</openerp>

and this is my model:

# -*- encoding: utf-8 -*-
from openerp.osv import fields, osv
from openerp import models

lass mymodule_test(osv.osv):
_name = 'mymodule.test'
_description = 'mymodule

columns = {

'name': fields.char('Name', size=128, help="Insert your name", required=True),
'surname': fields.char('Surname', size=128, required=True),

So, I have only one table (mymodule_test) with the attribure name and surname.

Now I want to add this class:

class mymodule_2db(osv.osv):
_name = 'mymodule.2module'
_description = 'mymodule'

_columns = {

'select': fields.boolean('Select?', default=True),
}

and I have updated my view:

<record id="view_mymodule_add" model="ir.ui.view"> 
<field name="name">mymodule.2module</field>
<field name="model">mymodule.2module</field>
<field name="arch" type="xml">
<form string="Address">
<sheet>
    <group name="group_top">
<group name="group_left">
    <field name="select" />
</group>
                   </group>
                   </sheet>
       </form>
   </field>
</record>

So I'm able to create anothe table (mymodule_2module) with the attribute 'select'.

I would like to have only one form (in the same page) where user can input 'name', 'surname' and could select 'select': 'name' and 'surname' must be writter in the table 'mymodule_test'; 'select' in the table 'mymodule_2module', using a foreign key.

0
sharjeel ali shaukat
On 7/28/15, 9:21 AM

Yes you can do it just call create of second table model in first table model create method

For example


def create(self, cr, uid, values, context=None):

    values1 = {"name":values.get('name'),"street":values.get('address')}

    partner = self.pool.get("res.partner").create(cr, uid, values1);

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

2 follower(s)

Stats

Asked: 7/28/15, 9:05 AM
Seen: 875 times
Last updated: 7/29/15, 5:53 AM