Odoo 中文社区

    • Register
    • Login
    • Search
    • Categories
    • Tags
    • Popular
    • Users
    • Groups

    Odoo中文社区可以通过以下两个域名访问:shine-it.net , odoo.net.cn

    由于系统升迁的原因,本论坛部分较早期的内容存在格式和链接损坏失效的问题,并非本论坛系统本身的缺陷,望谅解

    本社区没有维护任何QQ群讨论组,任何与本社区同名的QQ群讨论组的言论与本社区无关!

    开发人员可以登录gitter讨论组: http://gitter.im/odoo-china/Talk, 需要github账号

    如果您登录系统碰到问题,请在微信公众号留言:

    大家看看我这个Domain如何写

    Odoo 新手求助
    1
    3
    2901
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • T
      tedi3231 last edited by

      <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 Reply Last reply Reply Quote 0
      • T
        tedi3231 last edited by

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

        1 Reply Last reply Reply Quote 0
        • First post
          Last post