因此,我正在为黎巴嫩制作这种本地化类型的模块,并且目前正在执行定位操作。 预期的功能是通过过滤掉无关的选项来限制用户可以对选择的地区,区域和区域进行选择。
以下是模型:
# -*- coding: utf-8 -*-
from odoo import models, fields, api
# Base model
class LebaneseLocation(models.Model):
_inherit = "res.partner"
governate_id = fields.Many2one("lebanon.governate", "Governate")
district_id = fields.Many2one("lebanon.district", "District")
region_id = fields.Many2one("lebanon.region", "Region")
# Child models with the necessary relations
class Governate(models.Model):
_name = "lebanon.governate"
name = fields.Char()
child_districts = fields.One2many("lebanon.district", "parent_governate",
"Child Districts")
class District(models.Model):
_name = "lebanon.district"
name = fields.Char()
parent_governate = fields.Many2one("lebanon.governate", "Parent Governate")
child_regions = fields.One2many("lebanon.region", "parent_district",
"Child Regions")
class Region(models.Model):
_name = "lebanon.region"
name = fields.Char()
parent_district = fields.Many2one("lebanon.district", "Parent District")
和视图文件:
<?xml version="1.0"?>
<odoo>
<record id="view_res_partner_extended_location" model="ir.ui.view">
<field name="name">Contacts Custom</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="arch" type="xml">
<field name="category_id" position="after">
<field name="governate_id" domain="[('child_districts','=?','district_id'),('child_districts.child_regions','=?','region_id')]"/>
<field name="district_id"/>
<field name="region_id"/>
</field>
</field>
</record>
</odoo>
所有数据都是通过两个数据文件输入的,一个使没有关系的记录成为可能,而另一个更新具有关系的相同记录。
我当时正在使用Governate域进行测试,但它一直不返回任何内容。
是否有某种方法可以检查我正在评估的这些参数到底返回了什么?这对调试很有帮助。
编辑:这是Studio菜单中网域的屏幕截图,以防与调试完全相关(我通常避免像瘟疫一样躲避Studio) Domain Image
答案 0 :(得分:0)
我通过放弃XML方法并使用onchange api调用设置域来解决了我的问题:
@api.onchange('governate_id', 'district_id', 'region_id')
def update_domains(self):
governate = self.governate_id.name
district = self.district_id.name
region = self.region_id.name
result = {}
result['domain']={
'governate_id':[('child_districts.name','=?', governate),
('child_districts.child_regions.name', '=?', region)],
'district_id':[('parent_governate.name', '=?', governate),
('child_regions.name', '=?', region)],
'region_id':[('parent_district.name', '=?', district),
('parent_district.parent_governate.name', '=?', governate)]
}
return result