Changes in functions , workflow ; Created wizard to cancel Repair

bzr revid: ruchakpatel@gmail.com-20081015104108-nzgakcmoe60j3xbl
This commit is contained in:
Rucha Patel
2008-10-15 16:11:08 +05:30
parent a00409ffc6
commit ee5fc4053b
3 changed files with 90 additions and 33 deletions
+1
View File
@@ -29,6 +29,7 @@
##############################################################################
import mrp_repair
import wizard
import report
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
+72 -26
View File
@@ -51,11 +51,11 @@ class mrp_repair(osv.osv):
], 'State', readonly=True, help="Gives the state of the Repairs Order"),
'location_id': fields.many2one('stock.location', 'Current Location', required=True, select=True),
'location_dest_id': fields.many2one('stock.location', 'Delivery Location'),
'move_id': fields.many2one('stock.move', 'Move',required=True,domain="[('product_id','=',product_id),('location_dest_id','=',location_id)]"),#,('prodlot_id','=',prodlot_id)
'move_id': fields.many2one('stock.move', 'Move',required=True,domain="[('product_id','=',product_id)]"),#,('location_dest_id','=',location_id),('prodlot_id','=',prodlot_id)
'guarantee_limit': fields.date('Guarantee limit'),
'operations' : fields.one2many('repair.operation', 'repair_id', 'Operation Lines', readonly=True, states={'draft':[('readonly',False)]}),
'pricelist_id': fields.many2one('product.pricelist', 'Pricelist'),
'partner_invoice_id':fields.many2one('res.partner.address', 'Invoice to', readonly=True, states={'draft':[('readonly',False)]}),
'partner_invoice_id':fields.many2one('res.partner.address', 'Invoice to', readonly=True, states={'draft':[('readonly',False)]}, domain="[('partner_id','=',partner_id)]"),
'invoice_method':fields.selection([
("none","No Invoice"),
("b4repair","Before Repair"),
@@ -72,24 +72,27 @@ class mrp_repair(osv.osv):
'state': lambda *a: 'draft',
}
def onchange_product_id(self, cr, uid, ids, prod_id=False):
def onchange_product_id(self, cr, uid, ids, prod_id=False, move_id=False ):
if not prod_id:
return {'value':{'prodlot_id': False , 'move_id': False, 'location_id' : False}}
product = self.pool.get('product.product').browse(cr, uid, [prod_id])[0]
current_date = time.strftime('%Y-%m-%d')
limit = mx.DateTime.strptime(current_date, '%Y-%m-%d') + RelativeDateTime(months=product.warranty, days=-1)
result = {
'guarantee_limit': limit.strftime('%Y-%m-%d'),
}
return { 'value' : result }
if move_id:
move = self.pool.get('stock.move').browse(cr, uid, move_id)
product = self.pool.get('product.product').browse(cr, uid, [prod_id])[0]
date = move.date_planned#time.strftime('%Y-%m-%d')
limit = mx.DateTime.strptime(date, '%Y-%m-%d %H:%M:%S') + RelativeDateTime(months=product.warranty, days=-1)
result = {
'guarantee_limit': limit.strftime('%Y-%m-%d'),
}
return { 'value' : result }
return {}
def onchange_partner_id(self, cr, uid, ids, part):
if not part:
return {'value':{'address_id': False , 'pricelist_id': False }}
addr = self.pool.get('res.partner').address_get(cr, uid, [part])
return {'value':{'address_id': False , 'pricelist_id': False ,'partner_invoice_id' : False }}
addr = self.pool.get('res.partner').address_get(cr, uid, [part], ['delivery','invoice','default'])
pricelist = self.pool.get('res.partner').property_get(cr, uid,
part,property_pref=['property_product_pricelist']).get('property_product_pricelist',False)
return {'value':{'address_id': addr['default'], 'pricelist_id': pricelist}}
return {'value':{'address_id': addr['delivery'], 'partner_invoice_id' : addr['invoice'] , 'pricelist_id': pricelist}}
def onchange_lot_id(self, cr, uid, ids, lot ):
@@ -102,43 +105,71 @@ class mrp_repair(osv.osv):
return {'value':{'location_id': move.location_dest_id.id , 'move_id': move.id }}
else:
return {'value':{'location_id': False , 'move_id' : False}}
def action_cancel_draft(self, cr, uid, ids, *args):
if not len(ids):
return False
self.write(cr, uid, ids, {'state':'draft'})
wf_service = netsvc.LocalService("workflow")
for id in ids:
wf_service.trg_create(uid, 'mrp.repair', id, cr)
return True
mrp_repair()
class repair_operation(osv.osv):
_inherit = 'stock.move'
_name = 'repair.operation'
_description = 'Repair Operation'
_description = 'Repair Operations'
def _get_price(self, cr, uid, ids, name, arg, context={}):
res = {}
for val in self.browse(cr, uid, ids):
current_date = time.strftime('%Y-%m-%d')
if current_date < val.repair_id.guarantee_limit:
res[val.id] = 0.0
if current_date >= val.repair_id.guarantee_limit:
price = 0.0
pricelist = val.repair_id.pricelist_id.id
if pricelist:
price = self.pool.get('product.pricelist').price_get(cr, uid, [pricelist], val.product_id.id , 1.0, val.repair_id.partner_id.id)[pricelist]
if price is False:
warning={
'title':'No valid pricelist line found !',
'message':
"Couldn't find a pricelist line matching this product and quantity.\n"
"You have to change either the product, the quantity or the pricelist."
}
else:
res[val.id] = price
return res
_columns = {
'repair_id': fields.many2one('mrp.repair', 'Repair Order Ref', required=True, ondelete='cascade', select=True),
'name': fields.selection([('add','Add'),('remove','Remove')],'Type'),
'product_id': fields.many2one('product.product', 'Product', domain=[('sale_ok','=',True)]),
'type': fields.selection([('add','Add'),('remove','Remove')],'Type'),
'invoice': fields.boolean('Invoice'),
'price_unit': fields.float('Price'),
'product_qty': fields.float('Quantity', digits=(16,2)),
'product_uom': fields.many2one('product.uom', 'UoM'),
'location_id': fields.many2one('stock.location', 'Source Location', select=True),
'location_dest_id': fields.many2one('stock.location', 'Dest. Location', select=True),
'prodlot_id': fields.many2one('stock.production.lot', 'Lot Nb.', select=True),
'price_unit': fields.function(_get_price, method=True, store= True, type='float', string='Price'),
}
def product_id_change(self, cr, uid, ids, pricelist, product, uom=False, product_qty = 0,partner_id=False ):
if not product:
return {'value': {'product_qty' : 0.0, 'product_uom': False},'domain': {'product_uom': []}}
product_obj = self.pool.get('product.product').browse(cr, uid, product)
result = {}
warning = {}
if not uom:
result['product_uom'] = product_obj.uom_id.id
domain = {'product_uom':
[('category_id', '=', product_obj.uom_id.category_id.id)],}
if not pricelist:
warning={
'title':'No Pricelist !',
'message':
'You have to select a pricelist in the sale form !\n'
'You have to select a pricelist in the Repair form !\n'
'Please set one before choosing a product.'
}
else:
@@ -157,6 +188,21 @@ class repair_operation(osv.osv):
result.update({'price_unit': price})
return {'value': result , 'domain' :domain, 'warning':warning}
def onchange_operation_type(self, cr, uid, ids, type ):
if not type:
return {'value':{'location_id': False , 'location_dest_id' : False}}
stock_id = self.pool.get('stock.location').search(cr, uid, [('name','=','Stock')])[0]
produc_id = self.pool.get('stock.location').search(cr, uid, [('name','=','Default Production')])[0]
if type == 'add':
return {'value':{'location_id': stock_id , 'location_dest_id' : produc_id}}
if type == 'remove':
return {'value':{'location_id': produc_id , 'location_dest_id' : stock_id}}
_defaults = {
'name' : lambda *a: 'Repair Operation',
}
repair_operation()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
+17 -7
View File
@@ -2,6 +2,15 @@
<openerp>
<data>
<wizard
id="action_cancel_repair"
model="mrp.repair"
name="mrp.repair.cancel"
string="Cancel Repair"
menu = "False"
multi = "True"
/>
<record id="view_repair_order_form" model="ir.ui.view">
<field name="name">mrp.repair.form</field>
<field name="model">mrp.repair</field>
@@ -9,7 +18,7 @@
<field name="arch" type="xml">
<form string="Repairs order">
<group col="4" colspan="4">
<field name="product_id" select="1" on_change="onchange_product_id(product_id)"/>
<field name="product_id" select="1" on_change="onchange_product_id(product_id, move_id)"/>
<field name="prodlot_id" select="2" on_change="onchange_lot_id(prodlot_id)"/>
<field name="partner_id" select="2" on_change="onchange_partner_id(partner_id)" />
<field name="address_id"/>
@@ -17,14 +26,14 @@
<notebook colspan="4">
<page string="Products">
<field name="location_id"/>
<field name="move_id"/>
<field name="move_id" on_change="onchange_product_id(product_id, move_id)"/>
<field name="location_dest_id"/>
<field name="guarantee_limit"/>
<field name="guarantee_limit" />
<newline/>
<separator colspan="4" string="Operations"/>
<field colspan="4" mode="tree,form" name="operations" nolabel="1" widget="one2many_list">
<form string="Operations">
<field name="name"/>
<field name="type" on_change="onchange_operation_type(type)"/>
<field name="product_id" on_change="product_id_change(parent.pricelist_id,product_id,product_uom,product_qty, parent.partner_id)"/>
<field name="product_qty" string="Qty"/>
<field name="product_uom" string="UoM"/>
@@ -34,8 +43,8 @@
<field name="location_dest_id"/>
<field name="invoice"/>
</form>
<tree string="Operations lines">
<field name="name"/>
<tree string="Operations lines"> <!-- editable="bottom"> -->
<field name="type" on_change="onchange_operation_type(type)"/>
<field name="product_id"/>
<field name="product_qty" string="Qty"/>
<field name="product_uom" string="UoM"/>
@@ -51,8 +60,9 @@
<field name="state" select="2"/>
<button name="repair_confirm" states="draft" string="Confirm Repair"/>
<button name="repair_done" states="confirmed" string="Repair Done"/>
<button name="cancel" states="draft,confirmed,2binvoiced" string="Cancel Repair"/>
<button name="%(action_cancel_repair)d" states="draft,confirmed,2binvoiced" string="Cancel Repair" type="action"/>
<button name="make_invoice" states="2binvoiced" string="Make Invoice"/>
<button name="action_cancel_draft" states="cancel" string="Set to Draft" type="object"/>
</group>
</page>
<page string="Invoicing">