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

how to add a field created in a third object from custom module in inherited form ?

By
PY
on 11/28/13, 12:18 PM 550 views

Hi !

I have a field that I want to add to an inherited form. But I don't know how to do this. The field exist in another third object that I created with my module.

Here's my complete code for now :

shipping.py :

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

import openerp
from openerp import netsvc, tools, pooler
from openerp.osv import fields, osv
from openerp.tools.translate import _
import time

class shipping_rule(osv.osv):
    _name = 'shipping_rule'
    _order = 'shipping_rule_name asc'

    _columns = {
        'field_ids': fields.one2many('res.company', 'shipping_rule_id', required=True),
        'shipping_rule_name': fields.char('Rule name', size=128, required=True)
    }

    _sql_constraints = [
        ('uniq_name', 'unique(shipping_rule_name)', "A shipping rule already exists with this name. Shipping rule's name must be unique!"),
    ]


class inherit_res_company_for_shipping_rule(osv.osv):
    _name = 'res.company'
    _inherit = 'res.company'

    _columns = {
        'shipping_rule_id': fields.many2one('shipping_rule', 'Shipping rule', required=True)
    }

shipping_view.xml :

<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>
        <!-- form -->
        <record model="ir.ui.view" id="shipping_rule_form">
            <field name="name">shipping_rule.form</field>
            <field name="model">shipping_rule</field>
            <field name="priority" eval="2"/>
            <field name="arch" type="xml">
                <form string="Shipping rules" version="7.0">
                    <group col="2">
                        <field name="shipping_rule_name" /> 
                    </group>
                </form>
            </field>
        </record>
        <!-- tree -->
        <record model="ir.ui.view" id="shipping_rule_tree">
            <field name="name">shipping_rule.tree</field>
            <field name="model">shipping_rule</field>
            <field name="arch" type="xml">
                <tree string="Shipping rules">
                    <field name="shipping_rule_name"/>
                </tree>
            </field>
        </record>
        <!-- search -->
        <record model="ir.ui.view" id="shipping_rule_search">
            <field name="name">shipping_rule.search</field>
            <field name="model">shipping_rule</field>
            <field name="arch" type="xml">
                <search string="Shipping rules">
                    <field name="shipping_rule_name"/>
                </search>
            </field>
        </record>
        <!-- action -->
        <record model="ir.actions.act_window" id="action_shipping_rule">
            <field name="name">Shipping rules</field>
            <field name="type">ir.actions.act_window</field>
            <field name="res_model">shipping_rule</field>
            <field name="view_type">form</field>
            <field name="view_mode">form,tree</field>
            <field name="view_id" ref="shipping_rule_form"/>
            <field name="help" type="html">
                <p class="oe_view_nocontent_create">
                    Click here to create a shipping rule.
                </p>
            </field>
        </record>
        <!-- menus -->
        <menuitem 
            name="Shipping rules"
            id="menu_shipping_rule"
            parent="base.menu_purchase_root"
            sequence="16"
        />
        <menuitem
            id="menu_action_pos_cashier"
            parent="menu_shipping_rule"
            action="action_shipping_rule"
        />
    </data>
</openerp>

shipping_company_view.xml :

<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>   
        <!-- form -->
        <record model="ir.ui.view" id="shipping_res_company_form">
            <field name="name">res.company.form</field>
            <field name="model">res.company</field>
            <field name="view_type">form</field>
            <field name="inherit_id" ref="base.view_company_form"/>
            <field name="arch" type="xml">
                <field name="name" position="after">
                    <field name="?????????????????"/>
                </field>
            </field>
        </record>
    </data>
</openerp>

Thanks in advance !

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

0 follower(s)

Stats

Asked: 11/28/13, 12:18 PM
Seen: 550 times
Last updated: 3/16/15, 8:10 AM