代码之家  ›  专栏  ›  技术社区  ›  Chaban33

返回包含所有记录的视图

  •  1
  • Chaban33  · 技术社区  · 6 年前

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

    我的目标是,我的方法应该返回一个包含所有创建的记录的视图,并且用户可以删除一些记录(在平均树视图中使用垃圾图标),我如何才能实现?

    附笔。

    事实上我把视角改成了树 <field name="model">assortment.product.removal.wiz</field> 产品.分类.删除 它返回了包含所有记录的树视图,但该视图没有垃圾箱图标,因此用户无法删除记录

    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"/>
    
    1 回复  |  直到 6 年前
        1
  •  1
  •   Charif DZ    6 年前

    确保您的用户具有删除访问权限,并且您可以强制树上的“删除”图标如下所示

         <tree delete="1" >
    

    因为您在向导中显示记录,所以只需在窗体视图中显示它们

          # remove views key and use view_id
          'view_id': view.id
    

    我认为您缺少“删除”图标,因为ODOO以查看模式而不是编辑模式显示记录,因为您使用的是视图而不是视图ID。或者您的用户对模型没有“删除”访问权限。