Hi, I am working on module for Restaurant Management, where I added the tabs like Table Booking, Orders, Table Order and Kitchen Order Ticket.
Here, after confirmation of Table Booking an Order will crete and after that KOT will generate.
Now, I want to generate an Invoice for the final payment of a customer and I wish that, this particular invoice can shown in accounting module inside customer invoices.
I also tried workflows but there is a problem with the amount_total field. How to get the value of amount_total field inside of another module.(accounting-customer invoices)
Here is my code,
restaurant.py--------------------------------------------------------------------------------------------
class hotel_restaurant_reservation(osv.Model):
def create_order(self, cr, uid, ids, context=None):
proxy = self.pool.get('hotel.reservation.order')
for record in self.browse(cr, uid, ids):
table_ids = [tableno.id for tableno in record.tableno]
values = {
'reservationno':record.reservation_id,
'date1':record.start_date,
'table_no':[(6, 0, table_ids)],
}
proxy.create(cr, uid, values, context=context)
return True
def onchange_partner_id(self, cr, uid, ids, part):
if not part:
return {'value':{'partner_address_id': False}}
addr = self.pool.get('res.partner').address_get(cr, uid, [part], ['default'])
return {'value':{'partner_address_id': addr['default']}}
def action_set_to_draft(self, cr, uid, ids, *args):
self.write(cr, uid, ids, {'state': 'draft'})
wf_service = netsvc.LocalService('workflow')
for id in ids:
wf_service.trg_create(uid, self._name, id, cr)
return True
def table_reserved(self, cr, uid, ids, *args):
for reservation in self.browse(cr, uid, ids):
cr.execute("select count(*) from hotel_restaurant_reservation as hrr " \
"inner join reservation_table as rt on rt.reservation_table_id = hrr.id " \
"where (start_date,end_date)overlaps( timestamp %s , timestamp %s ) " \
"and hrr.id<> %s " \
"and rt.name in (select rt.name from hotel_restaurant_reservation as hrr " \
"inner join reservation_table as rt on rt.reservation_table_id = hrr.id " \
"where hrr.id= %s) " \
, (reservation.start_date, reservation.end_date, reservation.id, reservation.id))
res = cr.fetchone()
roomcount = res and res[0] or 0.0
if roomcount:
raise osv.except_osv(_('Warning'), _('You tried to confirm reservation with table those already reserved in this reservation period'))
else:
self.write(cr, uid, ids, {'state':'confirm'})
return True
def table_cancel(self, cr, uid, ids, *args):
self.write(cr, uid, ids, {
'state':'cancel'
})
return True
def table_done(self, cr, uid, ids, *args):
self.write(cr, uid, ids, {
'state':'done'
})
return True
_name = "hotel.restaurant.reservation"
_description = "Includes Hotel Restaurant Reservation"
_columns = {
'reservation_id':fields.char('Reservation No', size=64, required=True),
'room_no':fields.many2one('hotel.room', 'Room No', size=64),
'start_date':fields.datetime('Start Time', required=True),
'end_date':fields.datetime('End Time', required=True),
'cname':fields.many2one('res.partner', 'Customer Name', size=64, required=True),
'partner_address_id':fields.many2one('res.partner', 'Address'),
'tableno':fields.many2many('hotel.restaurant.tables', 'reservation_table', 'reservation_table_id', 'name', 'Table Number', help="Table reservation detail. "),
'state' : fields.selection([('draft', 'Draft'), ('confirm', 'Confirmed'), ('done', 'Done'), ('cancel', 'Cancelled')], 'state', select=True, required=True, readonly=True),
}
_defaults = {
'state': lambda * a: 'draft',
'reservation_id':lambda obj, cr, uid, context: obj.pool.get('ir.sequence').get(cr, uid, 'hotel.restaurant.reservation'),
}
_sql_constraints = [
('check_dates', 'CHECK (start_date<=end_date)', 'Start Date Should be less than the End Date!'),
]
Model for Orders ......
class hotel_restaurant_order(osv.Model):
def _sub_total(self, cr, uid, ids, field_name, arg, context=None):
res = {}
for sale in self.browse(cr, uid, ids, context=context):
res[sale.id] = sum(line.price_subtotal for line in sale.order_list)
return res
def _total(self, cr, uid, ids, field_name, arg, context=None):
res = {}
for line in self.browse(cr, uid, ids, context=context):
res[line.id] = line.amount_subtotal + (line.amount_subtotal * line.tax) / 100
return res
def generate_kot(self, cr, uid, ids, part):
order_tickets_obj = self.pool.get('hotel.restaurant.kitchen.order.tickets')
restaurant_order_list_obj = self.pool.get('hotel.restaurant.order.list')
for order in self.browse(cr, uid, ids):
table_ids = [x.id for x in order.table_no]
kot_data = order_tickets_obj.create(cr, uid, {
'orderno':order.order_no,
'kot_date':order.o_date,
'room_no':order.room_no.name,
'w_name':order.waiter_name.name,
'tableno':[(6, 0, table_ids)],
})
for order_line in order.order_list:
o_line = {
'kot_order_list':kot_data,
'name':order_line.name.id,
'item_qty':order_line.item_qty,
}
restaurant_order_list_obj.create(cr, uid, o_line)
return True
_name = "hotel.restaurant.order"
_description = "Includes Hotel Restaurant Order"
_columns = {
'order_no':fields.char('Order Number', size=64, required=True),
'o_date':fields.datetime('Date', required=True),
'room_no':fields.many2one('hotel.room', 'Room No'),
'waiter_name':fields.many2one('res.partner', 'Waiter Name'),
'table_no':fields.many2many('hotel.restaurant.tables', 'temp_table2', 'table_no', 'name', 'Table Number'),
'order_list':fields.one2many('hotel.restaurant.order.list', 'o_list', 'Order List'),
'tax': fields.float('Tax (%) '),
'amount_subtotal': fields.function(_sub_total, method=True, string='Subtotal'),
'amount_total':fields.function(_total, method=True, string='Total'),
}
_defaults = {
'order_no': lambda obj, cr, uid, context: obj.pool.get('ir.sequence').get(cr, uid, 'hotel.restaurant.order'),
}
Workflow........
<!-- Workflow definition -->
<record model="workflow" id="wkf_table_resrvation">
<field name="name">wkf.table.reservation</field>
<field name="osv">hotel.restaurant.reservation</field>
<field name="on_create">True</field>
</record>
#----------------------------------------------
Activity
<record model="workflow.activity" id="act_draft">
<field name="wkf_id" ref="wkf_table_resrvation" />
<field name="flow_start">True</field>
<field name="name">draft</field>
</record>
<record model="workflow.activity" id="act_confirm">
<field name="wkf_id" ref="wkf_table_resrvation" />
<field name="name">confirm</field>
<field name="kind">function</field>
<field name="action">table_reserved()</field>
<field name="split_mode">OR</field>
</record>
<record model="workflow.activity" id="act_cancel">
<field name="wkf_id" ref="wkf_table_resrvation" />
<field name="name">cancel</field>
<field name="kind">function</field>
<field name="action">table_cancel()</field>
</record>
<record model="workflow.activity" id="act_done">
<field name="wkf_id" ref="wkf_table_resrvation" />
<field name="name">done</field>
<field name="flow_stop">True</field>
<field name="kind">stopall</field>
<field name="action">table_done()</field>
</record>
<record model="workflow.activity" id="act_create_order">
<field name="wkf_id" ref="wkf_table_resrvation" />
<field name="name">create_order</field>
<field name="kind">function</field>
</record>
<!-- Transition -->
<record model="workflow.transition" id="t1">
<field name="act_from" ref="act_draft" />
<field name="act_to" ref="act_confirm" />
<field name="signal">confirm</field>
</record>
<record model="workflow.transition" id="t2">
<field name="act_from" ref="act_confirm" />
<field name="act_to" ref="act_done" />
<field name="signal">done</field>
</record>
<record model="workflow.transition" id="t3">
<field name="act_from" ref="act_confirm" />
<field name="act_to" ref="act_cancel" />
<field name="signal">cancel</field>
</record>
<record model="workflow.transition" id="t7">
<field name="act_from" ref="act_cancel" />
<field name="act_to" ref="act_draft" />
<field name="signal">settodraft</field>
</record>
<record model="workflow.transition" id="t8">
<field name="act_from" ref="act_done" />
<field name="act_to" ref="act_create_order" />
<field name="signal">create_order</field>
</record>