Module refactoring

I have written some code to adapt Tryton for my needs, and the code started as an experiment within a single module that has grown into a monolithic monster which has become a bit of a nightmare to manage and maintain, specially when I tried to upgrade it to the latest stable 5.4 version. So, I want to do some refactoring by separating it into multiple smaller modules, following the good software design approach. The problem I have encountered is that I have an existing production DB that is currently using my monolithic module, so I need to plan a strategy to do the refactoring but at the same time be able to update my DB to use the new refactored modules without losing data. So the specific questions I have are:

1- How do I rename an installed module? My approach is to rename the modules’ folder name, and the name in the tryton.cfg and files. Then I will do a DB SQL dump, edit the SQL data by doing a simple string replace of the old module’s name to the new one, and finally reload the SQL back into the DB. Is there any better approach?

2- I will redesign the original monolithic module and plan to divide it into 3 sub-modules, with the idea of grouping features that may be useful to other Tryton’s user, and possibly make them available as modules open to the community. One of the sub-module is the electronic invoice standard used in Costa Rica established by the government since 2018, and another is the listing of the geographical subdivisions for Costa Rica needed to define an address in the country. Most of the code consist of adding functions and more fields to Tryton’s base models such as account.invoice, party.address, product, etc. So when I move some of these class extensions from the old module to the new one, what would be the proper steps and actions needed to keep the data in the DB working after the change? My assumption is that there is no magic solution, and the data in the DB must be modified by hand for example: edit the ir_model and remove class names that are no longer present in the old module.

3- Once I have coded the new sub-modules, I will edit the ir_modules table and probably erase the original monolithic model information. Fire up the server and install the new sub-modules modules using the client. My question is will the server keep the existing data intact from those fields/columns in the tables and automatically associate (reuse) them with the classes from the the new sub-modules?

I am still relatively new to Tryton (started with version 4.8) and I am not a full time programmer. (This is why posting and responding in the discussion board from me is very slow) Programming is just my hobby and I use it to help my job. I believe through out Tryton’s evolution there have been instances with similar situations as mine with refactoring code from a module into another, so I would like to hear some advise on this matter and/or point me out some code examples within the release history so that I can read and learn from.

Why would you rename the module. Just add new modules and make the initial one depend on it.

If you keep the same name and definition for the fields, you have nothing to do.

1 Like

I want to rename it so that the name describe what the module does, in case someone else wants to use it.

You can still have meaningful name if you just move code to a proper module and keep the existing one with remaining code.