This question has been flagged
2 Replies
3050 Views

Hi, I have Odoo 12.0-20200916 (Community Edition) running in Windows 10.
I created a custom model at Odoo12\server\odoo\addons\sale_management\models\my_sale_order.py
to add a new field to the form. Now I want to do something when record is save so i try to override the write method.

Below is my code for my_sale_order.py

from odoo import models, fields, api

class SaleOrder(models.Model):

_inherit = 'sale.order'

additional_note = fields.Char(string='Additional Note')

@api.multi

  def write(self, values):

res = super(SaleOrder, self).write(values)

# do something

return res

When i upgrade the Sales module it returns below error,

Odoo Server Error
Traceback (most recent call last):
  File "D:\MyData\Odoo\Odoo12\server\odoo\models.py", line 1128, in _validate_fields
    check(self)
  File "d:\mydata\odoo\odoo12\server\odoo\addons\base\models\ir_ui_view.py", line 351, in _check_xml
    self.postprocess_and_fields(view.model, view_doc, view.id)
  File "d:\mydata\odoo\odoo12\server\odoo\addons\base\models\ir_ui_view.py", line 1098, in postprocess_and_fields
    self.raise_view_error(_('Model not found: %(model)s') % dict(model=model), view_id)
  File "d:\mydata\odoo\odoo12\server\odoo\addons\base\models\ir_ui_view.py", line 568, in raise_view_error
    raise ValueError(message)
ValueError: Model not found: sale.order.template
Avatar
Discard

hope these customization tips will help you: https://sites.google.com/view/thinkincode/erp/odoo

Best Answer

Hello Theedi,


You cannot take 2 separate file of same object i.e sale.order in the same module. Due to this you are facing this issue.


The best practice is that you need to create a separate module for your custom changes and never do any changes in base odoo addons.


For reference:

How to create a seperate module in odoo 

- https://www.odoo.com/documentation/13.0/howtos/backend.html

- https://www.cybrosys.com/blog/how-create-module-odoo


For inheritane and create/write method in odoo:

- https://www.cybrosys.com/blog/types-of-inheritance-odoo

- https://www.odoo.com/es_ES/forum/ayuda-1/question/write-and-create-function-130691

Regards,




Email:      odoo@aktivsoftware.com  

Skype: kalpeshmaheshwari

   

Avatar
Discard