我对Odoo并不熟悉,我还在努力了解它的观点。
我需要在购买的标准视图中添加一个字段“products”--输入的产品,它的价值应该从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)]}),
}发布于 2016-12-03 04:46:43
不需要定义关系--它已经存在了,所以您只需要在stock.move中添加相关字段,并通过继承现有视图将该合作伙伴字段添加到Stock.Move的列表视图或form视图中。
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 => 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>https://stackoverflow.com/questions/40931874
复制相似问题