我创建了一个自定义模块,用于在sale.order和 contract_num 以及 rel_sale_order project 和 contract_no >在购买模块中。现在在PO中选择“rel_sales_order”时,会自动将“contract_no”从SO传递给PO。怎么做? 我的代码:
的.py
from openerp import models, fields
class SaleLink(models.Model):
_inherit = 'sale.order'
project = fields.Char(string='Project', help='Project details')
contract_no = fields.Char(string='Contract No')
class PurchaseLink(models.Model):
_inherit = 'purchase.order'
contract_num = fields.Char('sale.order', string='Contract number')
rel_sale_order = fields.Many2one('sale.order', string='Related Sales Order', required=True)
.XML
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<record model="ir.ui.view" id="sale_linker_custom">
<field name="name">sale.order.custom.form.inherited</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='partner_id']" position="after">
<field name="project"/>
<field name="contract_no"/>
</xpath>
<xpath expr="//page[@string='Other Information']" position="after">
<page string="Related Purchase Orders">
</page>
</xpath>
</field>
</record>`
<record model="ir.ui.view" id="purchase_linker_custom">
<field name="name">purchase.order.custom.form.inherited</field>
<field name="model">purchase.order</field>
<field name="inherit_id" ref="purchase.purchase_order_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='partner_ref']" position="after">
<field name="contract_num"/>
</xpath>
<xpath expr="//field[@name='dest_address_id']" position="after">
<field name="rel_sale_order"/>
</xpath>
</field>
</record>
</data>
</openerp>
答案 0 :(得分:1)
您必须在PO rel_contract_no中添加另一个字段。
rel_contract_no = fields.Char(related='rel_sale_order.contract_no)
在视图上传递此字段。