Skip to Content
Menu
This question has been flagged
1 Reply
2224 Views

hi all,

below are both Model (.py) and View (xml) files, when I run it from custom Menu and toggle off, instead of Update and set it to False it Deletes record... what I made mistake? is it due to  widget i used? or anythig else? please guide.


Python file:

from odoo import models, fields

class ServiceTypes(models.Model):
    _name = 'tests.servicetypes'
    _rec_name = 'name'
    _description = "Tests Service Types and Services"
    name = fields.Char(string="Services Types", required=True)
    active = fields.Boolean(string="Active?", default=True)
    service_type_ids = fields.One2many('tests.services', 'service_type_id')

class Services(models.Model):
    _name = 'tests.services'
    _rec_name = 'name'
    _description = "Tests Services"
    name = fields.Char(string="Service Name", required=True)
    service_type_id = fields.Many2one('tests.servicetypes', string="Service Type", required=True)
    active = fields.Boolean(string="Active?", default=True)


XML file:
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
    <!-- Services Master Detail Form -->
    <record model="ir.ui.view" id="testsservicetypes_form_view">
        <field name="name">testsservicetypes.form</field>
        <field name="model">tests.servicetypes</field>
        <field name="arch" type="xml">
            <form string="Service Type">
                <sheet>
                    <group>
                        <field name="name"/>
                        <field name="active" widget="boolean_toggle"/>
                    </group>
                    <notebook>
                        <page string="Services">
                            <field name="service_type_ids">
                                <tree editable="bottom" string="Services">
                                    <field name="name"/>
                                    <field name="active" widget="boolean_toggle"/>
                                </tree>
                            </field>
                        </page>
                    </notebook>
                </sheet>
            </form>
        </field>
    </record>

    <record model="ir.ui.view" id="testsservicetypes_tree_view">
        <field name="name">testsservicetypes.tree</field>
        <field name="model">tests.servicetypes</field>
        <field name="arch" type="xml">
            <tree string="Service Types">
                <field name="name"/>
                <field name="active" widget="boolean_toggle"/>
            </tree>
        </field>
    </record>
</odoo>

regards

Avatar
Discard
Best Answer

Hi ,

Odoo provides inbuilt features to enable archive and unarchive options for records 

if the model has a Boolean field named active , Odoo will archive the record when you toggle off . 

Rename field name active to any other name , it will work as you expected .


Hope it Helps ,

Kiran K 


Avatar
Discard
Author

thanks, it means my lack of knowledge... again, and I have to change name "active" to "status" ?? please advice.

Just change field name active to something else , it will work as you expected . :)

Author

ok, i renamed it to "active_status" ... thanks again for your help :)

Related Posts Replies Views Activity
1
Nov 24
1483
1
Nov 24
1189
2
Sep 24
1047
1
Aug 24
2451
3
Aug 24
2686