<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 />
```
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也不可以,还请高手赐教,谢谢