This question has been flagged
4 Replies
17831 Views

Im tring to add a custom Field to the Products, but i dont get it... When im right, i easily go to "database structure" and "fields" and klick "add". But then i stuck at the standart field on the right side, when im right i have to choose "product.product", set a name and Save the Bad boy. Is this correct so far?

Then the next step would be go to "user interface" then "view" and add my field. But what do i have to write at the object field?

Down at Architecture ist: <tree string="My view"> <field name="name"/> </tree>

and when i trie to safe the whole thing i get an error, that the xml code is wrong.

So how can i make it?

Avatar
Discard
Best Answer

r way of adding fields to a model is working, but limits you in what you can do with that field. If you need to do calculations based on that field, you cannot do it without modifying python code.

Also when you have done a lot of modifications like this, and you need to setup another database, you have to do it all over again, manually (this will give errors, because you forget one, or setup one field a bit different than on the other server).

The preferred method is to create a new module, and install that module to get the new field(s) and method(s).

Example of module:

my_module (folder with following files)
- __init__.py
- __openeerp__.py
- my_module_code.py
- my_module_code_view.xml

__init__.py

#name of python file with code
import my_module_code

__openerp__.py

{
    'name': 'Name of module,
    'version': '0.1',
    'category': 'Others',
    'complexity': "normal",
    'description': """ Some description of your module """
    'author': ['Your name'],
    'website': 'my.website.com',
    'depends': [
        "product" #name of module which is needed to be installed
    ],
    'init_xml': [
        #place here the XML with initial data
    ],
    'update_xml': [
        "my_module_code_view.xml",
    ],
    'demo_xml': [],
    'test': [],
    'installable': True,
    'auto_install': False,
    'application': False,
    'images': [],
    'js': [],
}

my_module_code.py

from openerp.osv import fields, osv

class product_product(osv.osv):
    """
Modified product.product
    """
    _inherit = "product.product"

    _columns = {
        'my_new_field': fields.char('LABEL new Field', select=True,
            help='HELP text when hovering over the label in openERP'),
    }

def my_method(self, cr, uid, ids):
    """Description of my_method """
    #do your actions here

def existing_method(self, cr, uid, ... ):
    """ Override existing method, use same parameters as original """
    # do some action
    res = super(product_product, self_).existing_method(cr, uid, ...)
    # do some more actions
    return res #might be modified

my_module_code_view.xml:

<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>
<!-- Adding the fields from product.product to the screen -->
        <record id="product_normal_form_view" model="ir.ui.view">
            <field name="name">base.product.defaults.product.form</field>
            <field name="model">product.product</field>
            <field name="inherit_id" ref="product.product_normal_form_view"/>
            <field name="arch" type="xml">
                <field name='default_code' position='before'>
                    <field name="my_new_field"/>
                </field>
            </field>
        </record>
    </data>
</openerp>
Avatar
Discard
Author

Okay, i see the problem and i dont think that i can handle it alone. Were a small Business in Germany and we really need this kind of Plugin. If you have time to support us (of course paid) it would be great if you could send me a message to w.aeneas (AT) me . com. Thanks!

@patrick, how did you insert formatted code in your answer?

Is there an option to add different fields depending on the product category? For example a RAM will have a "memory" field. But a keyboard will have a "color" field.

Best Answer

Hi Do i need some special permition in order OpenERP 7 to see the custom module ( i use Windows 7 )?

Avatar
Discard

After Installation somewhere in the server addon path, you must refresh the list of modules, for US Language is "Settings/Modules/Update". Then you can search your custom module in "Installed modules".

Best Answer

@patric. Great comment on adding an extra field module. I am however struggling to do the same with pos.order. The problem is with the view.xml, where I am not sure which model and id to reference.

My code is as follows:

<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>
<!-- Adding the fields from product.product to the screen -->
        <record id="product_normal_form_view" model="ir.ui.view">
            <field name="name">base.pos.defaults.order.form</field>
            <field name="model">pos.order</field>
            <field name="inherit_id" ref="pos.order.action_pos_pos_form"/>
            <field name="arch" type="xml">
                <field name='default_code' position='before'>
                    <field name="credit_card" string='Credit Card'/>
                </field>
            </field>
        </record>
    </data>
</openerp>

I am aware my problem lies with the record id=? and field name='inherit_id" ref=?. Would you be able to assist please. I attempted looking at point_of_sale_view.xml and tried to use the id I pressume was correct, to no avail. How do you determine the correct id? and what is the syntax?
Thank you in advance.

Avatar
Discard