我是Odoo的新手,我仍然试图了解其观点。
我需要添加一个字段" Supplier"在采购的标准视图中 - 收货产品,其值应从stock_move.picking_id.partner_id中获取 我似乎无法弄清楚如何在视图xml中获取该值,尽管似乎已经定义了必要的关系,因为我可以在python代码中以这种方式获取它。
这是标准视图定义:
<record id="view_move_tree_receipt_picking" model="ir.ui.view">
<field name="name">stock.move.tree2</field>
<field name="model">stock.move</field>
<field name="priority" eval="6"/>
<field name="arch" type="xml">
<tree colors="grey:state == 'cancel'" string="Moves">
<field name="date" widget="date"/>
<field name="picking_id" string="Reference" invisible="1"/>
<field name="origin"/>
<field name="product_id"/>
<field name="product_uom_qty"/>
<field name="product_uom" string="Unit of Measure" groups="product.group_uom"/>
<field name="location_id" invisible="1"/>
<field name="location_dest_id" invisible="1"/>
<field name="create_date" invisible="1"/>
<field name="date_expected" invisible="1"/>
<button name="%(stock.move_scrap)d"
string="Scrap Products" type="action"
icon="terp-gtk-jump-to-ltr" context="{'scrap': True}"
states="draft,waiting,confirmed,assigned"
groups="stock.group_stock_user"/>
<field name="state"/>
<button name="action_done" states="draft,assigned,confirmed"
icon="gtk-go-forward" type="object" groups="stock.group_stock_user"
class="oe_highlight" help="Done"/>
</tree>
</field>
</record>
相关的列定义(为简洁起见,跳过不相关的行)
class stock_move(osv.osv):
_name = "stock.move"
_description = "Stock Move"
_order = 'date_expected desc, id'
_columns = {
'picking_id': fields.many2one('stock.picking', 'Reference', select=True, states={'done': [('readonly', True)]}),
}
class stock_picking(osv.osv):
_name = "stock.picking"
_inherit = ['mail.thread']
_description = "Picking List"
_order = "priority desc, date asc, id desc"
_columns = {
'partner_id': fields.many2one('res.partner', 'Partner', states={'done': [('readonly', True)], 'cancel': [('readonly', True)]}),
}
答案 0 :(得分:1)
不需要定义它已经存在的关系,所以你只需要在stock.move中添加相关字段,并在stock.move的列表视图或表单视图中添加该合作伙伴字段,方法是继承现有的视图。
class stock_move(osv.osv):
_inherit = "stock.move"
_columns = {
'partner_id': fields.related('picking_id', 'partner_id', 'Supplier', type='many2one', store=True, readonly=True),
}
现在使用继承在现有视图中添加此partner_id字段。
基本视图ID =&gt; stock.view_move_form(在你的情况下可能会有所不同)
<record id="new_view_id" model="ir.ui.view">
<field name="name">stock.form</field>
<field name="model">stock.move</field>
<field name="inherit_id" ref="stock.view_move_form" />
<field name="priority" eval="40"/>
<field name="arch" type="xml">
<!-- field name which you specify here after then new field will be added. -->
<field name="existing_field_name" position="after">
<field name="partner_id" />
</field>
</field>
</record>