0

I'm trying to get a client_order_ref from a sale order, from the account.invoice module. I don't know why it says that the field doesn't exits, and the field it's defined. Please help me

Python code

from odoo import models, fields, api, _

class AccountInvoice(models.Model):
    _inherit = 'account.invoice'

    client_order_ref = fields.Char(string="Client Order Ref", compute="get_client_from_sale_order")

    @api.depends('name')
    def get_client_from_sale_order(self):
        self.ensure_one()
        for rec in self:
            sale_order = self.env['sale.order'].search(
                [('name', '=', rec.origin)]
            )

            rec.client_order_ref = sale_order.client_order_ref

XML code

<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <record id="invoice_tree" model="ir.ui.view">
        <field name="name">account_invoice_tree_inherit</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="client_order_ref"/>
            </xpath>
        </field>
    </record>
</odoo>

TRACEBACK

Error: Odoo Server Error

Traceback (most recent call last): File "/opt/odoo/custom/src/odoo/odoo/models.py", line 1128, in _validate_fields check(self) File "/opt/odoo/custom/src/odoo/odoo/addons/base/models/ir_ui_view.py", line 351, in _check_xml self.postprocess_and_fields(view.model, view_doc, view.id) File "/opt/odoo/custom/src/odoo/odoo/addons/base/models/ir_ui_view.py", line 1138, in postprocess_and_fields self.raise_view_error(message, view_id) File "/opt/odoo/custom/src/odoo/odoo/addons/base/models/ir_ui_view.py", line 568, in raise_view_error raise ValueError(message) ValueError: Field client_order_ref does not exist

Error context: View account_invoice_tree_inherit [view_id: 1311, xml_id: cloudpiles_custom.invoice_tree, model: account.invoice, parent_id: 681]

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/opt/odoo/custom/src/odoo/odoo/tools/convert.py", line 758, in parse self._tags[rec.tag](rec, de, mode=mode) File "/opt/odoo/custom/src/odoo/odoo/tools/convert.py", line 663, in _tag_record record = model.with_context(rec_context)._load_records([data], self.mode == 'update') File "/opt/odoo/custom/src/odoo/odoo/models.py", line 3883, in _load_records data['record']._load_records_write(data['values']) File "/opt/odoo/custom/src/odoo/odoo/addons/base/models/ir_ui_view.py", line 1542, in _load_records_write super(View, self)._load_records_write(values) File "/opt/odoo/custom/src/odoo/odoo/models.py", line 3821, in _load_records_write self.write(values) File "/opt/odoo/custom/src/odoo/odoo/addons/base/models/ir_ui_view.py", line 445, in write res = super(View, self).write(self._compute_defaults(vals)) File "/opt/odoo/custom/src/odoo/odoo/models.py", line 3392, in write fields[0].determine_inverse(records) File "/opt/odoo/custom/src/odoo/odoo/fields.py", line 1200, in determine_inverse getattr(records, self.inverse)() File "/opt/odoo/custom/src/odoo/odoo/addons/base/models/ir_ui_view.py", line 275, in _inverse_arch view.write(data) File "/opt/odoo/custom/src/odoo/odoo/addons/base/models/ir_ui_view.py", line 445, in write res = super(View, self).write(self._compute_defaults(vals)) File "/opt/odoo/custom/src/odoo/odoo/models.py", line 3366, in write self._write(store_vals) File "/opt/odoo/custom/src/odoo/odoo/models.py", line 3502, in _write self._validate_fields(vals) File "/opt/odoo/custom/src/odoo/odoo/models.py", line 1132, in validate_fields raise ValidationError("%s\n\n%s" % (("Error while validating constraint"), tools.ustr(e))) odoo.exceptions.ValidationError: ('Error while validating constraint\n\nField client_order_ref does not exist\n\nError context:\nView account_invoice_tree_inherit\n[view_id: 1311, xml_id: cloudpiles_custom.invoice_tree, model: account.invoice, parent_id: 681]', None)

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/opt/odoo/custom/src/odoo/odoo/http.py", line 656, in _handle_exception return super(JsonRequest, self)._handle_exception(exception) File "/opt/odoo/custom/src/odoo/odoo/http.py", line 314, in _handle_exception raise pycompat.reraise(type(exception), exception, sys.exc_info()[2]) File "/opt/odoo/custom/src/odoo/odoo/tools/pycompat.py", line 87, in reraise raise value File "/opt/odoo/custom/src/odoo/odoo/http.py", line 698, in dispatch result = self._call_function(**self.params) File "/opt/odoo/custom/src/odoo/odoo/http.py", line 346, in _call_function return checked_call(self.db, *args, **kwargs) File "/opt/odoo/custom/src/odoo/odoo/service/model.py", line 98, in wrapper return f(dbname, *args, **kwargs) File "/opt/odoo/custom/src/odoo/odoo/http.py", line 339, in checked_call result = self.endpoint(*a, **kw) File "/opt/odoo/custom/src/odoo/odoo/http.py", line 941, in call return self.method(*args, **kw) File "/opt/odoo/custom/src/odoo/odoo/http.py", line 519, in response_wrap response = f(*args, **kw) File "/opt/odoo/auto/addons/web/controllers/main.py", line 967, in call_button action = self._call_kw(model, method, args, {}) File "/opt/odoo/auto/addons/web/controllers/main.py", line 955, in _call_kw return call_kw(request.env[model], method, args, kwargs) File "/opt/odoo/custom/src/odoo/odoo/api.py", line 759, in call_kw return _call_kw_multi(method, model, args, kwargs) File "/opt/odoo/custom/src/odoo/odoo/api.py", line 746, in _call_kw_multi result = method(recs, *args, **kwargs) File "", line 2, in button_immediate_upgrade File "/opt/odoo/custom/src/odoo/odoo/addons/base/models/ir_module.py", line 75, in check_and_log return method(self, *args, **kwargs) File "/opt/odoo/custom/src/odoo/odoo/addons/base/models/ir_module.py", line 628, in button_immediate_upgrade return self._button_immediate_function(type(self).button_upgrade) File "/opt/odoo/custom/src/odoo/odoo/addons/base/models/ir_module.py", line 562, in _button_immediate_function modules.registry.Registry.new(self._cr.dbname, update_module=True) File "/opt/odoo/custom/src/odoo/odoo/modules/registry.py", line 86, in new odoo.modules.load_modules(registry._db, force_demo, status, update_module) File "/opt/odoo/custom/src/odoo/odoo/modules/loading.py", line 417, in load_modules force, status, report, loaded_modules, update_module, models_to_check) File "/opt/odoo/custom/src/odoo/odoo/modules/loading.py", line 313, in load_marked_modules perform_checks=perform_checks, models_to_check=models_to_check File "/opt/odoo/custom/src/odoo/odoo/modules/loading.py", line 222, in load_module_graph load_data(cr, idref, mode, kind='data', package=package, report=report) File "/opt/odoo/custom/src/odoo/odoo/modules/loading.py", line 68, in load_data tools.convert_file(cr, package.name, filename, idref, mode, noupdate, kind, report) File "/opt/odoo/custom/src/odoo/odoo/tools/convert.py", line 802, in convert_file convert_xml_import(cr, module, fp, idref, mode, noupdate, report) File "/opt/odoo/custom/src/odoo/odoo/tools/convert.py", line 865, in convert_xml_import obj.parse(doc.getroot(), mode=mode) File "/opt/odoo/custom/src/odoo/odoo/tools/convert.py", line 764, in parse exc_info[2] File "/opt/odoo/custom/src/odoo/odoo/tools/pycompat.py", line 86, in reraise raise value.with_traceback(tb) File "/opt/odoo/custom/src/odoo/odoo/tools/convert.py", line 758, in parse self._tags[rec.tag](rec, de, mode=mode) File "/opt/odoo/custom/src/odoo/odoo/tools/convert.py", line 663, in _tag_record record = model.with_context(rec_context)._load_records([data], self.mode == 'update') File "/opt/odoo/custom/src/odoo/odoo/models.py", line 3883, in _load_records data['record']._load_records_write(data['values']) File "/opt/odoo/custom/src/odoo/odoo/addons/base/models/ir_ui_view.py", line 1542, in _load_records_write super(View, self)._load_records_write(values) File "/opt/odoo/custom/src/odoo/odoo/models.py", line 3821, in _load_records_write self.write(values) File "/opt/odoo/custom/src/odoo/odoo/addons/base/models/ir_ui_view.py", line 445, in write res = super(View, self).write(self._compute_defaults(vals)) File "/opt/odoo/custom/src/odoo/odoo/models.py", line 3392, in write fields[0].determine_inverse(records) File "/opt/odoo/custom/src/odoo/odoo/fields.py", line 1200, in determine_inverse getattr(records, self.inverse)() File "/opt/odoo/custom/src/odoo/odoo/addons/base/models/ir_ui_view.py", line 275, in _inverse_arch view.write(data) File "/opt/odoo/custom/src/odoo/odoo/addons/base/models/ir_ui_view.py", line 445, in write res = super(View, self).write(self._compute_defaults(vals)) File "/opt/odoo/custom/src/odoo/odoo/models.py", line 3366, in write self._write(store_vals) File "/opt/odoo/custom/src/odoo/odoo/models.py", line 3502, in _write self._validate_fields(vals) File "/opt/odoo/custom/src/odoo/odoo/models.py", line 1132, in validate_fields raise ValidationError("%s\n\n%s" % (("Error while validating constraint"), tools.ustr(e))) odoo.tools.convert.ParseError: "Error while validating constraint

Field client_order_ref does not exist

Error context: View account_invoice_tree_inherit [view_id: 1311, xml_id: cloudpiles_custom.invoice_tree, model: account.invoice, parent_id: 681] None" while parsing /opt/odoo/auto/addons/cloudpiles_custom/views/account_invoice_view.xml:3, near account_invoice_tree_inherit account.invoice

2
  • 1
    Have you checked if that specific python file (model) actually gets loaded? Commented Oct 5, 2022 at 4:07
  • Check if sale_order is not false if sale_order: then assigned rec.client_order_ref = sale_order.client_order_ref also use else rec.client_order_ref = False as an assignment is mandatory at least it is in odoo 13 Commented Oct 5, 2022 at 5:06

1 Answer 1

0

I guess, you forgot an important point about inheritance from odoo's models... when you added a new field on existing model in odoo's modules ,first of all you have to upgrading your module with command, not with odoo interface... just run this command: ./odoo-bin -c /etc/odoo-server.conf -d data_base_name -u module_name I hope this will help you.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.