我想向现有模块odoo11中添加一个新字段,但我不知道为什么它不起作用 [英] i want to add a new field to an existing module odoo11 but i don't know why it didn't work

查看:479
本文介绍了我想向现有模块odoo11中添加一个新字段,但我不知道为什么它不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<?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>

模型文件python

product_template.py

--编码:utf-8--

从odoo导入模型,字段,api

models file python

product_template.py

-- coding: utf-8 --

from odoo import models, fields , api

从odoo.addons导入小数精度为dp

from odoo.addons import decimal_precision as dp

从odoo.exceptions导入ValidationError,RedirectWarning,except_orm

from odoo.exceptions import ValidationError, RedirectWarning, except_orm

从odoo.tools导入pycompat

from odoo.tools import pycompat

Class ProductTemplate(models.Model):

class ProductTemplate(models.Model):

_inherit ='product.template'

_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)

推荐答案

要将相同的字段list_price放在list_price之后,应将xpath内的字段替换为所需的字段.

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>

这篇关于我想向现有模块odoo11中添加一个新字段,但我不知道为什么它不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆