This question has been flagged
3775 Views

So i made a menu that is calling a method that makes some logic and creates records in product.assortment.remove and after all record are created it returns a view. But my problem is that I get the view with 0 records.

My goal is that my method should return a view with all records created and a user can remove some records( with trash icon like in average tree view) how can i acheave that?

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"/>
Avatar
Discard