Error when duplicate invoice

Thks for the explainations.

I’m stuck in this process: the original invoice had many lines generated by Stock moves among Customer locations and Client ones. Once credit note is edited, I tried to duplicate the original invoice to be able to change the address. But this is refused with message ‘You cannot create this type of document (account.invoice.line-account.tax)’.
Do I have another solution than copying manually one by one each product and quantity on a new invoice? (an error prone process I must say)

Seems it’s unrelated. I don’t get this pb on an older db. Something messed up, I don’t know what.

I suspect that you have a custom modules that add a One2Many to account.invoice.line-account.tax model which does not inherit from ModelView so users are not allowed to write on it.

Now, I’m wondering if the copy operation should really check the access rights on the fields. Maybe it should just check read/write access on the records and do the operations without any other checks to follow the principle of access right on the border.

I’m surprised, I have no One2Many. Nothing found except in account_invoice:

$ grep -R 'account.invoice.line-account.tax'  trytond/modules/*/*.py
trytond/modules/account_invoice/invoice.py:    taxes = fields.Many2Many('account.invoice.line-account.tax',
trytond/modules/account_invoice/invoice.py:    __name__ = 'account.invoice.line-account.tax'

More, the same code base works in dev locally (duplicating invoice or creating a new one). Something went wrong in the db.

It may be useful to run the server with debug logging and can the full traceback for this error.

Here it is:

Traceback (most recent call last):
  File "/home/tryton/venv/lib/python3.5/site-packages/trytond/protocols/dispatcher.py", line 176, in _dispatch
    result = rpc.result(meth(*c_args, **c_kwargs))
  File "/home/tryton/venv/lib/python3.5/site-packages/trytond/modules/sale/invoice.py", line 77, in copy
    return super(Invoice, cls).copy(invoices, default=default)
  File "/home/tryton/venv/lib/python3.5/site-packages/trytond/modules/purchase/invoice.py", line 83, in copy
    return super(Invoice, cls).copy(invoices, default=default)
  File "/home/tryton/venv/lib/python3.5/site-packages/trytond/modules/account_invoice_history/invoice.py", line 53, in copy
    return super(Invoice, cls).copy(invoices, default=default)
  File "/home/tryton/venv/lib/python3.5/site-packages/trytond/modules/account_invoice/invoice.py", line 1127, in copy
    return super(Invoice, cls).copy(invoices, default=default)
  File "/home/tryton/venv/lib/python3.5/site-packages/trytond/model/workflow.py", line 57, in copy
    return super().copy(records, default=default)
  File "/home/tryton/venv/lib/python3.5/site-packages/trytond/model/modelstorage.py", line 357, in copy
    new_records = cls.create(to_create)
  File "/home/tryton/venv/lib/python3.5/site-packages/trytond/model/modelsql.py", line 147, in wrapper
    return func(cls, *args, **kwargs)
  File "/home/tryton/venv/lib/python3.5/site-packages/trytond/model/modelsql.py", line 643, in create
    field.set(cls, fname, *fargs)
  File "/home/tryton/venv/lib/python3.5/site-packages/trytond/model/fields/one2many.py", line 240, in set
    actions[action](ids, *args)
  File "/home/tryton/venv/lib/python3.5/site-packages/trytond/model/fields/one2many.py", line 223, in copy
    Target.copy(copies, default=default)
  File "/home/tryton/venv/lib/python3.5/site-packages/trytond/modules/account_invoice_stock/account.py", line 48, in copy
    return super(InvoiceLine, cls).copy(lines, default=default)
  File "/home/tryton/venv/lib/python3.5/site-packages/trytond/modules/account_invoice/invoice.py", line 2030, in copy
    return super(InvoiceLine, cls).copy(lines, default=default)
  File "/home/tryton/venv/lib/python3.5/site-packages/trytond/model/modelstorage.py", line 357, in copy
    new_records = cls.create(to_create)
  File "/home/tryton/venv/lib/python3.5/site-packages/trytond/modules/account_invoice/invoice.py", line 2021, in create
    return super(InvoiceLine, cls).create(vlist)
  File "/home/tryton/venv/lib/python3.5/site-packages/trytond/model/modelsql.py", line 147, in wrapper
    return func(cls, *args, **kwargs)
  File "/home/tryton/venv/lib/python3.5/site-packages/trytond/model/modelsql.py", line 643, in create
    field.set(cls, fname, *fargs)
  File "/home/tryton/venv/lib/python3.5/site-packages/trytond/model/fields/many2many.py", line 269, in set
    Relation.create(relation_to_create)
  File "/home/tryton/venv/lib/python3.5/site-packages/trytond/model/modelsql.py", line 147, in wrapper
    return func(cls, *args, **kwargs)
  File "/home/tryton/venv/lib/python3.5/site-packages/trytond/model/modelsql.py", line 545, in create
    super(ModelSQL, cls).create(vlist)
  File "/home/tryton/venv/lib/python3.5/site-packages/trytond/model/modelstorage.py", line 104, in create
    ModelAccess.check(cls.__name__, 'create')
  File "/home/tryton/venv/lib/python3.5/site-packages/trytond/ir/model.py", line 522, in check
    cls.raise_user_error(mode, model_name)
  File "/home/tryton/venv/lib/python3.5/site-packages/trytond/error.py", line 74, in raise_user_error
    raise UserError(error)
trytond.exceptions.UserError: ('UserError', ('Vous ne pouvez pas créer ce type de document\xa0! (account.invoice.line-account.tax)', ''))

This is not what is happening.

It seems that you have an access rule defined for the model account.invoice.line-account.tax which prevents you to write on it. Tryton by default does not have access rights on this model because it is only for internal usage.

Thks, solved. The access group “Invoice Read” I added had a line with “Line-Account Tax” read checkbox. Deleting this line solved the problem.

I miss a guide on how to allow some read access to users: creating this simple group I made two mistakes, this one and the fact that not adding Admin to the new group made some menu entries disappear.

The documentation about access rights have been recently rewrote: Access Rights — trytond 5.3 documentation

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