In this tutorial you are going to learn how to develop custom feature for shopinvader.
Shopinvader architecture is based on a REST API. The main idea is to be able to develop new feature without any frontend template. Traditional developement mix the front and the back but this is a bad practice and make slow the developpment (front dev wait for back dev and back dev wait for front dev)
To be efficient for every feature we develop we will start by writting a test ! So for developping a new feature you do not need to install wagon, locomotive. You just need Odoo, if you absolutly want to develop with wagon you really really go in the wrong way, so I will not help you ;).
Tips for testing
Be efficient use pytest : pytest-odoo
Every step of the following tutorial can be found here : odoo-shopinvader-customize
Imaging that you want to show an extra information on you sale order (like the state of manufacturing, the hour/date for retrieving your package…).
For the exercice we are going to add the field “custom_field” (a char field) on the sale order and add it into the API
If it’s the first time that you create an Odoo module please take a look here :
Writing test for shopinvader is quit is the same as usual but instead of using the TransactionCase of Odoo we recommend to use the CommonCase from Shopinvader.
The CommonCase class have some helper to make it simplier to test your service. You can import the class like that:
from odoo.addons.shopinvader.tests.common import CommonCase
class CustomSaleServiceTest(CommonCase):
def test_read_custom_field(self):
pass
This helper, will return you the service wanted
Example
with self.work_on_services() as work:
sale_service = work.component(usage="sales")
sale_service.dispatch('get', sale_id)
If you want to pass the partner logged on the front
partner = self.env.ref("shopinvader.partner_1")
with self.work_on_services(partner=partner) as work:
sale_service = work.component(usage="sales")
sale_service.dispatch('get', sale_id)
Try to build the test, when you think it’s ready you can take a look at
Solution at Modify sale service. STEP 2: Add test
You need to add the field “custom_fields” into the model sale.order
You need to inherit the method _convert_one_sale of the service shopinvader.sale.service
Note: service are base on the Component module: doc code source
Inheriting the SaleService can be done like this
from odoo.addons.component.core import Component
class SaleService(Component):
_inherit = "shopinvader.sale.service"
Now you know how to modify a webservice let’s go futher.
We are going to add a new field on the partner and make it editable for the address service
And yes again we start with the test. You need to create three test
Now you have a working broken test let’s add the feature
On the sale order we are going to add a new method that can be call by the web service
This method will be custom_action and will just flag the field custom_action_done on the sale order.
The test should use an existing sale order and call the method custom_action by using the dispatch method.
Add an assert to check that the field custom_action_done is flag at True
Now you can edit the sale service and add the custom_action method.
Do not forget to add a validator.