# How to use proteus with PayInvoice Wizard

**URL:** https://discuss.tryton.org/t/how-to-use-proteus-with-payinvoice-wizard/3939
**Category:** User
**Created:** [March 13, 2021, 3:06pm UTC](https://discuss.tryton.org/t/how-to-use-proteus-with-payinvoice-wizard/3939 "2021-03-13T15:06:49Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![rvong](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/r/3bc359/32.png) [@rvong](https://discuss.tryton.org/u/rvong)
#### Post date: [March 13, 2021, 3:06pm UTC](https://discuss.tryton.org/t/how-to-use-proteus-with-payinvoice-wizard/3939/1 "2021-03-13T15:06:49Z")

</div>

I have a problem getting proteus to execute the `account.invoice.pay` wizard. It raises the following error:

```auto
Traceback (most recent call last):
  File "./pay_invoices.py", line 221, in <module>
    run()
  File "./pay_invoices.py", line 217, in run
    main(args.database, args.config_file, args.source)
  File "./pay_invoices.py", line 202, in main
    pay_supply_invoices(source, config.get_config())
  File "./pay_invoices.py", line 188, in pay_supply_invoices
    pay_invoice = Wizard("account.invoice.pay", context=config.context)
  File "/home/richi/work/pyenv/tryton54/lib/python3.6/site-packages/proteus/ __init__.py", line 1207, in __init__
    self.execute(self.start_state)
  File "/home/richi/work/pyenv/tryton54/lib/python3.6/site-packages/proteus/ __init__.py", line 1234, in execute
    ctx)
  File "/home/richi/work/pyenv/tryton54/lib/python3.6/site-packages/proteus/config.py", line 188, in __call__
    result = rpc.result(meth(*args, **kwargs))
  File "/home/richi/work/pyenv/tryton54/lib/python3.6/site-packages/trytond/wizard/wizard.py", line 295, in execute
    return wizard._execute(state_name)
  File "/home/richi/work/pyenv/tryton54/lib/python3.6/site-packages/trytond/wizard/wizard.py", line 307, in _execute
    list(view['fields'].keys()))
  File "/home/richi/work/pyenv/tryton54/lib/python3.6/site-packages/trytond/wizard/wizard.py", line 93, in get_defaults
    defaults.update(default(fields))
  File "/home/richi/work/pyenv/tryton54/lib/python3.6/site-packages/trytond/modules/account_invoice/invoice.py", line 2738, in default_start
    default['company'] = invoice.company.id
  File "/home/richi/work/pyenv/tryton54/lib/python3.6/site-packages/trytond/model/modelstorage.py", line 1401, in __getattr__
    return super(ModelStorage, self). __getattr__ (name)
  File "/home/richi/work/pyenv/tryton54/lib/python3.6/site-packages/trytond/model/model.py", line 281, in __getattr__
    % (self. __name__ , name, self._values))
AttributeError: 'account.invoice' Model has no attribute 'company': None

```

I know the wizard accesses the current invoice ID from the context `active_id`, so I set this value in the proteus config context before calling the wizard, but it still doesn’t work. Here is my code:

```auto
           with config.set_context(active_id=invoice.id):
                pay_invoice = Wizard("account.invoice.pay", context=config.context)
                pay_invoice.form.date = invoice.invoice_date
                pay_invoice.form.description = mov_id
                pay_invoice.execute('choice', context=config.context)
                if (pay_invoice.form. __class__. __name__ == 'account.invoice.pay.ask'):
                    pay_invoice.form.type = 'writeoff'
                    pay_invoice.form.writeoff = writeoff_precio
                    pay_invoice.execute('pay', context=config.context)
            print(f"Paid, move {mov_id}")

```

I trace the error and it is due to `Transaction().context['active_id']` not returning a value when `PayInvoice.default_start(self, fields)` is called, as if setting the active\_id context in proteus config has no effect in the Transaction context.  
Can someone tell me what I am doing wrong?

---

<div class="post-metadata">

### Author: ![rvong](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/r/3bc359/32.png) [@rvong](https://discuss.tryton.org/u/rvong)
#### Post date: [March 13, 2021, 5:32pm UTC](https://discuss.tryton.org/t/how-to-use-proteus-with-payinvoice-wizard/3939/2 "2021-03-13T17:32:17Z")

</div>

I figured out the problem. I was not passing the correct parameters to proteus `Wizard` constructor.  
I need to pass the invoice to the `model` argument in the constructor, and within the constructor this set to `active_id` in the context.

So the working code is:

```auto
pay_invoice = Wizard("account.invoice.pay", context=config.context, models=[invoice])

```

---

<div class="post-metadata">

### Author: ![system](https://discuss-cdn.tryton.org/uploads/default/original/1X/c6f8ec0a40525cdcd50058c734283450a4b3d38b.png) [@system](https://discuss.tryton.org/u/system)
#### Post date: [April 12, 2021, 5:32pm UTC](https://discuss.tryton.org/t/how-to-use-proteus-with-payinvoice-wizard/3939/3 "2021-04-12T17:32:21Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
