PRIMARY KEY and button


(春节) #1

How to add a primary key to the model?
Ensure data uniqueness?
Can you add button method calls in the wizard?


(mono) #2

you must use a SQL UNIQUE constraint

example:

from trytond.model import ModelSQL, ModelView, fields, Unique

class YourModel(ModelSQL,ModelView)


    @classmethod
        def __setup__(cls):
            super(YourModel, cls).__setup__()
            table = cls.__table__()
            cls._sql_constraints += [
                ('key', Unique(table, table.your_unique_col,table.your_unique_col2,...),
                    'your message')
            ]

Wizard — trytond 5.1 documentation

you can add buttons and on the transition_state (for StateTransition) and do_state (for StateAction and StateReport) methods you can write your code and call the Pool for get other models methods


(春节) #3

Thank you very much for your answer.

TI
Does this button method binding exist in mind?


(mono) #4

you can by example:

class MyWizard(Wizard):
    "My Wizard"
    __name__ = "my_module.my_model.my_wizard"

    start = StateTransition()


    def transition_start(self):
        ShipmentInternal = Pool.get('stock.shipment.internal')
        Shipment = ShipmentInternal.browse([Transaction().context['active_id'])
        Shimpment.done(shipment)
        return 'end'

I used this for to jump steps on the sale process, maybe can help you of reference:



(Nicolas Évrard) #5

Tryton uses surrogate keys.
It’s the id column that is there for every Model.