Skip to content

Instantly share code, notes, and snippets.

@repodevs
Created July 17, 2017 10:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save repodevs/64ffb602025d5acafa6c3cb008b93cb4 to your computer and use it in GitHub Desktop.
Save repodevs/64ffb602025d5acafa6c3cb008b93cb4 to your computer and use it in GitHub Desktop.
add field in existing odoo models
from odoo import models, fields, api, _
class SiteSurvey(models.Model):
_inherit = "site.survey"
cancel_reason = fields.Char("cancel reason")
class SiteSurveyWizard(models.TransientModel):
_name = "site.survey.wizard"
cancel_note = fields.Char("Cancel Reason")
@api.multi
def cancel_it(self):
site_obj = self.env['site.survey']
context = dict(self._context or {})
for data in self:
for srv in site_obj.browse(context.get('active_ids')):
srv.write({'cancel_reason': data.cancel_note})
return True
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<!-- view for wizard -->
<record id="view_survey_cancel" model="ir.ui.view">
<field name="name">account.invoice.refund.form</field>
<field name="model">account.invoice.refund</field>
<field name="arch" type="xml">
<form string="Cancel Form">
<field name="cance_note" />
<footer>
<button string='Create Cancel Note' name="cancel_it" type="object" class="btn-primary"/>
<button string="Cancel" class="btn-default" special="cancel"/>
</footer>
</form>
</field>
<!-- action window -->
<record id="action_survey_cancel" model="ir.actions.act_window">
<field name="name">Cancel Survey</field>
<field name="res_model">site.survey.wizard</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="view_id" ref="view_survey_cancel"/>
<field name="target">new</field>
</record>
</data>
</odoo>
<!-- ADD THIS BUTTON IN YOUR XML "site.survey" VIEW -->
<button name="%(action_survey_cancel)d" type="action" string="Cancel Survey" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment