1
votes

I'm beginer in Odoo v8.0. I want to add a custom field into module "sale". The Error is "Field type_customer does not exist"

So my code here.

__init__.py:

from . import modify_type_quotation

__openerp__.py:

   {
       'name' : "Modify report template",
       'description' : """Modify report template for Quotation/Sale report""",
       'author' : "Nhu Van Tran",
       'category' : "Tools",
       'depends' : ['sale'],
       'data' : ['modify_create_quotation.xml'],
       'demo' : [],
       'installable' : True,
    }

modify_type_quotation.py:

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

from openerp import models, fields

class modify_print_content(models.Model):

   _inherit = "sale.order"
   _description = "Modify Print Content"

   type_customer = fields.selection([
                 ('Commercial', 'Commercial Customer'),
                 ('Residential', 'Risidential Customer'),
                 ], string = "Type of Customer", help = "Type of Customer", default = "Commercial", required = True)

and modify_create_quotation.xml:

 <?xml version="1.0" encoding="utf-8"?>
    <openerp>
       <data>
          <record model = "ir.ui.view" id = "modify_view_sale">
             <field name ="name">sale.order.form</field>
             <field name = "model">sale.order</field>
             <field name = "inherit_id" ref="sale.view_order_form"></field>
             <field name="arch" type="xml">
                <xpath expr="/form/sheet/group/group[2]/field[@name='client_order_ref']" position="after">
                    <field name="type_customer">Type customer</field>
                </xpath>
            </field>
          </record>
       </data>
    </openerp>
2

2 Answers

1
votes

I think the mistake is fields.selection where you made 's' in lowercase, and that could be the mistake.

type_customer = fields.Selection([
                 ('Commercial', 'Commercial Customer'),
                 ('Residential', 'Risidential Customer')
                 ], string = "Type of Customer", help = "Type of Customer", default = "Commercial", required = True)

Make sure you restart your odoo server, to get these things into effect.

1
votes

Your field in the xpath could be shorter :

<xpath expr="/form/sheet/group/group[2]/field[@name='client_order_ref']" position="after">
        <field name="type_customer"/>
    </xpath>

I don't know if it's the problem but adding an aditional parameter to the selectionfield declaration:

type_customer = fields.selection([
                 ('Commercial', 'Commercial Customer'),
                 ('Residential', 'Risidential Customer'),
                 ], "Type of Customer", help = "Type of Customer", default = "Commercial",select=True, required = True)

and I think the solution might be this: this would add the fields to sale.order instead of just inheriting the fields it already has

_name = "sale.order"
_inherit = "sale.order"