Skip to Content
Menu
You need to be registered to interact with the community.
This question has been flagged
1 Odgovori
2404 Prikazi

i have created a Master-Detail page and it works fine. Countries -> States

now i want to add further Cities which are depends on States , how I can add in model and view (xml) to achieve (the best approach). i am copying my model and xml files contents, please check and guide me to add Cities here as details (child) of States.

Model:

from odoo import models, fields, api


class HospitalCountries(models.Model):
_name = 'hospital.countries'
_description = "Countries"

name = fields.Text(string="Country Name", required=True)
slug = fields.Char(string="Slug")

country_ids = fields.One2many('hospital.states', 'country_id')


class HospitalStates(models.Model):
_name = 'hospital.states'
_description = "States"

name = fields.Text(string="State Name", required=True)
country_id = fields.Many2one('hospital.countries', "Country", required=True)

state_ids = fields.One2many('hospital.cities', 'state_id')


class HospitalCities(models.Model):
_name = 'hospital.cities'
_description = "Cities"

name = fields.Text(string="City Name", required=True)
country_id = fields.Many2one('hospital.countries', "Country", required=True)
state_id = fields.Many2one('hospital.states', "State", required=True, domain="[('country_id', '=', country_id)]")
View (xml):




ir\.ui\.view"\ id="locations_form_view">
\ \ \ \ \ \ \ \ locations\.form
\ \ \ \ \ \ \ \ hospital\.countries
\ \ \ \ \ \ \ \
\ \ \ \ \ \ \ \ \ \ \ \
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \
\ \ \ \ \ \ \ \ \ \ \ \
\ \ \ \ \ \ \ \
\ \ \ \


\ \ \ \ ir.ui.view" id="locations_tree_view">
locations.tree
hospital.countries









Locations
ir.actions.act_window
hospital.countries
tree,form


id="menu_locations"
name="Locations"
parent="menu_hospital_operations"
action="action_hospital_locations"
sequence="-11"/>


regards
Avatar
Opusti
Avtor

please also help me here to post my xml file code which can be readable, i copied from pycharm to notepad and from notepad copied the code and paste here, but don't know how it is formatting automatically here , before saving it looks normal but after save my post above, it is very bad now, code is also not complete, how i can paste the xml file code?
regards

Avtor

xml file:
......

<?xml version="1.0" encoding="UTF-8"?>
<odoo>

<!-- Locations Master Detail Form -->
<record model="ir.ui.view" id="locations_form_view">
<field name="name">locations.form</field>
<field name="model">hospital.countries</field>
<field name="arch" type="xml">
<form string="Countries">
<sheet>
<group>
<group>
<field name="name"/>
<field name="slug"/>
</group>
</group>
<notebook>
<page string="States">
<field name="country_ids">
<tree editable="bottom" string="States">
<field name="name"/>
</tree>
</field>
</page>
</notebook>
</sheet>
</form>
</field>
</record>

<record model="ir.ui.view" id="locations_tree_view">
<field name="name">locations.tree</field>
<field name="model">hospital.countries</field>
<field name="arch" type="xml">
<tree string="Countries">
<field name="name"/>
<field name="slug"/>
</tree>
</field>
</record>

<record id="action_hospital_locations" model="ir.actions.act_window">
<field name="name">Locations</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">hospital.countries</field>
<field name="view_mode">tree,form</field>
</record>

<menuitem
id="menu_locations"
name="Locations"
parent="menu_hospital_operations"
action="action_hospital_locations"
sequence="-11"/>
</odoo>

......

Avtor

can i get some help??

Avtor Best Answer

after 2 days, can i ask i have to create a new thread/topic or its is not possible in Odoo?

i already have posted my .xml file code in comment on 3rd May because of problem in pasting it as mentioned earlier.

using Answer feature because i think may be the comment is not able to catch attention.

regards

Avatar
Opusti
Related Posts Odgovori Prikazi Aktivnost
3
avg. 25
2936
1
maj 25
2827
1
apr. 25
3789
1
apr. 25
4656
1
apr. 25
2103