Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

python - i want to add a new field to an existing module odoo11 but i don't know why it didn't work

product_template.xml

the view to add the customizing field to the product module

<?xml version="1.0" encoding="utf-8"?>

<odoo>

    <data>

        <record id="product_template_only_form_view_inherit" model="ir.ui.view">

            <field name="name">product.template.common.form</field>

            <field name="model">product.template</field>

            <field name="inherit_id" 

               ref="product.product_template_only_form_view " />

            <field name="arch" type="xml">

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

                  <field name="list_price"/>

               </xpath>

            </field>

        </record>

    </data>

</odoo>

models file python

product_template.py

-- coding: utf-8 --

from odoo import models, fields , api

from odoo.addons import decimal_precision as dp

from odoo.exceptions import ValidationError, RedirectWarning, except_orm

from odoo.tools import pycompat

class ProductTemplate(models.Model):

_inherit = 'product.template'

_name = 'product.template'

_columns={

    'remise': fields.float('remise du fournisseur', size=10, required=True),

    'marge': fields.float('marge', size=10, required=True),

    'total_reste': fields.float('Reste', size=10, required=True),

}

  remise = fields.float('remise du fournisseur', size=10, required=True)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You are putting the same field list_price after list_price, you should replace the field that is inside the xpath by the field you want.

<record id="product_template_only_form_view_inherit" model="ir.ui.view">

    <field name="name">product.template.common.form</field>

    <field name="model">product.template</field>

    <field name="inherit_id" 

       ref="product.product_template_only_form_view " />

    <field name="arch" type="xml">

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

          <field name="your_custom_field"/>

       </xpath>

    </field>

</record>


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...