跳转至内容
  • 版块
  • 标签
  • 热门
  • 用户
  • 群组
皮肤
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • 默认(Flatly)
  • 不使用皮肤
折叠

Odoo 中文社区

  1. 主页
  2. 版块
  3. Odoo 开发与实施交流
  4. 继承时如果使用了不同的名称能否使用视图继承

继承时如果使用了不同的名称能否使用视图继承

已定时 已固定 已锁定 已移动 Odoo 开发与实施交流
5 帖子 2 发布者 2.9k 浏览
  • 从旧到新
  • 从新到旧
  • 最多赞同
登录后回复
此主题已被删除。只有拥有主题管理权限的用户可以查看。
  • T 离线
    T 离线
    tedi3231
    写于 最后由 编辑
    #1

    我有一个需求是这样的。一个朋友为一家连锁店装了很多摄像头,这些设备经常出问题,所以会有很多报修之类的东西处理,修好后也有一堆费用需要处理。因为各种不同的费用在填写的时候有许多字段都是一样的,我就想用继承了来实现,代码如下:

    <br />class FeeBase(osv.osv):<br />&nbsp; &nbsp; &quot;&quot;&quot;<br />&nbsp; &nbsp; 费用基本类型,作为维护费用来使用<br />&nbsp; &nbsp; &quot;&quot;&quot;<br />&nbsp; &nbsp; _name=&quot;tms.feebase&quot;<br /><br />&nbsp; &nbsp; _columns={<br />&nbsp; &nbsp; &nbsp; &nbsp; &quot;processid&quot;:fields.char(string=&quot;ProcessId&quot;,size=100,required=False),&nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &quot;feedate&quot;:fields.date(string=&quot;Fee Date&quot;),<br />&nbsp; &nbsp; &nbsp; &nbsp; &quot;store_id&quot;:fields.many2one(&quot;tms.store&quot;,string=&quot;Store&quot;),<br />&nbsp; &nbsp; &nbsp; &nbsp; &quot;storenum&quot;:fields.related(&quot;store_id&quot;,&quot;name&quot;,type=&quot;char&quot;,string=&quot;Store Num&quot;),<br />&nbsp; &nbsp; &nbsp; &nbsp; &quot;province&quot;:fields.function(get_province_name,type=&quot;char&quot;,string=&quot;Province&quot;),<br />&nbsp; &nbsp; &nbsp; &nbsp; &quot;feetype_id&quot;:fields.many2one(&quot;tms.feetype&quot;,&quot;Fee Type&quot;),<br />&nbsp; &nbsp; &nbsp; &nbsp; &quot;payman&quot;:fields.many2one(&quot;res.users&quot;,&quot;Pay Man&quot;),<br />&nbsp; &nbsp; &nbsp; &nbsp; &quot;amount&quot;:fields.float(string=&quot;Amount&quot;),<br />&nbsp; &nbsp; &nbsp; &nbsp; &quot;accountamount&quot;:fields.float(string=&quot;Account Amount&quot;),<br />&nbsp; &nbsp; &nbsp; &nbsp; &quot;accountperiod&quot;:fields.char(string=&quot;Account Period&quot;, size=20,required=False),<br />&nbsp; &nbsp; &nbsp; &nbsp; &quot;oanum&quot;:fields.char(string=&quot;OA Num&quot;,size=100),<br />&nbsp; &nbsp; &nbsp; &nbsp; &quot;remark&quot;:fields.text(string=&quot;Remark&quot;),<br />&nbsp; &nbsp; &nbsp; &nbsp; &quot;state&quot;:fields.selection([(&quot;draft&quot;,&quot;Draft&quot;),(&quot;hasexported&quot;,&quot;Has Exported&quot;),(&quot;hasoa&quot;,&quot;Has Input OANum&quot;),(&quot;hasback&quot;,&quot;Has Back&quot;)],<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  string=&quot;States&quot;),<br />&nbsp; &nbsp; }<br />
    

    ```
    class FeeForSend(osv.osv):
        _inherit="tms.feebase"
        _name = "tms.feeforsend"

        _columns={
            "sendcompany":fields.many2one("tms.sendcompany","Send Company"),
            "sendordernum":fields.char(string="Send Order num",size=100,required=True),
            "sendproduct":fields.char(string="Send Product", size=200,required=True),
        }
    ```
    ```
    class FeeForProductIt(osv.osv):
        _inherit="tms.feebase"
        _name = "tms.feeforproductit"

        _columns={
            "productname":fields.char(string="Product Name",size=200),
            "productprice":fields.float(string="Product Price"),
            "productcount":fields.integer(string="Product Count"),
            "accountproductprice":fields.integer(string="Account Product Price"),
            "accountproductcount":fields.integer(string="Account Product Count")
        }

    FeeForProductIt()

    class FeeForItService(osv.osv):
        _inherit="tms.feebase"
        _name = "tms.feeforitservice"

    FeeForItService()
    ```
    ```
    <record model="ir.ui.view" id="view_tms_feebase_tree">
                <field name="name">tms.feebase.tree</field>
                <field name="model">tms.feebase</field>
                <field name="type">tree</field>
                <field name="arch" type="xml">
                    <tree string="维护费登记">
                        <field name="processid"/>
                        <field name="store_id" />
                        <field name="province"/>
                        <field name="storenum"/>
                        <field name="accountperiod"/>
                        <field name="feetype_id"/>
                        <field name="feedate"/>
                        <field name="payman"/>
                        <field name="amount" sum="Account" />
                        <field name="accountamount" sum="Account Amount"/>
    <field name="state"/>
    <field name="oanum"/>
                    </tree>
                </field>
            </record>
    ```
    从代码中可以看出每个子类与父类相差很小,在视图中只需要多添加几个字段或者完全不用添加。但当我使用视图的继承的机制时发现如果对象在继承时_name与父类不一样,视图是不能继承的。
    有没有什么办法可以让我能够共用父类的视图?
    1 条回复 最后回复
    0
    • T 离线
      T 离线
      tedi3231
      写于 最后由 编辑
      #2

      有哪位大牛知道不?

      1 条回复 最后回复
      0
      • C 离线
        C 离线
        ccdos
        写于 最后由 编辑
        #3

        _inherit 后就不要改名字了,用同一个model
        加个 类别字段来区别不同的数据

        1 条回复 最后回复
        0
        • T 离线
          T 离线
          tedi3231
          写于 最后由 编辑
          #4

          [quote author=ccdos link=topic=9144.msg18882#msg18882 date=1375200370]
          _inherit 后就不要改名字了,用同一个model
          加个 类别字段来区别不同的数据
          [/quote]

          Hi ccos,谢谢你的答复。如果不改名字我在使用的过程中遇到的问题是视图继承后会导致父类视图也发生变化。我希望在添加不同费用时显示不同的FORM。

          1 条回复 最后回复
          0

          • 登录

          • 没有帐号? 注册

          • 登录或注册以进行搜索。
          • 第一个帖子
            最后一个帖子
          0
          • 版块
          • 标签
          • 热门
          • 用户
          • 群组