1
votes

I'm following a tutorial on Odoo and I have to create a new view to easily create/edit payment methods. Adding the many2one field in Sales Order works but once i add the xml lines given in the tutorial and upgrade it gives an error. Restarting the service results in an Internal Server Error.

The init is correct so that shouldnt be the problem, the py without the xml changes works fine.

This is the error i get

    Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 537, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 574, in dispatch
    result = self._call_function(**self.params)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 310, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 113, in wrapper
    return f(dbname, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 307, in checked_call
    return self.endpoint(*a, **kw)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 803, in __call__
    return self.method(*args, **kw)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 403, in response_wrap
    response = f(*args, **kw)
  File "/usr/lib/python2.7/dist-packages/openerp/addons/web/controllers/main.py", line 948, in call_button
    action = self._call_kw(model, method, args, {})
  File "/usr/lib/python2.7/dist-packages/openerp/addons/web/controllers/main.py", line 936, in _call_kw
    return getattr(request.registry.get(model), method)(request.cr, request.uid, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 241, in wrapper
    return old_api(self, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/addons/base/module/module.py", line 533, in button_immediate_upgrade
    return self._button_immediate_function(cr, uid, ids, self.button_upgrade, context=context)
  File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 241, in wrapper
    return old_api(self, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/addons/base/module/module.py", line 494, in _button_immediate_function
    registry = openerp.modules.registry.RegistryManager.new(cr.dbname, update_module=True)
  File "/usr/lib/python2.7/dist-packages/openerp/modules/registry.py", line 370, in new
    openerp.modules.load_modules(registry._db, force_demo, status, update_module)
  File "/usr/lib/python2.7/dist-packages/openerp/modules/loading.py", line 351, in load_modules
    force, status, report, loaded_modules, update_module)
  File "/usr/lib/python2.7/dist-packages/openerp/modules/loading.py", line 255, in load_marked_modules
    loaded, processed = load_module_graph(cr, graph, progressdict, report=report, skip_modules=loaded_modules, perform_checks=perform_checks)
  File "/usr/lib/python2.7/dist-packages/openerp/modules/loading.py", line 176, in load_module_graph
    _load_data(cr, module_name, idref, mode, kind='data')
  File "/usr/lib/python2.7/dist-packages/openerp/modules/loading.py", line 118, in _load_data
    tools.convert_file(cr, module_name, filename, idref, mode, noupdate, kind, report)
  File "/usr/lib/python2.7/dist-packages/openerp/tools/convert.py", line 901, in convert_file
    convert_xml_import(cr, module, fp, idref, mode, noupdate, report)
  File "/usr/lib/python2.7/dist-packages/openerp/tools/convert.py", line 987, in convert_xml_import
    obj.parse(doc.getroot(), mode=mode)
  File "/usr/lib/python2.7/dist-packages/openerp/tools/convert.py", line 853, in parse
    self._tags[rec.tag](self.cr, rec, n, mode=mode)
  File "/usr/lib/python2.7/dist-packages/openerp/tools/convert.py", line 763, in _tag_record
    id = self.pool['ir.model.data']._update(cr, self.uid, rec_model, self.module, res, rec_id or False, not self.isnoupdate(data_node), noupdate=self.isnoupdate(data_node), mode=self.mode, context=rec_context )
  File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 241, in wrapper
    return old_api(self, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/addons/base/ir/ir_model.py", line 1077, in _update
    res_id = model_obj.create(cr, uid, values, context=context)
  File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 241, in wrapper
    return old_api(self, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/addons/base/ir/ir_ui_view.py", line 264, in create
    context=context)
  File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 241, in wrapper
    return old_api(self, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 336, in old_api
    result = method(recs, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/models.py", line 4076, in create
    record = self.browse(self._create(old_vals))
  File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 239, in wrapper
    return new_api(self, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 463, in new_api
    result = method(self._model, cr, uid, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/models.py", line 4267, in _create
    recs._validate_fields(vals)
  File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 239, in wrapper
    return new_api(self, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/models.py", line 1271, in _validate_fields
    raise ValidationError('\n'.join(errors))
ParseError: "ValidateError
Field(s) `arch` failed against a constraint: Invalid view definition

Error details:
Field `writeoff` does not exist

Error context:
View `xx.payment.method tree`
[view_id: 868, xml_id: n/a, model: xx.payment.method, parent_id: n/a]" while parsing /home/pantera/Custom/xx_khleuven2/view/sale.xml:18, near
<record id="view_payment_method_tree" model="ir.ui.view">
            <field name="model">xx.payment.method</field>
            <field name="arch" type="xml">
                <tree string="Payment methods">
                    <field name="name"/>
                    <field name="writeoff"/>
                </tree>
            </field>
        </record>

My py file

   from datetime import datetime, timedelta
   import time
   from openerp.osv import fields, osv
   from openerp.tools.translate import _
   from openerp.tools import DEFAULT_SERVER_DATE_FORMAT, DEFAULT_SERVER_DATETIME_FORMAT
   import openerp.addons.decimal_precision as dp
   from openerp import workflow

class SaleOrder(osv.Model):
    _inherit = 'sale.order'

    _columns = {
        'xx_delivery_date': fields.date(string='Delivery date'),
        #'xx_payment_method': fields.selection([('visa', 'Visa'),
        #                                       ('cash', 'Cash')],
        #                                      string='Payment method'),
        'xx_payment_method': fields.many2one('xx.payment.method',
                                             string='Payment method')
    }

class PaymentMethod(osv.Model):
    _name = 'xx.payment.method'

    _columns = {
        'name': fields.char(size=128, string='Name'),
        'writeoff': fields.boolean(string='Writeoff'),
        'sale_ids': fields.one2many('sale.order', 'xx_payment_method',
                                    string='Sale orders')
    }

The xml file. Between the ------ lines is the part that should create the new menu.

  <?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>
        <record id="view_order_form" model="ir.ui.view">
            <field name="model">sale.order</field>
            <field name="inherit_id" ref="sale.view_order_form"/>
            <field name="arch" type="xml">
                <field name="client_order_ref" position="after">
                    <field name="xx_delivery_date"/>
                </field>

                <xpath expr="//form//field[@name='client_order_ref']" position="after">
                    <field name="xx_payment_method"/>
                </xpath>
            </field>
        </record>
        -------------------------------------------------------------
        <record id="view_payment_method_tree" model="ir.ui.view">
            <field name="model">xx.payment.method</field>
            <field name="arch" type="xml">
                <tree string="Payment methods">
                    <field name="name"/>
                    <field name="writeoff"/>
                </tree>
            </field>
        </record>

        <record id="action_payment_method" model="ir.actions.act_window">
            <field name="name">Payment methods</field>
            <field name="res_model">xx.payment.method</field>
            <field name="view_type">form</field>
            <field name="view_mode">tree,form</field>
        </record>

        <menuitem id="menu_payment_method" action="action_payment_method"
             parent="base.menu_base_config"/>
       -------------------------------------------------------------
    </data>
</openerp>

I don't have a clue on why the field is not recognized, I have compared it with the code from the tutorial and I can't find any differences.

Thanks in advance.

edit: I tried renaming the fields and then the 'writeoff' doesn't give the error but the 'name' field does. Remaning the 'name' field doesn't change anything, the error stays on that field.

Edit2: Ok the problem seems to have fixed itself and I have no idea why.. came back after a frustration break and tried again and everything worked so yea... Thanks for the help anyway!

1
did you restarted the server when you updated you .py file? When you modify any changes in .py file you need to restart the openerp server, to bring those changes in implementation. - Hardik Patadia

1 Answers

1
votes

Agree with @HardikPatadia: the error you get ("field not found") would normally be solved after restarting the server which reloads the py files. You say that restarting gives you an Internal Server Error, so you should check the Odoo log file to see what the error is - probably some python error.

Another thing that could be wrong is that you did not import your py file in init.py, so the fields are not recognized.