I am using ZendFramwork3, i'm new in this so don't know how to autoload the module after creation without terminal command.
I am creating module with programme just by taking module name from the user the following things will be done :
- Module structure for new module with namespace and controller & view files will be placed under module folder
- ModuleName is initialised in modules.config.php in config folder
- Also entry in composer.json in autoload --> psr-4 initialisation done
After that i have to manually run the command "composer dump-autoload" to perfectly work my module but i don't want to do that manually rather i want solution for that to run it programmatically.
Thank you for the solution in advance.
Related
I am new to Odoo and I need to know what is the basic steps of adding a new module.
More specifically I need to know how to add custom modules to the addons-path.
In Odoo document they explain this step as this
$ ./odoo-bin --addons-path=../custom,../enterprise/,addons
but did not work for me.
For adding a new module you should do these steps:
Build your module with your written code or scaffold command.
Add the module path in your config file at addons-path = '',''
Change your URL like this: http://localhost:8091/web?debug=1
Go to apps and from up tabs
Select update app list and refresh your page.
Now you can see your module in the apps.
If you are not getting your custom module in Odoo after adding the path then you can try to add the full path of your folder into addons-path.
To get the full path of your custom folder just right-click on the folder and go to properties and find the path of your folder.
Also, you have to make sure to Apply the Update App list in your Odoo App Dashboard after restarting the server with custom addons.
I am new to Odoo.sh.
When I use the editor to create a new module using the scaffold command
odoo-bin scaffold shelter
The module is named shelter, however, when I try to update current module,
it shows warning:
odoo.modules.loading: invalid module names, ignored: shelter
When i connect to the build, I was not able to see the new module I build under apps.
Anyone know where the problem is?
Question updated:
In odoo sh, under odoo folder, tried the update all module command
In terminal, the warning shown above went away.
However, still no module found named "shelter" after I activate the dev mode and update the apps list.
no module found
Value of conf file listed:
conf file list
well The user is answered in comments. so I am adding the answer for documentation purpose.
when scaffolding a new module make sure that it is added in addon path or listed in odoo configuration file.
I am using Odoo v12 on Windows.
I have followed the steps in HowTo to create a module Saadoodoo. My problem is that I have failed to make this new module appear on the Odoo module list.
I am using the below command
python.exe odoo-bin" -d SaadoIncLocal -i Saadoodoo --addons-path D:\PythonDev\Odoo
It seems Odoo simply ignores the commands and starts the server normally, as the module does not appear on the apps list (even when selecting developer mode).
I thought the issue may be in the addon path, so I added the module under the default Odoo path along with Odoo modules in C:\Program Files (x86)\Odoo 12.0\server\odoo\addons and did an apps update on Odoo interface but still problem persists. Starting and stopping the server does not help either.
What am I doing wrong?
After adding new module in the addons_path, you have to turn on debug/developer mode, goto Apps > Update modules list, remove Apps filter from search and search your module.
Don't forget to add __manifest__.py with proper data, which is important for odoo addons.
If still having problem, you can use scaffold option of odoo-bin to create empty module.
python.exe odoo-bin scaffold my_module
This is will create a empty module with all the necessary skeleton files in the current working directory, you can just move it to addons folder, rename the variables accordingly and files and you are good to go.
There could be 2 Reasons that you are not able to see the module :-
1. You have not updated the database
Two ways to update the database :-
1.1 from Terminal use this command to update the module and database
./odoo-bin -c debian/odoo.conf -d {NAME_OF_ODOO_DATABASE} -u {NAME_OF_THE_NEW_MODULE}
1.2. From frontend
By activating the developer mode by going to Setting --> under the developer tools option --> Activate the developer mode
Now go to app list and select the option update app list.
2. You have not configured the addons path in the debian/odoo.conf file
Make sure that you have added the addons_path of the custom-addons folder in odoo.conf file inside debian folder
why don't you simply use these commands
cd C:\Program Files (x86)\Odoo 12.0\server\odoo\addons
C:\Program Files (x86)\Odoo 12.0\python\python.exe C:\Program Files (x86)\Odoo 12.0\server\odoo-bin scaffold my_module --config C:\Program Files (x86)\Odoo 12.0\server\odoo.conf
Oh once your module is ready, go to the Odoo directory in windows, navigate to custom-addons and you will see a list of all the available modules. paste your new module in there. Now open the Odoo again, go to Apps, then update module list. Then search for your app in the app list. Make sure the developer mode is activated
Go to your odoo-version folder (ex: cd /home-path/odoo-09.0/10.0/11.0/12.0/13.0) where your odoo-bin file is placed (till odoo-10.0 the file is openerp-server but in later version the file is odoo-bin)
Run the command ./odoo-bin scaffold yourModuleName destinationDirectory (odoo_version >= 10)
Run the command ./openerp-server scaffold your_module_name destinationDirectory (odoo_version < 10)
please use configuration file to run odoo(it's quite easy without any mistake)
run this command: python3 odoo-bin --save --config odoo.cfg --stop-after-init
that will save odoo.cfg file open it up and add your custom module path in addons_path varibale which is defined in top of configuartion file
using mode debug, go to your apps, click update app list
Use this command to create module in odoo.
odoo-bin scaffold mynewmodule addons
directive command module-name modulepath
Have you click Update App List in menu Apps?
This is screenshot from Odoo 11, it should applied in Odoo 12 but may be different position.
I am trying to start PHPUnit testing.
I am using composer to load PHPUnit 4.5 , Yii 1.1.14 and some custom Yii packages that we have built.
Inside those custom packages, we autoload some files that set some aliases using the Yii class.
When running our application, we include the base Yii file manually, and then run the composer generated autoloads.
The trouble is, when we run PHPUnit.. the composer autoloads get run first. Even when specifying a bootstrap file with the include:
bin/phpunit --bootstrap carcass/phpunit.bootstrap.php
Leading to the following Exception:
Fatal error: Class 'Yii' not found
In fact it appears the autoloads are run even before the -- options are parsed:
bin/phpunit --help
results in the same error. Removing the autoloads allows PHPunit to run.
Is there any way around this?
I tried placing an autoload for the Yii base file in our main composer.json, but the sub-packages' autoloads get run first.. same error.
I also tried placing an autoload for the Yii base file in each of the sub-packages.. but then we get redeclaration errors as composer uses require. I'm also not a massive fan of this option as it rigidly defines where the Yii definition comes from to sub-packages that don't really need to know.
As the autoload classmap section is run first before all the files sections (including those from the sub-packages).
Placing the yii and YiiBase files in the classmap of the main composer.json for our project solved this issue:
"autoload": {
"classmap": [
"composer_packages/yiisoft/yii/framework/YiiBase.php",
"composer_packages/yiisoft/yii/framework/yii.php"
],
"files": [
...
]
}
I want to write unit tests for a module file I created and put it in lib directory. Under test/unit directory, I have created a mylib_test.rb file. In the file I have required mylib. When I run rake test:units it gives a const_missing: uninitialized constant mylib::constantname error. I'm thinking that this is because it is not loading the rails environment since the constant is defined in one of the initializers file. I'm I correct? How do I get it to work? What is the best way to write unit tests for modules?
I'm using rails 3.1.3 and the model works perfectly when I run the application both from terminal and from a browser.
I just ran into this as well. There are (at least?) 2 possible problems:
Your module is not in the autoload path
Look in config/application.rb for this line:
config.autoload_paths += %W(#{config.root}/extras)
If it's commented, uncomment it. This line will turn on autoloading for all files inside extras, and all files in subdirectories of extras, too. It's probably safest to move your modules into extras, but if you really want to leave them in lib, change the line to be:
config.autoload_paths += %W(#{config.root}/extras #{config.root}/lib)
Your module is in the autoload path, but not named the way Rails expects
(see this: Rails 2.3.5: How does one access code inside of lib/directory/file.rb?)
By convention, Rails wants the name of your module to match the directory hierarchy and the filename. So the file extras/mylib.rb would be expected to contain
module Mylib # not MyLib or My_lib
...
end
This works for subdirectories as well, so a file extras/mydir/mylib.rb should contain:
module Mydir
module Mylib # or class Mylib
...
end
end
This naming convention is the same as what Rails expects for controllers and models. Underscores in the filename turn into a camelcase class/module name. A file called my_lib.rb would be expected to have a module MyLib in it (but not Mylib).
NOTE that autoload does not mean that the module is automatically loaded at startup; rather, it's automatically loaded when it's first used. So even if you have some code like puts "hi from mylib" at the top of your mylib.rb file, you won't see that print until your code uses Mylib somewhere.
Finally, if you really want your modules to load at startup, go create a file called config/initializers/force_load_libraries.rb and put this in there:
Dir.glob("#{Rails.root}/extras/force_load/*.rb").each { |f| require f }
Now go put your libs in extras/force_load and they should load when Rails starts up.
I finally realized what was wrong. In my test files, I was including my modules from the lib directory, Instead of reopening the module and put the test files in the the module. After doing that rake test:units works perfectly. Test files should remain in test/unit directory