Hie, 2018-01-31 14:51 GMT+01:00 Maxime Richez <maxime.ric...@gmail.com>: > > Hi, > > Some questions and explanations of something i thought easy to realize... > I decide to create a custom module to add a sequence on an existing field. In my case, it concerns stock_lot module. There's a field "number" (type char, required=true) that i need to be "sequenced". > > So in my module, there are 2 classes: Configuration, ConfigurationSequence to define my sequence and i update the original class "Lot" to define "number" field "readonly", and set sequence on this number field when creating a new lot. > > Here's the code: https://pastebin.com/74EXsjT7
I think the problem is: cls.number.states['readonly'] = True Try to remove required states that is not True (and/or invisible in case that you like not show it) > In the first time, forgot the __register__ method. > > When executing my new module and saving a new lot, this was not working, i got error on "Number" that is required... it seems number field is not updated by my new sequence... > > Checking my create method, there's a test "if values.get('number') is None:"... > I discovered this test is not working because value of the field is not None but "" (checking database, related field is defined as "NOT NULL" because of the "required = True" in the original model and then couldn't be None). > > Checking many tryton scripts, i saw it was possible to remove the "NOT NULL" through the register method with "table.not_null_action('number', action='remove')"... but not allowed to do this with a custom module because there is a check if the module_name attempting to update fields is the original module. > > So, what's the best way to finish my custom module? > > - Changing my original test "if values.get('number') is None:" by "if values.get('number') == "":" (and keeping the database unchanged) ? > - Using some sql in the __register__ method to remove the "NOT NULL" on the "number" column ? Why not design your feature as the code in party module (from sequence or not)? https://bitbucket.org/tryton/party/src/7f54e6742e171187d0e84640f68fd88bc30a8e28/party.py?at=default&fileviewer=file-view-default#party.py-34 https://bitbucket.org/tryton/party/src/7f54e6742e171187d0e84640f68fd88bc30a8e28/party.py?at=default&fileviewer=file-view-default#party.py-188 Regards -- You received this message because you are subscribed to the Google Groups "tryton-dev" group. To view this discussion on the web visit https://groups.google.com/d/msgid/tryton-dev/CAN2HbXWC93NcxJnN1XA2mz_mshzr2KhO-mpS_6Tw2A3QhpNTbA%40mail.gmail.com.