I have the same problem as @shafi12 when trying to add an action “sort_lines” to the account_invoice module. Please have a look at my code. I get the error “Forbidden 403” when selecting the button in the Tryton client (first I just tried to make log entry when selecting the action button).
invoice.xml
<tryton>
<data>
<record model="ir.ui.view" id="invoice_view_form">
<field name="model">account.invoice</field>
<field name="inherit" ref="account_invoice.invoice_view_form" />
<field name="name">invoice_form</field>
</record>
<record model="ir.model.button" id="invoice_sort_lines">
<field name="name">sort_lines</field>
<field name="string">Sort lines</field>
<field name="model" search="[('model', '=', 'account.invoice')]" />
</record>
</data>
</tryton>
invoice.py
from trytond.model import fields, ModelView, Workflow
from trytond.pool import PoolMeta, Pool
from trytond.pyson import Eval
import logging
logger = logging.getLogger(__name__)
class Invoice(metaclass=PoolMeta):
__name__ = 'account.invoice'
sort_state = fields.Selection([
('unsorted', "Unsorted"),
('sorted', "Sorted")
],
"Sort state", required=True,
readonly=True, sort=False
)
@classmethod
def __setup__(cls):
super().__setup__()
cls._transitions.update({
('unsorted', 'sorted'),
})
cls._buttons.update({
'sort_lines': {
'readonly': Eval('sort_state') == 'sorted',
'depends': ['sort_state']
}
})
@classmethod
def default_sort_state(cls):
return 'unsorted'
@classmethod
@ModelView.button
def sort_lines(cls, invoices):
for invoice in invoices:
logger.info("sorting invoice: id {}: recepient {}".format(invoice.id, invoice.party.name))