0

I want to create a excel file that has data from sales, products and stock

ex:

| consumer[key] | Country | product | Inventory Units | Sales Units |

I think I know how to create the file but not sure how to get the information

I added a button to the action [sales] so the user can filter then select the records

but not don't know how to get the recored selected into my function

can you please advice on how to do it

<record id="test_report" model="ir.actions.act_window">
  <field name="name">test report</field>
  <field name="type">ir.actions.act_window</field>
  <field name="res_model">test_report.test_sales_inv_pro</field>
  <field name="view_mode">form</field>
  <field name="target">new</field>
  <field name="binding_model_id" ref="sale.model_sale_order" />
  <field name="binding_view_types">list</field>
  <field name="view_id" ref="sale_report_wizard"/>
</record>

<record id="sale_report_wizard" model="ir.ui.view">
  <field name="name">test report wiz</field>
  <field name="model">test_report.test_sales_inv_pro</field>
  <field name="type">form</field>
  <field name="arch" type="xml">
      <form>
          <footer>
              <button name="fun_test" string="Print" type="object" class="oe_highlight"/>
          </footer>
      </form>
  </field>
</record>

class test_sales_inv_pro(models.TransientModel):
    _name = 'test_report.test_sales_inv_pro'

    @api.model
    def fun_test(self):
        active_ids = self.env.context.get('active_ids', [])
        _logger.warning(active_ids)

When I tried this code I got

You are not allowed to create 'Change the state of sale order' (test_report.test_sales_inv_pro) records.

Moaz Mabrok
  • 697
  • 10
  • 32

1 Answers1

2

You can get the ids of the selected records and with those ids browse the records. Those record ids are found in the context dictionary inside the env object.

sale_obj = self.env['sale.order']
active_ids = self.env.context.get('active_ids', [])
sales = sale_obj.browse(active_ids)
Tiki
  • 760
  • 1
  • 8
  • 16