Add a button to sort invoice lines

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).


    <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 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')]" />

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

    def __setup__(cls):
            ('unsorted', 'sorted'),
           'sort_lines': {
                'readonly': Eval('sort_state') == 'sorted',
                'depends': ['sort_state']

    def default_sort_state(cls):
        return 'unsorted'

    def sort_lines(cls, invoices):
        for invoice in invoices:
  "sorting invoice: id {}: recepient {}".format(,

For me you Invoice class is not correctly registered in the Pool so the final account.invoice object does not contain the button which raises FORBIDDEN when being called.

I followed the example “Extend model” in the modul tutorial (Extend model — Tryton server). Here is my :

from trytond.pool import Pool
from . import invoice

__all__ = ['register']

def register():
        module='sort-invoice-grouping', type_='model')

This does not seem to be a valid module name.

Thanks, that was the error. I changed the module name from sort-invoice-grouping to sort_invoice_groupint and it works; so no dashes, only underscore in the module name! The register call is now:

def register():
        module='sort_invoice_grouping', type_='model')

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