Skip to Content
Menu
This question has been flagged
4 Replies
10604 Views

Hello,

I am currently having a problem with Odoo. I have created a module to add a "title" field to the quotes and purchase order of the sales module, when I install my module everything works but now I can no longer update the sales module and the sales management module. When I try to update them I have the following error: "the field` title_id` does not exist ". Moreover when I uninstall my custom module I can no longer access the Odoo modules, I get the same error as during the update.

Here is my code :

my model:

from odoo import fields, models, api

class SaleTitre(models.Model):
    _inherit='sale.order'    
    _name='sale.order'       
    titre_id=fields.Char('Titre', size=250, store=True)   
    @api.multi
    def _prepare_invoice(self):    
        values = super(SaleTitre, self)._prepare_invoice()
        values.update({
            'titre_rel': self.titre_id,
        })
        return values
class InvoiceTitre(models.Model):
    _inherit='account.invoice'
    _name='account.invoice'
    titre_rel=fields.Char('Titre',size=250, store=True)     

My views :

<?xml version="1.0"?>
<odoo>
 <data>
 
 
    <record id="sale.view_quotation_tree_extend" model="ir.ui.view"> 
        <field name="name"> sale.order.quotation.tree.titre</field> 
        <field name="model">sale.order</field> 
        <field name="inherit_id" ref="sale.view_quotation_tree"/>
        <field name="arch" type="xml">   
        <xpath expr="//field[@name='partner_id']" position="after"> 
             <field name="titre_id" groups="base.group_user"/>  
           
         </xpath>
        </field>
  
    </record> 
  

 
  <record id="sale.view_tree_extend" model="ir.ui.view">   
        <field name="name"> sale.order.tree.titre</field> 
        <field name="model">sale.order</field>     
        <field name="inherit_id" ref="sale.view_order_tree"/>    
        <field name="arch" type="xml">    
        <xpath expr="//field[@name='partner_id']" position="after">  
             <field name="titre_id" groups="base.group_user"/>   
           
         </xpath>
        </field>
  
    </record> 
 


 
  <record id="sale.view_invoice_tree_extend" model="ir.ui.view">   
        <field name="name"> sale.order.invoice.tree.titre</field> 
        <field name="model">account.invoice</field>     
        <field name="inherit_id" ref="account.invoice_tree"/>    
        <field name="arch" type="xml">    
        <xpath expr="//field[@name='partner_id']" position="after">  
             <field name="titre_rel" groups="base.group_user"/>   
           
         </xpath>
        </field>
  
    </record> 
 

 
  <record id="sale.view_invoice_form_extend" model="ir.ui.view">   
        <field name="name"> sale.order.invoice.form.titre</field> 
        <field name="model">account.invoice</field>     
        <field name="inherit_id" ref="account.invoice_form"/>    
        <field name="arch" type="xml">    
        <xpath expr="//field[@name='partner_id']" position="after">  
             <field name="titre_rel" groups="base.group_user"/>   
           
         </xpath>
        </field>
  
    </record> 
 

 
    <record id="sale.view_order_form_extend" model="ir.ui.view">
        <field name="name"> sale.order.form.titre</field>
        <field name="model">sale.order</field>
        <field name="inherit_id" ref="sale.view_order_form"/>
        <field name="arch" type="xml">
        <xpath expr="//field[@name='payment_term_id']" position="after">
            <field name="titre_id"/>
        </xpath>
        </field>  
    </record>
  
    <record id="sale.view_quotation_titre_search" model="ir.ui.view">
        <field name="name"> sale.order.tree.titre.search</field>
        <field name="model">sale.order</field>
        <field name="inherit_id" ref="sale.view_sales_order_filter"/>
        <field name="arch" type="xml">
        <xpath expr="//field[@name='name']" position="after">
            <field name="titre_id"/>
        </xpath>
        </field>  
    </record>
    

    <record id="account.view_invoice_titre_search" model="ir.ui.view">
        <field name="name"> sale.order.tree.titre.search</field>
        <field name="model">account.invoice</field>
        <field name="inherit_id" ref="account.view_account_invoice_filter"/>
        <field name="arch" type="xml">
        <xpath expr="//field[@name='number']" position="after">
            <field name="titre_rel"/>
        </xpath>
        </field>  
    </record>
    
 

   </data>
</odoo>

My manifest:

# -*- coding: utf-8 -*-
{
    'name': ' Gestion des ventes-Ajout du champs Titre',  
    'description': """  
Pouvoir définir un titre aux devis/Bon de commande et factures
                        +
Transmission du titre lors de la génération de la facture à partir d'un devis/Bon de commande
""",
    'author': 'Rockyozen',
    'depends': ['sale'],      
    'data': ['views/sale_titre.xml'],      
    'application': False, 
}


The error :

Traceback (most recent call last):
  File "/opt/odoo/odoo11/odoo/models.py", line 1057, in _validate_fields
    check(self)
  File "/opt/odoo/odoo11/odoo/addons/base/ir/ir_ui_view.py", line 342, in _check_xml
    self.postprocess_and_fields(view.model, view_doc, view.id)
  File "/opt/odoo/odoo11/odoo/addons/base/ir/ir_ui_view.py", line 1083, in postprocess_and_fields
    self.raise_view_error(message, view_id)
  File "/opt/odoo/odoo11/odoo/addons/base/ir/ir_ui_view.py", line 533, in raise_view_error
    raise ValueError(message)
ValueError: Le champ `titre_id` n'existe pas
Contexte de l'erreur :
Vue `sale.order.tree`
[view_id: 652, xml_id: sale.view_order_tree, model: sale.order, parent_id: n/a]
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/opt/odoo/odoo11/odoo/tools/convert.py", line 745, in parse
    self._tags[rec.tag](rec, de, mode=mode)
  File "/opt/odoo/odoo11/odoo/tools/convert.py", line 655, in _tag_record
    id = self.env(context=rec_context)['ir.model.data']._update(rec_model, self.module, res, rec_id or False, not self.isnoupdate(data_node), noupdate=self.isnoupdate(data_node), mode=self.mode)
  File "/opt/odoo/odoo11/odoo/addons/base/ir/ir_model.py", line 1488, in _update
    record.write(values)
  File "/opt/odoo/odoo11/odoo/addons/base/ir/ir_ui_view.py", line 425, in write
    res = super(View, self).write(self._compute_defaults(vals))
  File "/opt/odoo/odoo11/odoo/models.py", line 3184, in write
    field.determine_inverse(records)
  File "/opt/odoo/odoo11/odoo/fields.py", line 1092, in determine_inverse
    getattr(records, self.inverse)()
  File "/opt/odoo/odoo11/odoo/addons/base/ir/ir_ui_view.py", line 273, in _inverse_arch
    view.write(data)
  File "/opt/odoo/odoo11/odoo/addons/base/ir/ir_ui_view.py", line 425, in write
    res = super(View, self).write(self._compute_defaults(vals))
  File "/opt/odoo/odoo11/odoo/models.py", line 3164, in write
    self._write(old_vals)
  File "/opt/odoo/odoo11/odoo/models.py", line 3335, in _write
    self._validate_fields(vals)
  File "/opt/odoo/odoo11/odoo/models.py", line 1061, in _validate_fields
    raise ValidationError("%s\n\n%s" % (_("Error while validating constraint"), tools.ustr(e)))
odoo.exceptions.ValidationError: ("Erreur lors de la validation de la contrainte\n\nLe champ `titre_id` n'existe pas\n\nContexte de l'erreur :\nVue `sale.order.tree`\n[view_id: 652, xml_id: sale.view_order_tree, model: sale.order, parent_id: n/a]", None)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/opt/odoo/odoo11/odoo/http.py", line 653, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/opt/odoo/odoo11/odoo/http.py", line 312, in _handle_exception
    raise pycompat.reraise(type(exception), exception, sys.exc_info()[2])
  File "/opt/odoo/odoo11/odoo/tools/pycompat.py", line 87, in reraise
    raise value
  File "/opt/odoo/odoo11/odoo/http.py", line 695, in dispatch
    result = self._call_function(**self.params)
  File "/opt/odoo/odoo11/odoo/http.py", line 344, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "/opt/odoo/odoo11/odoo/service/model.py", line 97, in wrapper
    return f(dbname, *args, **kwargs)
  File "/opt/odoo/odoo11/odoo/http.py", line 337, in checked_call
    result = self.endpoint(*a, **kw)
  File "/opt/odoo/odoo11/odoo/http.py", line 939, in __call__
    return self.method(*args, **kw)
  File "/opt/odoo/odoo11/odoo/http.py", line 517, in response_wrap
    response = f(*args, **kw)
  File "/opt/odoo/odoo11/addons/web/controllers/main.py", line 939, in call_button
    action = self._call_kw(model, method, args, {})
  File "/opt/odoo/odoo11/addons/web/controllers/main.py", line 927, in _call_kw
    return call_kw(request.env[model], method, args, kwargs)
  File "/opt/odoo/odoo11/odoo/api.py", line 699, in call_kw
    return call_kw_multi(method, model, args, kwargs)
  File "/opt/odoo/odoo11/odoo/api.py", line 690, in call_kw_multi
    result = method(recs, *args, **kwargs)
  File "<decorator-gen-51>", line 2, in button_immediate_upgrade
  File "/opt/odoo/odoo11/odoo/addons/base/module/module.py", line 72, in check_and_log
    return method(self, *args, **kwargs)
  File "/opt/odoo/odoo11/odoo/addons/base/module/module.py", line 618, in button_immediate_upgrade
    return self._button_immediate_function(type(self).button_upgrade)
  File "/opt/odoo/odoo11/odoo/addons/base/module/module.py", line 552, in _button_immediate_function
    modules.registry.Registry.new(self._cr.dbname, update_module=True)
  File "/opt/odoo/odoo11/odoo/modules/registry.py", line 85, in new
    odoo.modules.load_modules(registry._db, force_demo, status, update_module)
  File "/opt/odoo/odoo11/odoo/modules/loading.py", line 379, in load_modules
    force, status, report, loaded_modules, update_module, models_to_check)
  File "/opt/odoo/odoo11/odoo/modules/loading.py", line 274, in load_marked_modules
    perform_checks=perform_checks, models_to_check=models_to_check
  File "/opt/odoo/odoo11/odoo/modules/loading.py", line 181, in load_module_graph
    _load_data(cr, module_name, idref, mode, kind='data')
  File "/opt/odoo/odoo11/odoo/modules/loading.py", line 95, in _load_data
    tools.convert_file(cr, module_name, filename, idref, mode, noupdate, kind, report)
  File "/opt/odoo/odoo11/odoo/tools/convert.py", line 792, in convert_file
    convert_xml_import(cr, module, fp, idref, mode, noupdate, report)
  File "/opt/odoo/odoo11/odoo/tools/convert.py", line 853, in convert_xml_import
    obj.parse(doc.getroot(), mode=mode)
  File "/opt/odoo/odoo11/odoo/tools/convert.py", line 752, in parse
    exc_info[2]
  File "/opt/odoo/odoo11/odoo/tools/pycompat.py", line 86, in reraise
    raise value.with_traceback(tb)
  File "/opt/odoo/odoo11/odoo/tools/convert.py", line 745, in parse
    self._tags[rec.tag](rec, de, mode=mode)
  File "/opt/odoo/odoo11/odoo/tools/convert.py", line 655, in _tag_record
    id = self.env(context=rec_context)['ir.model.data']._update(rec_model, self.module, res, rec_id or False, not self.isnoupdate(data_node), noupdate=self.isnoupdate(data_node), mode=self.mode)
  File "/opt/odoo/odoo11/odoo/addons/base/ir/ir_model.py", line 1488, in _update
    record.write(values)
  File "/opt/odoo/odoo11/odoo/addons/base/ir/ir_ui_view.py", line 425, in write
    res = super(View, self).write(self._compute_defaults(vals))
  File "/opt/odoo/odoo11/odoo/models.py", line 3184, in write
    field.determine_inverse(records)
  File "/opt/odoo/odoo11/odoo/fields.py", line 1092, in determine_inverse
    getattr(records, self.inverse)()
  File "/opt/odoo/odoo11/odoo/addons/base/ir/ir_ui_view.py", line 273, in _inverse_arch
    view.write(data)
  File "/opt/odoo/odoo11/odoo/addons/base/ir/ir_ui_view.py", line 425, in write
    res = super(View, self).write(self._compute_defaults(vals))
  File "/opt/odoo/odoo11/odoo/models.py", line 3164, in write
    self._write(old_vals)
  File "/opt/odoo/odoo11/odoo/models.py", line 3335, in _write
    self._validate_fields(vals)
  File "/opt/odoo/odoo11/odoo/models.py", line 1061, in _validate_fields
    raise ValidationError("%s\n\n%s" % (_("Error while validating constraint"), tools.ustr(e)))
odoo.tools.convert.ParseError: "Erreur lors de la validation de la contrainte
Le champ `titre_id` n'existe pas
Contexte de l'erreur :
Vue `sale.order.tree`
[view_id: 652, xml_id: sale.view_order_tree, model: sale.order, parent_id: n/a]
None" while parsing /opt/odoo/odoo11/addons/sale/views/sale_views.xml:148, near
<record id="view_order_tree" model="ir.ui.view">
            <field name="name">sale.order.tree</field>
            <field name="model">sale.order</field>
            <field name="priority">2</field>
            <field name="arch" type="xml">
                <tree string="Sales Orders" decoration-bf="message_needaction==True" decoration-muted="state=='cancel'">
                    <field name="message_needaction" invisible="1"/>
                    <field name="name" string="Order Number"/>
                    <field name="confirmation_date" string="Confirmation Date"/>
                    <field name="partner_id"/>
                    <field name="user_id"/>
                    <field name="amount_total" sum="Total Tax Included" widget="monetary"/>
                    <field name="currency_id" invisible="1"/>
                    <field name="invoice_status" invisible="1"/>
                    <field name="state" invisible="1"/>
                </tree>
            </field>
        </record>

If anyone can help me, I would be very grateful.
Thank you for your time !
Avatar
Discard
Best Answer

Hello Rockyzen,

The field you mentioned in the error is 'title_id' does not exist and in the code, you've defined the field as 'titre_id'.

'title_id' must be there in the database and removed from code. Make sure you've 'titre_id' in the database and not 'title_id'.

You can create a new database and look into it.

Hope this is helpful to you.

Thank you!

Regards,




Email:      odoo@aktivsoftware.com  

Skype: kalpeshmaheshwari

   

Avatar
Discard
Author Best Answer

I fixed the problem, thanks to everyone who tried to help me !!

Here is my procedure:


During all of the procedures below, you should definitely not go to the Sales application.


1 / From the Odoo interface you have to delete the views created by my module


2 / In my module, delete all the code of the model except the classes and the “_inherit”


3 / Delete the “views” folder from the module


4 / Delete the “data” line from the module manifest


5 / Uninstall my module


6 / Relaunch the Odoo server


7 / Update the “Sales” and “sales management” modules


8 / Install my module


9 / Update the “Sales” and “sales management” modules


10 / Put back the previously deleted code in the module, without forgetting the “views” folder and the “data” line in the manifest. You must change the id of the views of the module (ex: sale. View_quotation_tree_extend ----> view_quotation_tree_extend)


+ When doing this kind of inheritance you should not put a "_name" in your model


 

11 / Relaunch the Odoo server

12 / Update my module

13 / Update the “sales” and “sales management” modules


and it's done !

Avatar
Discard
Best Answer

Hi,

I check your code,

1. First check model name given in init.py.

2. add depends = ['sale','account']

3. In xml change id .( ex : sale.id_name change to id_name)


After change, Confirm module will be install

Avatar
Discard
Best Answer

Hi,

Can you remove the name attribute given from the model and see,

Change the below,

class SaleTitre(models.Model):
_inherit='sale.order'
_name='sale.order'

To

class SaleTitre(models.Model):
_inherit = 'sale.order'

Apply the same for the other model also.


Reference: How To Inherit And Add Field to Existing Views In Odoo12

Thanks

Avatar
Discard
Related Posts Replies Views Activity
2
Jul 24
939
1
Jun 24
3560
1
Oct 23
8578
1
Oct 23
97
1
Aug 23
2192