返回包含所有记录的视图



所以我制作了一个菜单,它调用了一个方法,该方法生成一些逻辑并在product.assortment.remove中创建记录,在创建所有记录后,它返回一个视图。但我的问题是,我得到的视图有0条记录。

我的目标是,我的方法应该返回一个创建了所有记录的视图,用户可以删除一些记录(像普通树视图中那样带有垃圾图标(,我该如何保存?

p.S.

实际上,我把视图改为树,把<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。或者您的用户没有对该模型的删除访问权限。

最新更新