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

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

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

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

大家看看我这个Domain如何写



  • [code]<br />class Reservation(osv.osv):<br />    """<br />    客户预约<br />    """<br />    _name = "spa.reservation"<br /><br />    _columns = {<br />        # 'name' : fields.char(string="Name"),<br />        'name' : fields.related("partner_id", "name", type="char", string="Name"),<br />        'partner_id' : fields.many2one('res.partner', string="Customer", required=True, domain="[('customer','=',1)]"),<br />        'store_id' : fields.many2one('spa.store', string="Store" , required=True),<br />        'emp_id' : fields.many2one('hr.employee', string="Employee", domain="[('store_id','=',store_id)]"),<br />        'reservationdate' : fields.datetime(string="Reservation Date", required=True),<br />        'remark' : fields.char(string="Remark"),<br />        'reservationlines': fields.one2many('spa.reservationline', 'reservation_id', string="Reservation Lines"),<br />        'state' : fields.selection([('draft', 'Draft'), ('cancel', 'Cancel'), ('complete', 'Complete')], string="State", readonly=True),<br />    }<br />    _defaults = {<br />        'state':lambda self, cr, uid, context:'draft',<br />    }<br />Reservation()<br /><br />class ReservationLine(osv.osv):<br />    _columns = {<br />        # "name":fields.related("product_id","name",type="string",string="Name"),<br />        "reservation_id": fields.many2one("spa.reservation", string="Reservation"),<br />        "product_id" : fields.many2one("spa.product", string="Product"),<br />        "room_id" : fields.many2one("spa.room", string="Room"),<br />        "emp_id" : fields.many2one("hr.employee" , string="Employee"),<br />        "price" : fields.float(string="Price", required=True),<br />        "unit" : fields.char(string="Unit"),<br />        "count":fields.integer(string="Product Count", required=True),<br />        "amount" : fields.float(string="Amount"),<br />        # "amount" : fields.function(_get_reservation_line_amount, string="Amount"),<br />    }<br />[/code]<br />[code]<br />class Store(osv.osv):<br />    _name = "spa.store"<br /><br />    def name_get(self, cr, uid, ids, context=None):<br />        res = []<br />        display_widget = None<br />        if context:<br />            display_widget = context.get("display_widget", None)<br />        for r in self.read(cr, uid, ids, ['name', 'storenum']):<br />            if display_widget == "dropdownlist":<br />                res.append((r['id'], '(%s)%s' % (r['storenum'], r['name'])))<br />            else:<br />                res.append((r['id'], r['name']))<br />        return res<br /><br />    def name_search(self, cr, uid, name="", args=None, operator="ilike", context=None, limit=100):<br />        if not args:<br />            args = []<br />        if not context:<br />            context = {}<br />        ids = []<br />        if name:<br />            ids = self.search(cr, uid, [('storenum', operator, name)] + args, limit=limit, context=context)<br />        if not ids:<br />            ids = self.search(cr, uid, [('name', operator, name)] + args, limit=limit, context=context)<br />        return self.name_get(cr, uid, ids, context=context)<br /><br />    _columns = {<br />        "name":fields.char(string="Store Name", required=True, size=200),<br />        "storenum":fields.char(string="Store num", required=True, size=100),<br />        "country_id":fields.many2one("res.country", string="Country", store=True, required=True),<br />        "province_id":fields.many2one("res.country.state", string="Province", store=True, required=True, domain=[('country_id', '=', 49)]),<br />        "address":fields.char(string="Address", size=200),<br />        "contactperson":fields.char(string="Contact Person", size=100),<br />        "telephone":fields.char(string="Telephone", size=50),<br />        "mobile":fields.char(string="Mobile", size=50),<br />        "email":fields.char(string="Email", size=200),<br />        "xCoordinate":fields.char(string="X", size=200),<br />        "yCoordinate":fields.char(string="Y", size=200),<br />        "rooms" : fields.one2many("spa.room", "store_id", string="Rooms"),<br />        "remark":fields.text(string="Remark")<br />    }<br />    _sql_constraints = [('storenum_uniq', 'unique(storenum)', 'Storenum must be unique!')]<br /><br />Store()<br /><br />class Room(osv.osv):<br />    """<br />    房间<br />    """<br />    _name = "spa.room"<br /><br />    _columns = {<br />        "name": fields.char(string="Room Name", required=True, size=200),<br />        "roomnum":fields.char(string="Room Number", required=False, size=100),<br />        "store_id": fields.many2one("spa.store", string="Store", required=True),<br />        "description": fields.text(string="Description", required=False),<br />        "remark" : fields.text(string="Remark"),<br />    }<br />Room()<br />[/code]<br /><br />[code]<br /> <record model="ir.ui.view" id="view_reservation_form"><br /> <field name="name">view.reservation.form</field><br /> <field name="model">spa.reservation</field><br /> <field name="type">form</field><br /> <field name="arch" type="xml"><br /> <form string="Customer Reservation" version="7.0"><br /> <header><br /> <button name="reservation_complete" states="draft" type="object" string="Convert To Order" class="oe_hightlight"/><br /> <button name="reservation_cancel" states="draft" type="object" string="Cancel" class="oe_hightlight"/><br /> <field name="state" widget="statusbar" statusbar_visible="draft,cancel" statusbar_colors='{"cancel":"red","draft":"blue"}'/><br /> </header><br /> <sheet><br /> <group col="4"><br /> <field name="partner_id"/><br /> <field name="store_id"/><br /> <field name="emp_id"/><br /> <field name="reservationdate"/><br /> </group><br /> <group><br /> <field name="remark"/><br /> </group><br /> <notebook><br /> <page string="Reservation Lines"><br /> <field name="reservationlines"><br /> <tree version="7.0" editable="bottom"><br /> <field name="product_id" on_change="product_id_change(product_id,count)"/><br /> <field name="room_id" /><br /> <field name="emp_id"/><br /> <field name="count" on_change="product_count_change(count,price)"/><br /> <field name="price"/><br /> <field name="amount"/><br /> </tree><br /> </field><br /> </page><br /> </notebook><br /> </sheet><br /> </form><br /> </field><br /> </record><br />[/code]<br /><br />我希望的是FORM的Store改变后,在Tree中选择的房间只能是选中的Store下的房间。<br />尝试了几种方式都不行,第一种是在ReservationLine的room_id添加了一个Domain [('store_id','=','reservation_id.store_id')],<br />第二种方式是尝试在view中添加domain也不可以,还请高手赐教,谢谢



  • [code]<br />class Reservation(osv.osv):<br />    """<br />    客户预约<br />    """<br />    _name = "spa.reservation"<br /><br />    _columns = {<br />        # 'name' : fields.char(string="Name"),<br />        'name' : fields.related("partner_id", "name", type="char", string="Name"),<br />        'partner_id' : fields.many2one('res.partner', string="Customer", required=True, domain="[('customer','=',1)]"),<br />        'store_id' : fields.many2one('spa.store', string="Store" , required=True),<br />        'emp_id' : fields.many2one('hr.employee', string="Employee", domain="[('store_id','=',store_id)]"),<br />        'reservationdate' : fields.datetime(string="Reservation Date", required=True),<br />        'remark' : fields.char(string="Remark"),<br />        'reservationlines': fields.one2many('spa.reservationline', 'reservation_id', string="Reservation Lines"),<br />        'state' : fields.selection([('draft', 'Draft'), ('cancel', 'Cancel'), ('complete', 'Complete')], string="State", readonly=True),<br />    }<br />    _defaults = {<br />        'state':lambda self, cr, uid, context:'draft',<br />    }<br />Reservation()<br /><br />class ReservationLine(osv.osv):<br />    _columns = {<br />        # "name":fields.related("product_id","name",type="string",string="Name"),<br />        "reservation_id": fields.many2one("spa.reservation", string="Reservation"),<br />        "product_id" : fields.many2one("spa.product", string="Product"),<br />        "room_id" : fields.many2one("spa.room", string="Room"),<br />        "emp_id" : fields.many2one("hr.employee" , string="Employee"),<br />        "price" : fields.float(string="Price", required=True),<br />        "unit" : fields.char(string="Unit"),<br />        "count":fields.integer(string="Product Count", required=True),<br />        "amount" : fields.float(string="Amount"),<br />        # "amount" : fields.function(_get_reservation_line_amount, string="Amount"),<br />    }<br />[/code]<br />[code]<br />class Store(osv.osv):<br />    _name = "spa.store"<br /><br />    def name_get(self, cr, uid, ids, context=None):<br />        res = []<br />        display_widget = None<br />        if context:<br />            display_widget = context.get("display_widget", None)<br />        for r in self.read(cr, uid, ids, ['name', 'storenum']):<br />            if display_widget == "dropdownlist":<br />                res.append((r['id'], '(%s)%s' % (r['storenum'], r['name'])))<br />            else:<br />                res.append((r['id'], r['name']))<br />        return res<br /><br />    def name_search(self, cr, uid, name="", args=None, operator="ilike", context=None, limit=100):<br />        if not args:<br />            args = []<br />        if not context:<br />            context = {}<br />        ids = []<br />        if name:<br />            ids = self.search(cr, uid, [('storenum', operator, name)] + args, limit=limit, context=context)<br />        if not ids:<br />            ids = self.search(cr, uid, [('name', operator, name)] + args, limit=limit, context=context)<br />        return self.name_get(cr, uid, ids, context=context)<br /><br />    _columns = {<br />        "name":fields.char(string="Store Name", required=True, size=200),<br />        "storenum":fields.char(string="Store num", required=True, size=100),<br />        "country_id":fields.many2one("res.country", string="Country", store=True, required=True),<br />        "province_id":fields.many2one("res.country.state", string="Province", store=True, required=True, domain=[('country_id', '=', 49)]),<br />        "address":fields.char(string="Address", size=200),<br />        "contactperson":fields.char(string="Contact Person", size=100),<br />        "telephone":fields.char(string="Telephone", size=50),<br />        "mobile":fields.char(string="Mobile", size=50),<br />        "email":fields.char(string="Email", size=200),<br />        "xCoordinate":fields.char(string="X", size=200),<br />        "yCoordinate":fields.char(string="Y", size=200),<br />        "rooms" : fields.one2many("spa.room", "store_id", string="Rooms"),<br />        "remark":fields.text(string="Remark")<br />    }<br />    _sql_constraints = [('storenum_uniq', 'unique(storenum)', 'Storenum must be unique!')]<br /><br />Store()<br /><br />class Room(osv.osv):<br />    """<br />    房间<br />    """<br />    _name = "spa.room"<br /><br />    _columns = {<br />        "name": fields.char(string="Room Name", required=True, size=200),<br />        "roomnum":fields.char(string="Room Number", required=False, size=100),<br />        "store_id": fields.many2one("spa.store", string="Store", required=True),<br />        "description": fields.text(string="Description", required=False),<br />        "remark" : fields.text(string="Remark"),<br />    }<br />Room()<br />[/code]<br /><br />[code]<br /> <record model="ir.ui.view" id="view_reservation_form"><br /> <field name="name">view.reservation.form</field><br /> <field name="model">spa.reservation</field><br /> <field name="type">form</field><br /> <field name="arch" type="xml"><br /> <form string="Customer Reservation" version="7.0"><br /> <header><br /> <button name="reservation_complete" states="draft" type="object" string="Convert To Order" class="oe_hightlight"/><br /> <button name="reservation_cancel" states="draft" type="object" string="Cancel" class="oe_hightlight"/><br /> <field name="state" widget="statusbar" statusbar_visible="draft,cancel" statusbar_colors='{"cancel":"red","draft":"blue"}'/><br /> </header><br /> <sheet><br /> <group col="4"><br /> <field name="partner_id"/><br /> <field name="store_id"/><br /> <field name="emp_id"/><br /> <field name="reservationdate"/><br /> </group><br /> <group><br /> <field name="remark"/><br /> </group><br /> <notebook><br /> <page string="Reservation Lines"><br /> <field name="reservationlines"><br /> <tree version="7.0" editable="bottom"><br /> <field name="product_id" on_change="product_id_change(product_id,count)"/><br /> <field name="room_id" /><br /> <field name="emp_id"/><br /> <field name="count" on_change="product_count_change(count,price)"/><br /> <field name="price"/><br /> <field name="amount"/><br /> </tree><br /> </field><br /> </page><br /> </notebook><br /> </sheet><br /> </form><br /> </field><br /> </record><br />[/code]<br /><br />我希望的是FORM的Store改变后,在Tree中选择的房间只能是选中的Store下的房间。<br />尝试了几种方式都不行,第一种是在ReservationLine的room_id添加了一个Domain [('store_id','=','reservation_id.store_id')],<br />第二种方式是尝试在view中添加domain也不可以,还请高手赐教,谢谢



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


登录后回复
 

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