Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
5847 Lượt xem

I'm using v10 and I'm trying to add few fields to 'res.partner' and then add the same fields to other forms.

Here are my .py and .xml:

class add_vendor_ship_carrier(models.Model):
    _inherit = 'res.partner'
    ship_carrier = fields.Char('Ship Carrier')
    ship_carrier_account = fields.Char('Ship Carrier Account')

class add_to_sales_order(models.Model):
    _inherit = 'sale.order'
    ship_carrier = fields.Char(related='partner_id.ship_carrier')
    ship_carrier_account = fields.Char(related='partner_id.ship_carrier_account')

class add_to_purchase_order(models.Model):
    _inherit = 'purchase.order'
    ship_carrier = fields.Char(related='partner_id.ship_carrier')
    ship_carrier_account = fields.Char(related='partner_id.ship_carrier_account')
<record id="ship_carrier_supplier_form" model="ir.ui.view"> 
<field name="name">vendor.carrier.inherit</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="priority">36</field>
<field name="arch" type="xml">
<field name="property_stock_supplier" position="after">  
<field name="ship_carrier"/>
           <field name="ship_carrier_account"/>  
</field>
</field>
</record>

<record id="ship_carrier_sale_order_form" model="ir.ui.view">
    <field name="name">customer.carrier.sale.order.inherit</field>
    <field name="model">sale.order</field>
    <field name="inherit_id" ref="sale.view_order_form"/>
    <field name="priority">36</field>
    <field name="arch" type="xml">
        <field name="fiscal_position_id" position="after">
            <field name="ship_carrier"/>
            <field name="ship_carrier_account"/>
        </field>
    </field>
</record>

<record id="supplier_carrier_purchase_order_form" model="ir.ui.view">
<field name="name">supplier.carrier.purchase.order.inherit</field>
<field name="model">purchase.order</field>
<field name="inherit_id" ref="purchase.purchase_order_form"/>
<field name="priority">36</field>
   <field name="arch" type="xml">
<field name="date_planned" position="after">
<field name="ship_carrier"/>
<field name="ship_carrier_account"/>
</field>
</field>
</record>

It added my 2 custom fields to 'res.partner' and to 'sale.order' forms, but not to 'purchase.order' form.

I'm getting the following error:

ValueError: Can't validate view:
Field `ship_carrier` does not exist

I'm trying to use related fields to add them to multiple forms, but it doesn't work for purchase order for some reason. 

What am I doing wrong and what is the easiest way to add a field to multiple forms?

Thanks for help in advance.

Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

So one smart man told me that I was getting that error because of this:

<field name="date_planned" position="after">

I was trying to add field in the tree view purchase.order.line \https://github.com/odoo/odoo/blob/10.0/addons/purchase/views/purchase_views.xml#L212

I tried to add them to an existing tabs by using <xpath> and following xml tags like expr="//form/sheet/notebook/page ...", but I failed. So I created a separate tab and put my fields in there. It's not exactly what I wanted, but good enough for now.


Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
3
thg 12 16
8418
18
thg 12 22
36970
1
thg 11 19
5031
1
thg 6 18
5561
6
thg 6 18
5715