OpenERP modeling / views: related object inline

自古美人都是妖i 提交于 2019-12-23 04:28:33

问题


I have installed the built in OpenERP 6.1 module crm.

As a result, I now have res.lead active and visible at "Sales->Opportunities".

I'd like to edit this object / view to show the partner's billing address.

Since I want to do this on the Opporunities form, there is already a partner_id.

Copying another module, I defined my new module like this:

class crm_lead(osv.osv):
    _name = _inherit = 'crm.lead'
    _columns = {
    'billing_address_id': fields.many2one('res.partner.address', 'Partner Billing Address', domain="[('partner_id','=',partner_id),('type','in',['invoice', 'default'])]"),
    }

And I changed my update_xml to:

    <record model="ir.ui.view" id="crm_case_form_view_oppor">
        <field name="name">Opportunity form (inherit)</field>
        <field name="model">crm.lead</field>
        <field name="inherit_id" ref="crm.crm_case_form_view_oppor"/>
        <field name="arch" type="xml">
            <data>
                <separator string="Details" position="replace" />
                <field name="description" position="replace">
                    <group colspan="2" col="4">
                        <separator colspan="4" string="Billing" />
                        <field widget="one2many_list" mode="form,tree" name="billing_address_id" colspan="4" nolabel="1" />
                    </group>
                    <group colspan="2" col="4">
                        <separator colspan="4" string="Details" />
                        <field name="description" nolabel="1" colspan="4" />
                    </group>
                </field>
            </data>
        </field>
    </record>

The problem is that the related object shows all the related fields (as I'd guess would be expected). In particular, it shows the partner_id and company fields, which I'd like to hide since they should default to / inherit from this opportunity (or the linked partner).

How can I hide these fields? I can't simply add a bunch of 'related' fields, as there is potentially more than one billing address.

Thanks for the help!


Edit: To be clearer, an opportunity should only have a single chosen billing address, chosen from the partner's invoice / default addresses. It should be displayed inline to allow easy editing.


回答1:


There are a couple of ways to specify the view for related fields like this. You can use the context like this:

<field 
    name="order_line" 
    colspan="4" 
    nolabel="1"
    context="{'form_view_ref': 'module.view_id', 'tree_view_ref': 'model.view_id'}"/>

You can also specify the whole view for the child record as a subview within the parent view like this:

    <!-- <=== order_line is a one2many field -->
    <field name="order_line" colspan="4" nolabel="1">
        <form>
            <field name="qty"/>
            ...
        </form>
        <tree>
            <field name="qty"/>
            ...
        </tree>
    </field>



回答2:


OK, I was a bit confused because you put a one2many widget on a many2one field.

If you want to control how a one2many field is displayed, use the subview or context methods I mentioned in my other answer.

If you want to control how a many2one field is displayed, you might be able to use related fields that pull fields from the record you selected, but I doubt it. Read-only might work, but I don't think it makes sense to edit multiple related fields and be able to change the selected record. You might be able to hack together some function fields with a store function that lets you write back to the related record, but it seems like it would really confuse your users.




回答3:


On any OE Relation field you can define the Intenal View like :

  <field name=""  mode="tree,form">
        <!--Internal tree view for your Relation field model-->
        <tree>
        </tree>

        <!--Internal Form view for your Relation field model-->
        <form>
        </form>
  </field>

Example Under Addons 1 Click to Example 2 Click to See Example

Hope this will help you,.




回答4:


Now if yo uwan to shoe specific detail on your m2o file then we have some optional way also where you have to over the def name_get of your relational model, namge get look like :

name_get(cr, user, ids, context=None)
   Returns the preferred display value (text representation) for the records with 
   the given ids. By default this will be the value of the name column, unless the
   model implements a custom behavior. Can sometimes be seen as the inverse function
   of name_search(), but it is not guaranteed to be.

   Rtype :  list(tuple)
   Return : list of pairs (id,text_repr) for all records with the given ids.

So here in this method you can decide what string you want to show your relational field. Example

This will fix your problem partially i guess.



来源:https://stackoverflow.com/questions/11143678/openerp-modeling-views-related-object-inline

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!