Openerp 访问视图中多个字段的子值
为了能够根据最短使用寿命要求更容易地选择批次/批次,我希望在“库存、查看、包装、操作、批次”视图中的批次号旁边显示变量“使用日期”(模块product.Expiration)的值 视图(属于模型stock.pack.operation)定义如下(默认): 然后,我找到并发布了建议定义为子视图的SO:Openerp 访问视图中多个字段的子值,openerp,odoo-10,qweb,Openerp,Odoo 10,Qweb,为了能够根据最短使用寿命要求更容易地选择批次/批次,我希望在“库存、查看、包装、操作、批次”视图中的批次号旁边显示变量“使用日期”(模块product.Expiration)的值 视图(属于模型stock.pack.operation)定义如下(默认): 然后,我找到并发布了建议定义为子视图的SO: <!-- ... --> <field name="arch" type="xml"> <field name="lot_id" position="after
<!-- ... -->
<field name="arch" type="xml">
<field name="lot_id" position="after">
<field name="lot_id" nolabel="1">
<tree>
<field name="use_date"/>
</tree>
</field>
</field>
</field>
<!-- ... -->
这一次它没有抛出错误,但是它第二次添加了字段lot\u id,而不是字段use\u date
任何关于如何在批号旁边添加use_date字段的提示都将不胜感激 您可以在模型stock.pack.operation.lot中创建相关字段:
use_date = fields.Char(string='Use date', related='lot_id.use_date')
然后您可以将其添加到视图中:
<!-- ... -->
<field name="pack_lot_ids" nolabel="1" attrs="{'readonly': [('state', '=', 'done')]}">
<tree editable="bottom" decoration-success="qty_todo==qty"
decoration-danger="(qty_todo > 0) and (qty>qty_todo)">
<field name="lot_name" invisible="not context.get('only_create', False)"/>
<field name="lot_id" invisible="context.get('only_create', False)"
domain="[('product_id','=', parent.product_id)]"
context="{'default_product_id': parent.product_id, 'active_pack_operation': parent.id}"/>
<field name="use_date" />
<field name="qty_todo"
invisible="not context.get('show_reserved') or context.get('serial') or context.get('state_done')"
readonly="1"/>
<field name="qty" invisible="context.get('serial')"/>
<button name="do_minus" type="object" icon="fa-minus-square" attrs="{'invisible': [('qty', '<=', 0.99)]}"
invisible="not context.get('show_reserved') or context.get('state_done')"/>
<button name="do_plus" type="object" icon="fa-plus-square" attrs="{'invisible': [('plus_visible', '=', False)]}"
invisible="not context.get('show_reserved') or context.get('state_done')"/>
<field name="plus_visible" invisible="1"/>
</tree>
</field>
<!-- ... -->
我希望这对您有所帮助您可以在model stock.pack.operation.lot中创建一个相关字段:
use_date = fields.Char(string='Use date', related='lot_id.use_date')
然后您可以将其添加到视图中:
<!-- ... -->
<field name="pack_lot_ids" nolabel="1" attrs="{'readonly': [('state', '=', 'done')]}">
<tree editable="bottom" decoration-success="qty_todo==qty"
decoration-danger="(qty_todo > 0) and (qty>qty_todo)">
<field name="lot_name" invisible="not context.get('only_create', False)"/>
<field name="lot_id" invisible="context.get('only_create', False)"
domain="[('product_id','=', parent.product_id)]"
context="{'default_product_id': parent.product_id, 'active_pack_operation': parent.id}"/>
<field name="use_date" />
<field name="qty_todo"
invisible="not context.get('show_reserved') or context.get('serial') or context.get('state_done')"
readonly="1"/>
<field name="qty" invisible="context.get('serial')"/>
<button name="do_minus" type="object" icon="fa-minus-square" attrs="{'invisible': [('qty', '<=', 0.99)]}"
invisible="not context.get('show_reserved') or context.get('state_done')"/>
<button name="do_plus" type="object" icon="fa-plus-square" attrs="{'invisible': [('plus_visible', '=', False)]}"
invisible="not context.get('show_reserved') or context.get('state_done')"/>
<field name="plus_visible" invisible="1"/>
</tree>
</field>
<!-- ... -->
我希望这对您有所帮助谢谢@Dayana,同时,我也选择了您建议的相关字段-但是,use_date是一个Datetime字段,因此它应该是use_date=fields.Datetime(…);)由于Odoo对我来说是一个全新的东西,而且我还在“幕后”学习它的工作原理,因此我仍然对一种不用修改模型就能显示使用日期的解决方案感兴趣。到目前为止,我一直假设可以在视图中不受限制地遵循关系,从而显示相关模型的数据,而无需更改视图指定给的模型。你知道我的假设是否错误吗?在视图中,你不能使用点符号访问字段。您需要在模型中创建字段,或者必须创建相关字段才能在视图中显示它们。我希望你的疑问得到澄清。谢谢@Dayana,同时,我也选择了你建议的相关字段-但是,use_date是一个Datetime字段,因此它应该是use_date=fields.Datetime(…)。)由于Odoo对我来说是一个全新的东西,而且我还在“幕后”学习它的工作原理,因此我仍然对一种不用修改模型就能显示使用日期的解决方案感兴趣。到目前为止,我一直假设可以在视图中不受限制地遵循关系,从而显示相关模型的数据,而无需更改视图指定给的模型。你知道我的假设是否错误吗?在视图中,你不能使用点符号访问字段。您需要在模型中创建字段,或者必须创建相关字段才能在视图中显示它们。我希望你的疑虑得到澄清。
<!-- ... -->
<field name="pack_lot_ids" nolabel="1" attrs="{'readonly': [('state', '=', 'done')]}">
<tree editable="bottom" decoration-success="qty_todo==qty"
decoration-danger="(qty_todo > 0) and (qty>qty_todo)">
<field name="lot_name" invisible="not context.get('only_create', False)"/>
<field name="lot_id" invisible="context.get('only_create', False)"
domain="[('product_id','=', parent.product_id)]"
context="{'default_product_id': parent.product_id, 'active_pack_operation': parent.id}"/>
<field name="use_date" />
<field name="qty_todo"
invisible="not context.get('show_reserved') or context.get('serial') or context.get('state_done')"
readonly="1"/>
<field name="qty" invisible="context.get('serial')"/>
<button name="do_minus" type="object" icon="fa-minus-square" attrs="{'invisible': [('qty', '<=', 0.99)]}"
invisible="not context.get('show_reserved') or context.get('state_done')"/>
<button name="do_plus" type="object" icon="fa-plus-square" attrs="{'invisible': [('plus_visible', '=', False)]}"
invisible="not context.get('show_reserved') or context.get('state_done')"/>
<field name="plus_visible" invisible="1"/>
</tree>
</field>
<!-- ... -->