Put a transparent button over the portal rows:
If the parent is locked, do something useless (like set empty variable..). The portal is no longer accessible, the button will prevent this.
If it's not locked go the the field in the portal to be edited/created.
Maybe you will have to get the current portal row on click to redirect the click to the right row.
Using multiple "psyeudo" buttoms you can lock any field on your layout.
Please don't forget to assign an object name for every field/object you want to go to.
I have solved this issue using a field in the parent that cannot be modified: a lock field.
In order to create child records from the parent I set a validation in the child table primary key that only let create records if the lock field in the parent is open. Since record creation on this table is only accessed through the parent it has no security issues.
This technique cannot prevent the last row of a portal to be filled but it does not allow to commit the record, it reverts it to the previous state. I think portal records locking can only be done using your technique of using another portal view with diferent options in the relationship graph or with interface hacking (transparent buttons and such).
At the database level, it seems create cannot be limited by the schema, but commit can.
If you disallow creation of portal rows via the relationship, instead controlling this process via a script, you will be able to more readily handle the locking issue because it will no longer possible for anyone to simply click in the blnk last portal row to create a new record, and you can also set the portal to not allow direct entry in Browse mode.
I think it is not possible to toggle the "allow creation of records" in the relationship graph by scripting or calculation. Remember he wants to lock the master and detail records once they are marked as locked. Very useful in invoices, for example.
So he would need two relationships. One for showing and one for editing and a script to switch between both layouts when convenient. However, not showing is not locking.
Having one layout for entering data and one layout for showing data (when editing is not allowed) is a nice solution but still you need to make sure no one can bypass the user interface an insert rows in the database when a record is locked. The foolproof way is in the database schema.
I think it is not possible to toggle the "allow creation of records" in the relationship graph by scripting or calculation.
That is not what I was suggesting.
I would like to understand better what you are suggesting.
I assume that what you are saying is to create two layouts. One with editable portal (allow create on the relationship graph) and one with a non editable portal (allow create on the relationship graph empty). After you fill the info in the layout with editable portal then provide a mechanism to navigate to the other layout with non editable portal. This way an "invoice" could be locked after printed, for example.
This works and the question is not about that. You are not avoiding record creation on the table which is the issue, just not showing the interface. From another layout or interface new records on the detail table could be created.
The only way I have found to lock the database at schema level is using a field validation since "security" does not provide a "limit..." on create records.
To avoid editing on child records, I have activated in the security of the database the option "limit..." and insert a calculation that takes into consideration the field record status closed. If status is not closed, then allow editing of the child records.