1
sales.order.line에서 sales_ship이라는 필드와 ship_sale이라는 필드가 있습니다. 이제 내가 원하는 것은 기본적으로 sales.order.line의 ship_sale에서 sales.order의 선택된 sales_ship을 기본적으로 사용하도록하는 것입니다. 문맥을 사용하여 그것을하는 방법? 여기 내 전체 코드입니다.odoo 8.0에서 컨텍스트를 사용하여 판매 주문 라인에 판매 주문 필드를 표시하는 방법은 무엇입니까?
py.
from openerp import models , fields
class ShipInfo (models.Model):
_name = "ship.ship"
imo = fields.Char (string = "IMO" , size = 64 , required = True)
hull_number = fields.Char (string = ' Hull Number ' , size = 64 , required = True)
engine_number = fields.Char (string = ' Engine Number ' , size = 64 , required = True)
vessel_name = fields.Char (string = 'Vessel Name' , size = 64)
build_year = fields.Char (string = 'Build Year' , size = 64)
ship_yard = fields.Many2one ('res.partner' , string = 'Ship Yard')
ship_owner = fields.Many2one ('res.partner' , string = 'Ship Owner')
ship_management = fields.Many2one ('res.partner' ,string= 'Ship Management')
engine_builder = fields.Many2one ('res.partner' , string = 'Engine Builder')
_rec_name = 'vessel_name'
class SaleOrderInherited (models.Model):
_inherit = 'sale.order'
sales_ship = fields.Many2one ('ship.ship' , string = 'Sales Ship')
class SaleOrderLineInherited (models.Model):
_inherit = 'sale.order.line'
ship_sale = fields.Many2one ('ship.ship' , string = 'Sales Ship')
.XML
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<menuitem id="ship_module" name="ship" parent="base.menu_base_config" action="action_view_ship" sequence="30"/>
<!--<menuitem id="ship_menu" name="ship information" parent="ship_module"/>-->
<record model="ir.ui.view" id="ship_form">
<field name="name">ship.ship.form.view</field>
<field name="model">ship.ship</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="ship info">
<sheet>
<group>
<group> <field name="imo"/>
<field name="hull_number"/>
<field name="engine_number"/>
<field name="vessel_name" context="{'sales_ship':sales_ship}"/>
<field name="build_year"/>
</group>
<group>
<field name="ship_yard"/>
<field name="ship_owner"/>
<field name="ship_management"/>
<field name="engine_builder"/>
</group>
</group>
</sheet>
</form>
</field>
</record>
<record model="ir.ui.view" id="ship_tree">
<field name="name">ship.ship.tree</field>
<field name="model">ship.ship</field>
<field name="type">tree</field>
<field name="arch" type="xml">
<tree string="ship info">
<field name="imo"/>
<field name="hull_number"/>
<field name="engine_number"/>
<field name="vessel_name" context="{'sales_ship':sales_ship}"/>
<field name="build_year"/>
<field name="ship_yard"/>
<field name="ship_owner"/>
<field name="ship_management"/>
<field name="engine_builder"/>
</tree>
</field>
</record>
<record model="ir.actions.act_window" id="action_view_ship">
<field name="name">ship info</field>
<field name="res_model">ship.ship</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="help" type="html">
<p class="oe_view_nocontent_create">Create new ship
</p>
</field>
</record>
<!--Inherit the sale order form view-->
<record id="view_sale_order_custom" model="ir.ui.view">
<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="sales_ship" context="{'sales_ship':sales_ship}"/>
</xpath>
<xpath expr="/form/sheet/notebook/page/field[@name='order_line']/tree/field[@name='name']" position="after">
<field name="ship_sale" context="{'sales_ship':sales_ship}"/>
</xpath>
<group>
<button string="Add to Order Line"/>
</group>
</field>
</record>
</data>
그러나 그것은 error.Uncaught 오류 제공 : 나가서 설명하자면 NameError : 이름이 'sales_ship가'지금 확인 – DGL
정의되지 않습니다. 내 대답을 업데이트했습니다. –