This question has been flagged
1 Reply
3494 Views

Hello,

I am trying to add a custom field (size_of_pieces) to the Manufacturing Order screen (View Name: mrp.production.form), but I get the following error: Field `size_of_pieces` does not exist

This is my code:

models.py :

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

from odoo import models, fields, api


class mo_screen(models.Model):
    _name = 'mo.screen'
    _inherit = 'mrp.production'
   
    size_of_pieces = fields.Char(string='Size of Pieces', store=True, readonly=False)
   

   
class inv_screen(models.Model):
    _name = 'inv.screen'
    _inherit = 'stock.picking'
   
    size_of_pieces_inv = fields.Many2one('mo.screen', string='Size of Pieces', store=True, readonly=False)


views.xml :
<odoo>
  <data>
      <record id="mrp_production_form_view_inherits" model="ir.ui.view">
            <field name="name">mrp.production.form</field>
            <field name="model">mrp.production</field>
            <field name="priority" eval="40"/>
            <field name="inherit_id" ref="mrp.mrp_production_form_view"/>
            <field name="arch" type="xml">
                <xpath expr="//form/sheet/group/group/field[@name='bom_id']" position="after"> 
                    <field name="size_of_pieces"/>
                </xpath>
            </field>
      </record>
  </data>
</odoo>


__manifest__.py :
# -*- coding: utf-8 -*-
{
    'name': "mo_screen",

    'summary': """
        Short (1 phrase/line) summary of the module's purpose, used as
        subtitle on modules listing or apps.openerp.com""",

    'description': """
        Long description of module's purpose
    """,

    'author': "My Company",
    'website': "http://www.yourcompany.com",

    # Categories can be used to filter modules in modules listing
    # Check https://github.com/odoo/odoo/blob/13.0/odoo/addons/base/data/ir_module_category_data.xml
    # for the full list
    'category': 'Uncategorized',
    'version': '0.1',

    # any module necessary for this one to work correctly
    'depends': ['base', 'mrp', 'product', 'stock'],

    # always loaded
    'data': [
        # 'security/ir.model.access.csv',
        'views/views.xml',
        'views/templates.xml',
        'views/inv_views.xml',
    ],
    # only loaded in demonstration mode
    'demo': [
        'demo/demo.xml',
    ],
}




I've Tried:
Different xpath variations, such as:
<xpath expr="//sheet/group/group/field[@name='bom_id']" position="after"> 

<xpath expr="//group/group/field[@name='bom_id']" position="after"> 


Also, my models __init__.py :
# -*- coding: utf-8 -*-

from . import models





Any help is highly appreciated, thanks!

Avatar
Discard
Best Answer

Hi,

Remove the _name from the both the class and see,

class mo_screen(models.Model):
     _inherit = 'mrp.production'
   
    size_of_pieces = fields.Char(string='Size of Pieces', store=True, readonly=False)


Just only give the _inherit='model_name'  .


You can see more about how to add a new field to existing view from here: https://www.youtube.com/watch?v=z1Tx7EGkPy0&list=PLqRRLx0cl0hoJhjFWkFYowveq2Zn55dhM&index=11


Thanks

Avatar
Discard
Author

That just fixed it, thanks a lot!