Package: odoo9-addon-cms-form
CMS FormBasic website contents form framework. Allows to define front-end forms for every models in a simple way.If you are tired of re-defining every time an edit form or a search form for your odoo website,
this is the module you are looking for.Featuresautomatic form generation (create, write, search)automatic route generation (create, write, search)automatic machinery based on fields’ type:widget renderingfield value load (from existing instance or from request)field value extraction (from request)field value write (to existing instance)highly customizableworks with every odoo modelworks also without any modeladd handy attributes to models inheriting fromwebsite.published.mixin:cms_add_url: lead to create form view. By default/cms/form/create/my.modelcms_edit_url: lead to edit form view. By default/cms/form/edit/my.model/model_idcms_search_url: lead to search form view. By default/cms/form/search/my.modelUsageCreate / Edit formJust inherit fromcms.formto add a form for your model. Quick example for partner:classPartnerForm(models.AbstractModel):_name='cms.form.res.partner'_inherit='cms.form'_form_model='res.partner'_form_model_fields=('name','country_id')_form_required_fields=('name','country_id')In this case you’ll have form with the following characteristics:works withres.partnermodelhave onlynameandcountry_idfieldsboth fields are required (is not possible to submit the form w/out one of those values)Here’s the result:The form will be automatically available on these routes:/cms/form/create/res.partnerto create new partners/cms/form/edit/res.partner/1edit existing partners (partner id=1 in this case)NOTE: default generic routes work if the form’s name iscms.form.+ model name, likecms.form.res.partner.
If you want you can easily define your own controller and give your form a different name,
and have more elegant routes like`/partner/edit/partner-slug-1.
Take a look atcms_form_example.By default, the form is rendered as an horizontal twitter bootstrap form, but you can provide your own templates of course.
By default, fields are ordered by their order in the model’s schema. You can tweak it using_form_fields_order.Form with extra control fieldsImagine you want to notify the partner after its creation but only if you really need it.The form above can be extended with extra fields that are not part of the_form_modelschema:classPartnerForm(models.AbstractModel):_name='cms.form.res.partner'_inherit='cms.form'_form_model='res.partner'_form_model_fields=('name','country_id','email')_form_required_fields=('name','country_id','email')notify_partner=fields.Boolean()defform_after_create_or_update(self,values,extra_values):ifextra_values.get('notify_partner'):# do what you want here...notify_partnerwill be included into the form but it will be discarded on create and write.
Nevertheless you can use it as a control flag before and after the record has been created or updated
using the hookform_after_create_or_update, as you see in this example.Search formJust inherit fromcms.form.searchto add a form for your model. Quick example for partner:classPartnerSearchForm(models.AbstractModel):"""Partner model search form."""_name='cms.form.search.res.partner'_inherit='cms.form.search'_form_model='res.partner'_form_model_fields=('name','country_id',)_form_fields_order=('country_id','name',)The form will be automatically available at:/cms/form/search/res.partner.NOTE: default generic routes work if the form’s name is`cms.form.search+ model name, likecms.form.search.res.partner.
If you want you can easily define your own controller and give your form a different name,
and have more elegant routes like/partners.
Take a look atcms_form_example.Master / slave fieldsA typical use case nowadays: you want to show/hide fields based on other fields’ values.
For the simplest cases you don’t have to write a single line of JS. You can do it like this:classPartnerForm(models.AbstractModel):_name='cms.form.res.partner'_inherit='cms.form'_form_model='res.partner'_form_model_fields=('name','type','foo')def_form_master_slave_info(self):info=self._super._form_master_slave_info()info.update({# master field'type':{# actions'hide':{# slave field: action values'foo':('contact',),},'show':{'foo':('address','invoice',),}},})returninfoHere we declared that:whentypefield is equal tocontact-> hidefoofieldwhentypefield is equal toaddressorinvoice-> showfoofieldKnown issues / Roadmapadd more tests, especially per each widget and type of fieldprovide better widgets for image and file fields in generalo2m fields: to be tested at allmove widgets to abstract models toosearch form: generate default search domain in a clever wayadd easy way to switch from horizontal to vertical formprovide more examplesx2x fields: allow sub-items creationhandle api onchangessupport python expressions into master/slave rulesBug TrackerBugs are tracked onGitHub Issues. In case of trouble, please
check there if your issue has already been reported. If you spotted it first,
help us smashing it by providing a detailed and welcomed feedback.CreditsSponsorFluxdock.io.ContributorsSimone Orsi <simone.orsi@camptocamp.com>MaintainerThis module is maintained by the OCA.OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.To contribute to this module, please visithttps://odoo-community.org.