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

原论坛用户的基本信息和发帖这里都予以保留,请注意:原论坛用户无需重新注册新用户,但是您的密码需要重置

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

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

大家看看我这个Domain如何写



  • [code]
    class Reservation(osv.osv):
        """
        客户预约
        """
        _name = "spa.reservation"

        _columns = {
            # 'name' : fields.char(string="Name"),
            'name' : fields.related("partner_id", "name", type="char", string="Name"),
            'partner_id' : fields.many2one('res.partner', string="Customer", required=True, domain="[('customer','=',1)]"),
            'store_id' : fields.many2one('spa.store', string="Store" , required=True),
            'emp_id' : fields.many2one('hr.employee', string="Employee", domain="[('store_id','=',store_id)]"),
            'reservationdate' : fields.datetime(string="Reservation Date", required=True),
            'remark' : fields.char(string="Remark"),
            'reservationlines': fields.one2many('spa.reservationline', 'reservation_id', string="Reservation Lines"),
            'state' : fields.selection([('draft', 'Draft'), ('cancel', 'Cancel'), ('complete', 'Complete')], string="State", readonly=True),
        }
        _defaults = {
            'state':lambda self, cr, uid, context:'draft',
        }
    Reservation()

    class ReservationLine(osv.osv):
        _columns = {
            # "name":fields.related("product_id","name",type="string",string="Name"),
            "reservation_id": fields.many2one("spa.reservation", string="Reservation"),
            "product_id" : fields.many2one("spa.product", string="Product"),
            "room_id" : fields.many2one("spa.room", string="Room"),
            "emp_id" : fields.many2one("hr.employee" , string="Employee"),
            "price" : fields.float(string="Price", required=True),
            "unit" : fields.char(string="Unit"),
            "count":fields.integer(string="Product Count", required=True),
            "amount" : fields.float(string="Amount"),
            # "amount" : fields.function(_get_reservation_line_amount, string="Amount"),
        }
    [/code]
    [code]
    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()
    [/code]

    [code]
    <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>
    [/code]

    我希望的是FORM的Store改变后,在Tree中选择的房间只能是选中的Store下的房间。
    尝试了几种方式都不行,第一种是在ReservationLine的room_id添加了一个Domain [('store_id','=','reservation_id.store_id')],
    第二种方式是尝试在view中添加domain也不可以,还请高手赐教,谢谢



  • [code]
    class Reservation(osv.osv):
        """
        客户预约
        """
        _name = "spa.reservation"

        _columns = {
            # 'name' : fields.char(string="Name"),
            'name' : fields.related("partner_id", "name", type="char", string="Name"),
            'partner_id' : fields.many2one('res.partner', string="Customer", required=True, domain="[('customer','=',1)]"),
            'store_id' : fields.many2one('spa.store', string="Store" , required=True),
            'emp_id' : fields.many2one('hr.employee', string="Employee", domain="[('store_id','=',store_id)]"),
            'reservationdate' : fields.datetime(string="Reservation Date", required=True),
            'remark' : fields.char(string="Remark"),
            'reservationlines': fields.one2many('spa.reservationline', 'reservation_id', string="Reservation Lines"),
            'state' : fields.selection([('draft', 'Draft'), ('cancel', 'Cancel'), ('complete', 'Complete')], string="State", readonly=True),
        }
        _defaults = {
            'state':lambda self, cr, uid, context:'draft',
        }
    Reservation()

    class ReservationLine(osv.osv):
        _columns = {
            # "name":fields.related("product_id","name",type="string",string="Name"),
            "reservation_id": fields.many2one("spa.reservation", string="Reservation"),
            "product_id" : fields.many2one("spa.product", string="Product"),
            "room_id" : fields.many2one("spa.room", string="Room"),
            "emp_id" : fields.many2one("hr.employee" , string="Employee"),
            "price" : fields.float(string="Price", required=True),
            "unit" : fields.char(string="Unit"),
            "count":fields.integer(string="Product Count", required=True),
            "amount" : fields.float(string="Amount"),
            # "amount" : fields.function(_get_reservation_line_amount, string="Amount"),
        }
    [/code]
    [code]
    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()
    [/code]

    [code]
    <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>
    [/code]

    我希望的是FORM的Store改变后,在Tree中选择的房间只能是选中的Store下的房间。
    尝试了几种方式都不行,第一种是在ReservationLine的room_id添加了一个Domain [('store_id','=','reservation_id.store_id')],
    第二种方式是尝试在view中添加domain也不可以,还请高手赐教,谢谢



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


登录后回复
 

与 Odoo 中文社区 的连接断开,我们正在尝试重连,请耐心等待