跳转至内容
  • 版块
  • 标签
  • 热门
  • 用户
  • 群组
皮肤
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • 默认(Flatly)
  • 不使用皮肤
折叠

Odoo 中文社区

  1. 主页
  2. 版块
  3. Odoo 新手求助
  4. 大家看看我这个Domain如何写

大家看看我这个Domain如何写

已定时 已固定 已锁定 已移动 Odoo 新手求助
3 帖子 1 发布者 3.1k 浏览
  • 从旧到新
  • 从新到旧
  • 最多赞同
登录后回复
此主题已被删除。只有拥有主题管理权限的用户可以查看。
  • T 离线
    T 离线
    tedi3231
    写于 最后由 编辑
    #1
    <br />class Reservation(osv.osv):<br />&nbsp; &nbsp; &quot;&quot;&quot;<br />&nbsp; &nbsp; 客户预约<br />&nbsp; &nbsp; &quot;&quot;&quot;<br />&nbsp; &nbsp; _name = &quot;spa.reservation&quot;<br /><br />&nbsp; &nbsp; _columns = {<br />&nbsp; &nbsp; &nbsp; &nbsp; # &#039;name&#039; : fields.char(string=&quot;Name&quot;),<br />&nbsp; &nbsp; &nbsp; &nbsp; &#039;name&#039; : fields.related(&quot;partner_id&quot;, &quot;name&quot;, type=&quot;char&quot;, string=&quot;Name&quot;),<br />&nbsp; &nbsp; &nbsp; &nbsp; &#039;partner_id&#039; : fields.many2one(&#039;res.partner&#039;, string=&quot;Customer&quot;, required=True, domain=&quot;[(&#039;customer&#039;,&#039;=&#039;,1)]&quot;),<br />&nbsp; &nbsp; &nbsp; &nbsp; &#039;store_id&#039; : fields.many2one(&#039;spa.store&#039;, string=&quot;Store&quot; , required=True),<br />&nbsp; &nbsp; &nbsp; &nbsp; &#039;emp_id&#039; : fields.many2one(&#039;hr.employee&#039;, string=&quot;Employee&quot;, domain=&quot;[(&#039;store_id&#039;,&#039;=&#039;,store_id)]&quot;),<br />&nbsp; &nbsp; &nbsp; &nbsp; &#039;reservationdate&#039; : fields.datetime(string=&quot;Reservation Date&quot;, required=True),<br />&nbsp; &nbsp; &nbsp; &nbsp; &#039;remark&#039; : fields.char(string=&quot;Remark&quot;),<br />&nbsp; &nbsp; &nbsp; &nbsp; &#039;reservationlines&#039;: fields.one2many(&#039;spa.reservationline&#039;, &#039;reservation_id&#039;, string=&quot;Reservation Lines&quot;),<br />&nbsp; &nbsp; &nbsp; &nbsp; &#039;state&#039; : fields.selection([(&#039;draft&#039;, &#039;Draft&#039;), (&#039;cancel&#039;, &#039;Cancel&#039;), (&#039;complete&#039;, &#039;Complete&#039;)], string=&quot;State&quot;, readonly=True),<br />&nbsp; &nbsp; }<br />&nbsp; &nbsp; _defaults = {<br />&nbsp; &nbsp; &nbsp; &nbsp; &#039;state&#039;:lambda self, cr, uid, context:&#039;draft&#039;,<br />&nbsp; &nbsp; }<br />Reservation()<br /><br />class ReservationLine(osv.osv):<br />&nbsp; &nbsp; _columns = {<br />&nbsp; &nbsp; &nbsp; &nbsp; # &quot;name&quot;:fields.related(&quot;product_id&quot;,&quot;name&quot;,type=&quot;string&quot;,string=&quot;Name&quot;),<br />&nbsp; &nbsp; &nbsp; &nbsp; &quot;reservation_id&quot;: fields.many2one(&quot;spa.reservation&quot;, string=&quot;Reservation&quot;),<br />&nbsp; &nbsp; &nbsp; &nbsp; &quot;product_id&quot; : fields.many2one(&quot;spa.product&quot;, string=&quot;Product&quot;),<br />&nbsp; &nbsp; &nbsp; &nbsp; &quot;room_id&quot; : fields.many2one(&quot;spa.room&quot;, string=&quot;Room&quot;),<br />&nbsp; &nbsp; &nbsp; &nbsp; &quot;emp_id&quot; : fields.many2one(&quot;hr.employee&quot; , string=&quot;Employee&quot;),<br />&nbsp; &nbsp; &nbsp; &nbsp; &quot;price&quot; : fields.float(string=&quot;Price&quot;, required=True),<br />&nbsp; &nbsp; &nbsp; &nbsp; &quot;unit&quot; : fields.char(string=&quot;Unit&quot;),<br />&nbsp; &nbsp; &nbsp; &nbsp; &quot;count&quot;:fields.integer(string=&quot;Product Count&quot;, required=True),<br />&nbsp; &nbsp; &nbsp; &nbsp; &quot;amount&quot; : fields.float(string=&quot;Amount&quot;),<br />&nbsp; &nbsp; &nbsp; &nbsp; # &quot;amount&quot; : fields.function(_get_reservation_line_amount, string=&quot;Amount&quot;),<br />&nbsp; &nbsp; }<br />
    

    ```
    class Store(osv.osv):
        _name = "spa.store"

        def name_get(self, cr, uid, ids, context=None):
            res = []
            display_widget = None
            if context:
                display_widget = context.get("display_widget", None)
            for r in self.read(cr, uid, ids, ['name', 'storenum']):
                if display_widget == "dropdownlist":
                    res.append((r['id'], '(%s)%s' % (r['storenum'], r['name'])))
                else:
                    res.append((r['id'], r['name']))
            return res

        def name_search(self, cr, uid, name="", args=None, operator="ilike", context=None, limit=100):
            if not args:
                args = []
            if not context:
                context = {}
            ids = []
            if name:
                ids = self.search(cr, uid, [('storenum', operator, name)] + args, limit=limit, context=context)
            if not ids:
                ids = self.search(cr, uid, [('name', operator, name)] + args, limit=limit, context=context)
            return self.name_get(cr, uid, ids, context=context)

        _columns = {
            "name":fields.char(string="Store Name", required=True, size=200),
            "storenum":fields.char(string="Store num", required=True, size=100),
            "country_id":fields.many2one("res.country", string="Country", store=True, required=True),
            "province_id":fields.many2one("res.country.state", string="Province", store=True, required=True, domain=[('country_id', '=', 49)]),
            "address":fields.char(string="Address", size=200),
            "contactperson":fields.char(string="Contact Person", size=100),
            "telephone":fields.char(string="Telephone", size=50),
            "mobile":fields.char(string="Mobile", size=50),
            "email":fields.char(string="Email", size=200),
            "xCoordinate":fields.char(string="X", size=200),
            "yCoordinate":fields.char(string="Y", size=200),
            "rooms" : fields.one2many("spa.room", "store_id", string="Rooms"),
            "remark":fields.text(string="Remark")
        }
        _sql_constraints = [('storenum_uniq', 'unique(storenum)', 'Storenum must be unique!')]

    Store()

    class Room(osv.osv):
        """
        房间
        """
        _name = "spa.room"

        _columns = {
            "name": fields.char(string="Room Name", required=True, size=200),
            "roomnum":fields.char(string="Room Number", required=False, size=100),
            "store_id": fields.many2one("spa.store", string="Store", required=True),
            "description": fields.text(string="Description", required=False),
            "remark" : fields.text(string="Remark"),
        }
    Room()
    ```

    ```
    <record model="ir.ui.view" id="view_reservation_form">
    <field name="name">view.reservation.form</field>
    <field name="model">spa.reservation</field>
    <field name="type">form</field>
    <field name="arch" type="xml">
    <form string="Customer Reservation" version="7.0">
    <header>
    <button name="reservation_complete" states="draft" type="object" string="Convert To Order" class="oe_hightlight"/>
    <button name="reservation_cancel" states="draft" type="object" string="Cancel" class="oe_hightlight"/>
    <field name="state" widget="statusbar" statusbar_visible="draft,cancel" statusbar_colors='{"cancel":"red","draft":"blue"}'/>
    </header>
    <sheet>
    <group col="4">
    <field name="partner_id"/>
    <field name="store_id"/>
    <field name="emp_id"/>
    <field name="reservationdate"/>
    </group>
    <group>
    <field name="remark"/>
    </group>
    <notebook>
    <page string="Reservation Lines">
    <field name="reservationlines">
    <tree version="7.0" editable="bottom">
    <field name="product_id" on_change="product_id_change(product_id,count)"/>
    <field name="room_id" />
    <field name="emp_id"/>
    <field name="count" on_change="product_count_change(count,price)"/>
    <field name="price"/>
    <field name="amount"/>
    </tree>
    </field>
    </page>
    </notebook>
    </sheet>
    </form>
    </field>
    </record>
    ```

    我希望的是FORM的Store改变后,在Tree中选择的房间只能是选中的Store下的房间。
    尝试了几种方式都不行,第一种是在ReservationLine的room_id添加了一个Domain [('store_id','=','reservation_id.store_id')],
    第二种方式是尝试在view中添加domain也不可以,还请高手赐教,谢谢
    1 条回复 最后回复
    0
    • T 离线
      T 离线
      tedi3231
      写于 最后由 编辑
      #2

      问题解决了,还是基础不牢。对这种情况,可以添加<field name="room_id" domain = "[('store_id','=',parent.store_id)]"/>
      用parent就可以解决类似的问题

      1 条回复 最后回复
      0

      • 登录

      • 没有帐号? 注册

      • 登录或注册以进行搜索。
      • 第一个帖子
        最后一个帖子
      0
      • 版块
      • 标签
      • 热门
      • 用户
      • 群组