odoo - 返回包含所有记录的视图
问题描述
所以我制作了一个菜单,该菜单调用了一种方法,该方法制作了一些逻辑并在其中创建记录,product.assortment.remove
并且在创建所有记录之后它返回一个视图。但我的问题是我得到了 0 条记录的视图。
我的目标是我的方法应该返回一个创建了所有记录的视图,并且用户可以删除一些记录(在平均树视图中带有垃圾桶图标)我怎样才能做到这一点?
附言
实际上,我将视图更改为树, <field name="model">assortment.product.removal.wiz</field>
然后product.assortment.remove
它返回了包含所有记录的树视图,但是该视图没有垃圾桶图标,因此用户无法删除记录
class AssortmentProductRemoval(models.TransientModel):
_name = 'assortment.product.removal.wiz'
_description = "Wizard for removing assortment product"
prod_assort_rem_ids = fields.One2many(
'product.assortment.remove', 'product_id',
string='Product Assortmen Remove',)
@api.multi
def _check_assortment_items(self):
<-- some logic here -->
assort_rem_obj = self.env['product.assortment.remove']
vals = ({'qty_sold': qty,
'product_id': product.id,
'profit': profit})
assort_rem_obj.create(vals)
view = self.env.ref('config_hetlita.assortment_product_removal')
return {
'type': 'ir.actions.act_window',
'view_type': 'form',
'view_mode': 'form',
'res_model': 'assortment.product.removal.wiz',
'views': [(view.id, 'form'), (False, 'tree')],
'res_id': self.id,
'target': 'new'
}
class ProductAssortmentRemove(models.Model):
_name = 'product.assortment.remove'
product_id = fields.Many2one(
'product.template', string='Product',
domain=[],
required=False)
turnover = fields.Float(string='Turnover', required=False)
profit = fields.Float(string='Profit', required=False)
qty_sold = fields.Float(string='Quantity sold', required=False)
<record model="ir.ui.view" id="assortment_product_removal">
<field name="name">view.name</field>
<field name="model">assortment.product.removal.wiz</field>
<field name="arch" type="xml">
<form string="Update Set">
<field name="prod_assort_rem_ids" >
<tree editable="bottom">
<field name="product_id"/>
<field name="turnover"/>
<field name="qty_sold"/>
</tree>
</field>
<footer>
<button string="Cancel" icon="gtk-cancel" special="cancel" />
or
<button name="action_save_sol" string="Save" type="object" icon="gtk-ok"/>
</footer>
</form>
</field>
</record>
<record id="action_test2" model="ir.actions.server">
<field name="name">Assortment product removal</field>
<field name="model_id" ref="model_assortment_product_removal_wiz"/>
<field name="state">code</field>
<field name="code">action = self._check_assortment_items(cr, uid, context.get('active_ids'), context=context)</field>
</record>
<menuitem id="your_menu_id12" action="action_test2" parent="base.menu_sale_config" name="Assort remove" sequence="1"/>
解决方案
确保您的用户具有删除访问权限,您可以像这样在树上强制删除图标
<tree delete="1" >
而且因为您在向导中显示您的记录,所以只需在表单视图中显示它们
# remove views key and use view_id
'view_id': view.id
我认为您缺少删除图标,因为 odoo 以视图模式而不是编辑模式显示记录,因为您使用了视图而不是 view_id。或者您的用户对模型没有删除访问权限。
推荐阅读
- python - 使用多处理应用多参数函数以生成熊猫列
- shell - 如何在 gdb 批处理模式下运行命令(打印 $_siginfo,x/i $pc)?
- javascript - TypeError:无法读取未定义的属性“hasOne”
- sql - Oracle SQL - 仅返回具有最高 enquiry_log_number 的查询 ID 的值
- snowflake-cloud-data-platform - 雪花不接受连接中的别名
- reactjs - Storybook 不呈现故事,错误:“useContext(...) 未定义”
- python-3.x - 二维数组处理
- python - pygame 键检测未检测到按键
- javascript - 无法让 Jupyter 笔记本访问 javascript 变量
- java - 如何解决 java.math.BigInteger 无法转换为 java.lang.Integer