`
radzhang
  • 浏览: 307769 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Odoo的Field的一些点滴

    博客分类:
  • ODOO
 
阅读更多

1.many2one是用来建立两个表之间的关联的,必须在子表里定义一个字段(实体表里也会生成这个字段),指向主表的model。

例如:course和session的关联里,session子表的model里就要定义一个course_id,指向主表的一条记录。

一个session里只能有一个course,一个course里有过的session。

course_id = fields.Many2one('openacademy.course',

                                ondelete='cascade', string="Course", required=True)

 

2.one2many是一个虚拟关系,定义了也不会在实体表里创建字段的。在主表里定义,指向明细表的model,并且必须指定明细表里定义的和主表相关联的字段。必须先定义many2one之后才能定义one2many。

例如:course主表里可以定义一个session_ids代表子表的一个集合。

    session_ids = fields.One2many(

        'openacademy.session', 'course_id', string="Sessions")

 

3.many2many会创建一个两个实体表的主键的新的关联表。关联表为两个实体表名加_rel。

例如:session里定义一个出席者的字段。一个session里可以有多个  Attendees,一个attendee也存在于

多个session里,这时就要定义两个表的关联关系表。

    attendee_ids = fields.Many2many('res.partner', string="Attendees")

 

4.fields.related。

 

 

 

生产批次model

            'partner_id':fields.many2one('res.partner',string=u'客户',),

            'name':fields.char(u'生产批次',copy=False),

            'partner_lot':fields.char(u'客户批次号',),

            'product_id':fields.many2one('product.product',string=u'客供代码'),

            'product_name':fields.related('product_id','name',type='char',string=u'品名',),

            'tse_code':fields.related('product_id','tse_code',type='char',string=u'TSE代码',),

            'product_qty':fields.integer(u'制造量'),

生产单model,一个生产批次有多个生产单

        'plot_id':fields.many2one('mrp.pro.lots',string='生产批次'),

        'routing_no':fields.integer(u'工序批次'),

        //这里的related写法还不明白。是否是因为不是获取单纯的关联表里的某个单纯字段的原因?

         是因为获取的partner_id在生产批次model里也是many2one的集合的原因呢?但是为什么partner_lot

         不能按照上面的简单的写法写

        'partner_id':fields.related('plot_id','partner_id',type="many2one",relation="res.partner",string=u"客户",

                            store={

                                'mrp.production': (lambda self, cr, uid, ids, c=None: ids, ['plot_id',], 30),

                                'mrp.pro.lots': (_get_partner_id, ['partner_id',], 30),

                                  }),

        'partner_lot':fields.related('plot_id','partner_lot',type="char",string=u"客户批次号",

                            store={

                                'mrp.production': (lambda self, cr, uid, ids, c=None: ids, ['plot_id',], 30),

                                'mrp.pro.lots': (_get_parlot_id, ['partner_lot',], 30),

                                  }),

 

 class mrp_production(osv.osv):继承osv.osv是7.0的写法?找到osv.fields下面的fields.function方法

下面有store相关的注释。

 

    .. _field-function-store:

 

    .. rubric:: The ``store`` parameter

 

    The ``store`` parameter allows caching the result of the field computation in the

    database, and defining the triggers that will invalidate that cache and force a

    recomputation of the function field.

    When not provided, the field is computed every time its value is read.

    The value of ``store`` may be either ``True`` (to recompute the field value whenever

    any field in the same record is modified), or a dictionary specifying a more

    flexible set of recomputation triggers.

 

    A trigger specification is a dictionary that maps the names of the models that

    will trigger the computation, to a tuple describing the trigger rule, in the

    following form::

 

        store = {

            'trigger_model': (mapping_function,

                              ['trigger_field1', 'trigger_field2'],

                              priority),

        }

 

    A trigger rule is defined by a 3-item tuple where:

 

        * The ``mapping_function`` is defined as follows:

 

            .. function:: mapping_function(trigger_model, cr, uid, trigger_ids, context)

 

                Callable that maps record ids of a trigger model to ids of the

                corresponding records in the source model (whose field values

                need to be recomputed).

 

                :param orm model: trigger_model

                :param list trigger_ids: ids of the records of trigger_model that were

                                         modified

                :rtype: list

                :return: list of ids of the source model whose function field values

                         need to be recomputed

 

        * The second item is a list of the fields who should act as triggers for

          the computation. If an empty list is given, all fields will act as triggers.

        * The last item is the priority, used to order the triggers when processing them

          after any write operation on a model that has function field triggers. The

          default priority is 10.

 

    In fact, setting store = True is the same as using the following trigger dict::

 

        store = {

              'model_itself': (lambda self, cr, uid, ids, context: ids,

                               [],

                               10)

        }

 

 

分享到:
评论

相关推荐

    Odoo Select Field disable

    该模块用于在Odoo环境中,指定Selection字段可选择的值。

    ODOO10菜单和界面

    ODOO10是Odoo(原OpenERP)的一个版本,它是一款开源的企业资源规划(ERP)软件,包含了业务应用程序的广泛范围,比如销售、CRM、库存管理、生产、会计等。ODOO10的菜单和界面是用户与软件进行交互的前端部分,对...

    odoo 15企业版资源分享

    根据Cybrosys的Odoo V15书籍¹,一些新功能包括: - 高级用户界面:为了完美处理CRM平台中的每个操作,建立了一个高度发展的高级用户界面。 - 高级过滤选项:Odoo CRM模块中几乎所有窗口都包括高级过滤选项。 - ...

    odoo定时任务task的实现方式

    Odoo是一个开源的ERP(企业资源规划)平台,它提供了一整套企业级应用解决方案,包括CRM、库存管理、会计、人力资源、项目管理等等。在实际应用中,Odoo支持定时任务(cron jobs)的设置,使得系统能够按照预定的...

    odoo8安装步骤

    ### Odoo 8 在 CentOS Linux 下的安装步骤详解 Odoo 是一款开源的企业资源管理系统,提供了包括销售管理、采购管理、库存管理等在内的多种业务功能模块。Odoo 的前身是 OpenERP,在版本 8 中正式更名为 Odoo。本文...

    odoo14 企业版源码

    在深入探讨Odoo 14企业版源码之前,我们需要先了解一些基础知识。 **Odoo概述** Odoo是基于Python语言开发的,它集成了多种业务应用,包括销售管理、采购管理、库存管理、财务管理、人力资源、项目管理、客户服务...

    Odoo开发手册第五版,odoo14开发手册,Python

    《Odoo开发手册第五版》是针对Odoo 14这一版本的一份详尽指南,主要面向Python开发者,旨在帮助他们深入理解和掌握Odoo的开发技术。Odoo是一款开源的企业资源规划(ERP)软件,它提供了包括销售、采购、库存、财务、...

    odoo11.cookbook

    ### Odoo 11 开发食谱:第二版 #### 关键知识点概览 1. **Odoo 平台概述** - **定义与历史**:Odoo 是一个开源的企业资源规划 (ERP) 和客户关系管理 (CRM) 解决方案,提供一系列集成应用来满足业务需求。 - **...

    odoo16简洁好用的开源主题,安装即用

    Odoo社区主题:Odoo社区主题是由Odoo社区开发的一些额外主题,可以在Odoo应用商店中免费下载。这些主题提供了不同的颜色方案、风格和布局,用户可以根据自己的需求和喜好进行选择。 自定义主题:Odoo用户可以根据...

    odoo17 python源码

    Odoo 17是Odoo系列企业资源规划(ERP)软件中的一个版本,由比利时Odoo S.A.公司开发并维护。作为一款开源且高度可定制的业务管理平台,Odoo 17提供了全面的企业级解决方案,涵盖了财务管理、销售管理、采购管理、...

    odoo-13.0源码.zip

    《Odoo 13.0源码解析与应用探索》 Odoo,作为一个全球领先的开源企业应用程序套件,因其强大的模块化设计、易扩展性和高度定制性,深受开发者和企业的青睐。本文将针对《odoo-13.0源码.zip》进行详细解读,旨在...

    odoo13 企业版源码

    《Odoo 13企业版源码解析与学习指南》 Odoo,作为一个全面的企业级开源应用程序套件,被广泛应用于企业管理、电子商务、销售、采购、财务、人力资源等多个领域。Odoo 13是其最新版本,带来了诸多改进和新功能,...

    odoo_11.0源文件

    Odoo V11引入了全局快捷键和全局搜索功能,使Odoo导航比以往任何时候都更快捷。Odoo 的开源模式让我们可利用无数开发人员和业务专家,在短短数年内,打造数百款应用。 具有强大的技术基础,Odoo 的结构非常独特。其...

    Odoo培训PPT.pptx

    odoo培训PPT odoo入门培训PPT ·

    Odoo8开发教程

    附录部分提供了有关Odoo的一些额外信息,包括老API的介绍、PostgreSQL数据库命令行操作、反向代理的安装和配置、跟踪项目源码的初始化进程以及会计科目的配置等。这些是进行Odoo开发时可能会用到的高级主题。 最后...

    Odoo saas~16.3 (最新版本)

    Odoo是一款开源的企业资源计划(ERP)软件,其最新版本为16.3,被称为"Odoo SaaS~16.3"。该版本引入了众多改进和创新,旨在提供更高效、用户友好的企业解决方案。 Odoo 16.3的亮点之一是其无缝切换特性,这意味着...

    Odoo_14_Development_Cookbook.pdf

    本书名为《Odoo_14_Development_Cookbook》,是一本关于Odoo 14开发的指南,由Packt Publishing出版。根据提供的文本内容,本书第四版于2020年出版,作者包括Parth Gajjar、Alexandre Fayolle、Holger Brunn和Daniel...

    odoo17 企业版源码

    odoo17 企业版源码

    fedora 安装ODOO服务

    ### Fedora 下安装 Odoo 服务 #### 一、前言 Odoo 是一款基于 Python 的开源企业资源管理系统(ERP),提供了全面的企业应用解决方案。本文主要介绍如何在 Fedora 系统上安装并配置 Odoo 服务,包括安装 ...

    odoo16-电子发票

    Odoo 16是一款开源的企业管理软件,具有强大的功能和可定制性。其中,电子发票是其财务管理模块中的一个重要功能,可以帮助企业快速、准确地管理发票,并提高财务流程的效率。 一、电子发票简介 电子发票是指将发票...

Global site tag (gtag.js) - Google Analytics