宜兴通达竭诚为您服务。

通达科技 - 宜兴电脑维护及IT服务外包服务商

Context & Domain
  • 上传者: Administrator
  • 上传时间:2024年02月18日 11时31分14秒
摘要:
Using XML or Python, you can pass any information in context. Additionally, the domain is any requirement that aids in data filtering during searches. ......
正文 相关文章 请喝咖啡

    Using XML or Python, you can pass any information in context. Additionally, the domain is any requirement that aids in data filtering during searches. Therefore, when coding, context and domain will be more helpful. A context is a python dictionary that assists in passing necessary info to an Odoo function. You can see that practically every method in Odoo had a context argument to transmit data. Examples of many ways to use context are given below.

    1. To pass default values for fields:

    <field name="work_location_id" context="{'default_address_id': address_id}" />

    This way, you can set the default value for a field.

    2. Setting default filters and groups by records

    <group expand="0" string="Group By">

                <filter string="Department" name="department" domain="[]" context="{'group_by': 'department_id'}"/>

                <filter string="Company" name="company" domain="[]" context="{'group_by': 'company_id'}" groups="base.group_multi_company"/>

                <filter string="Employment Type" name="employment_type" domain="[]" context="{'group_by': 'contract_type_id'}"/>

             </group>

    Inside the context you can add the group_by field.

    3. In Window actions

    <record id="crm_lead_action_my_activities" model="ir.actions.act_window">

                <field name="name">My Activities</field>

                <field name="res_model">crm.lead</field>

                <field name="view_mode">tree,kanban,graph,pivot,calendar,form,activity</field>

                <field name="view_id" ref="crm_lead_view_list_activities"/>

                <field name="domain">[('activity_ids','!=',False)]</field>

                <field name="search_view_id" ref="crm.view_crm_case_my_activities_filter"/>

                <field name="context">{'default_type': 'opportunity',

                        'search_default_assigned_to_me': 1}

                </field>

                <field name="help" type="html">

                    <p class="o_view_nocontent_smiling_face">

                        Looks like nothing is planned.

                    </p><p>

                        Schedule activities to keep track of everything you have to do.

                    </p>

                </field>

             </record>

             

    For defining default values for new records, use context in window actions. The default type in this instance is set to opportunity.

    4. Python has a function

    Context is also usable inside of Python functions. You can access any value from XML passed to your Python function as self.partner id is the value that is passed from the XML in this statement: env.context.get('partner id').

    5. In search view and filters

    <group expand="0" string="Group By">

                <filter string="User" name="user" domain="[]" context="{'group_by':'user_id'}"/>

                <filter string="Type" name="type" domain="[]" context="{'group_by':'resource_type'}"/>

                <filter string="Company" name="company" domain="[]" context="{'group_by':'company_id'}" groups="base.group_multi_company"/>

                <filter string="Working Time" name="working_period" domain="[]" context="{'group_by':'calendar_id'}"/>

            </group>

    Here added two filters inside the group tag, and passed the group_by using context.

    Domain:

    Domains can be used to search for or filter data or records depending on particular criteria. A field, operator, and value are all parts of a domain. You can filter the data using a variety of operators.

    The syntax for the domain is:domain="[(field_name, 'operator', ‘value’)]"

    The name of the field in the associated model to which the domain should be assigned is the field name. There are several distinct kinds of operators in Odoo.

    -> comparison operators : < ,>, =, !=, <=,>=

    -> [('name', '=like', ‘Mitchel’)] - This returns ‘Mitchel’

    -> [('name', '=like', 'odoo')] - This returns ‘%odoo%’

    -> [('name', '=like', 'odoo')] - This returns ‘%Odoo%’, ‘%odoo’

    -> In’ and ‘not in’ : These are used to check if the value is present or not in the value list

    -> child_of’ operator: It is used to find the child values in relation.

    You can use domains in different situations

    1. In a search view filter

    <search string="Search for mrp workcenter">

                <field name="name" string="Work Center" filter_domain="['|', ('name', 'ilike', self), ('code', 'ilike', self)]"/>

                <filter name="archived" string="Archived" domain="[('active', '=', False)]"/>

                <group expand="0" string="Group By...">

                    <filter string="Company" name="company" domain="[]" context="{'group_by': 'company_id'}" groups="base.group_multi_company"/>

                </group>

             </search>

    2. In record rule

    <record model="ir.rule" id="res_users_log_rule">

                <field name="name">res.users.log per user</field>

                <field name="model_id" ref="model_res_users_log"/>

                <field name="domain_force">[('create_uid','=', user.id)]</field>

                <field name="perm_read" eval="False"/>

             </record>

    3. fields_view_get() method

    Use the domain in the fields view get method to specify dynamic values for domain filters ().

    4. To filter relational object fields records

    partner_id = fields.Many2one('res.partner', 'Account Holder', ondelete='cascade', index=True, domain=['|', ('is_company', '=', True), ('parent_id', '=', False)], required=True)

    5.To display specific records

    <record id="action_bank_statement_tree" model="ir.actions.act_window">

                <field name="name">Bank Statements</field>

                <field name="res_model">account.bank.statement</field>

                <field name="view_mode">tree,pivot,graph</field>

                <field name="domain">['|', ('journal_id', '=', False), ('journal_id.type', '=', 'bank')]</field>

                <field name="context">{'journal_type':'bank'}</field>

                <field name="search_view_id" ref="view_bank_statement_search"/>

                <field name="help" type="html">

                  <p class="o_view_nocontent_smiling_face">

                    Register a bank statement

                  </p><p>

                    A bank statement is a summary of all financial transactions

                    occurring over a given period of time on a bank account. You

                    should receive this periodically from your bank.

                  </p><p>

                    Odoo allows you to reconcile a statement line directly with

                    the related sale or purchase invoices.

                  </p>

                </field>

             </record>

    本文章从网上收集,如有侵权请联系tderp@tderp.com删除
  • 微信扫一扫,一分也是爱:
  • 微信

服务原则及地区范围

宜兴通达网络科技有限公司,地处中国宜兴环科园内,是一家高新技术企业。公司在企业网络维护和企业信息化建设与咨询方面,有10多年经验。

我公司愿与客户一道,力求彻底解决客户问题!
我们不是在给企业提供“头痛医头、脚痛医脚”的暂时解决方案,而是在部署根本性安全与稳定服务!!
我们愿携手客户,建立企业IT规划;杜绝随意安装系统、软件等操作;力求共同维护有序、安全、稳定的网络办公环境!!!
IT服务,服务是根本,客户是上帝;我们提供快速响应、快速上门、快速排查,提供优质高效的服务!!!!

通达科技提供全国范围内的服务,服务形式包括远程协助、电话咨询、电子邮件咨询、传真咨询、问答平台的问题解决等。

宜兴地区提供上门服务:

  • 市区服务:宜城街道、城北街道(屺亭街道)、新街街道、新庄街道、环科园、渚桥开发区
  • 市郊服务:张渚镇、西渚镇、太华镇、徐舍镇、官林镇、杨巷镇、新建镇、和桥镇、高塍镇、万石镇、周铁镇、芳桥镇、丁蜀镇、湖父镇。
  • 联系电话:189-21-343434
  • 在线沟通: