Changed model of Operations in mrp_repair, inherited stock.move, changes in view
bzr revid: ruchakpatel@gmail.com-20081020093240-mspqx7pwi9b5eojl
This commit is contained in:
+100
-37
@@ -38,6 +38,7 @@ class mrp_repair(osv.osv):
|
||||
_name = 'mrp.repair'
|
||||
_description = 'Repairs Order'
|
||||
_columns = {
|
||||
'name' : fields.char('Name',size=24),
|
||||
'product_id': fields.many2one('product.product', string='Product to Repair', required=True ,domain=[('sale_ok','=',True)]),
|
||||
'partner_id' : fields.many2one('res.partner', 'Partner', select=True),
|
||||
'address_id': fields.many2one('res.partner.address', 'Delivery Address', domain="[('partner_id','=',partner_id)]"),
|
||||
@@ -53,7 +54,7 @@ class mrp_repair(osv.osv):
|
||||
'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)
|
||||
'guarantee_limit': fields.date('Guarantee limit'),
|
||||
'operations' : fields.one2many('stock.move', 'repair_id', 'Operation Lines', readonly=True, states={'draft':[('readonly',False)]}),
|
||||
'operations' : fields.one2many('mrp.repair.lines', '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)]}, domain="[('partner_id','=',partner_id)]"),
|
||||
'invoice_method':fields.selection([
|
||||
@@ -131,12 +132,12 @@ class mrp_repair(osv.osv):
|
||||
company = self.pool.get('res.users').browse(cr, uid, uid).company_id
|
||||
for repair in self.browse(cr, uid, ids, context={}):
|
||||
if repair.location_dest_id:
|
||||
output_id = repair.location_dest_id
|
||||
output_id = repair.location_dest_id.id
|
||||
for line in repair.operations:
|
||||
proc_id=False
|
||||
date_planned = time.strftime('%Y-%m-%d %H:%M:%S')
|
||||
if line.product_id and line.product_id.product_tmpl_id.type in ('product', 'consu'):
|
||||
location_id = line.location_id
|
||||
location_id = line.location_id.id
|
||||
if not picking_id:
|
||||
picking_id = self.pool.get('stock.picking').create(cr, uid, {
|
||||
'origin': repair.product_id.code, # + (repair.partner_id and repair.partner_id.name) or ' ',
|
||||
@@ -147,21 +148,40 @@ class mrp_repair(osv.osv):
|
||||
'note': repair.internal_notes,
|
||||
'invoice_state': 'none',
|
||||
})
|
||||
operation = self.pool.get('stock.move')
|
||||
operation.write(cr, uid, line.id,{'picking_id' : picking_id} )
|
||||
proc_id = self.pool.get('mrp.procurement').create(cr, uid, {
|
||||
'name': repair.name or 'Repair',
|
||||
'origin': repair.name,
|
||||
'date_planned': date_planned,
|
||||
'product_id': line.product_id.id,
|
||||
'product_qty': line.product_qty,
|
||||
'product_uom': line.product_uom.id,
|
||||
'location_id': repair.location_id.id,
|
||||
'procure_method': 'make_to_stock' ,# NEEDS TO BE CHANGED
|
||||
'move_id': line.id,
|
||||
})
|
||||
wf_service = netsvc.LocalService("workflow")
|
||||
wf_service.trg_validate(uid, 'mrp.procurement', proc_id, 'button_confirm', cr)
|
||||
# operation = self.pool.get('stock.move')
|
||||
# operation.write(cr, uid, line.id,{'picking_id' : picking_id} )
|
||||
vals = {
|
||||
'name': line.product_id.name[:64],
|
||||
'picking_id': picking_id,
|
||||
'product_id': line.product_id.id,
|
||||
'date_planned': date_planned,
|
||||
'product_qty': line.product_uom_qty,
|
||||
'product_uom': line.product_uom.id,
|
||||
'product_uos_qty': line.product_uos_qty,
|
||||
'product_uos': (line.product_uos and line.product_uos.id)\
|
||||
or line.product_uom.id,
|
||||
'product_packaging' : line.product_packaging.id,
|
||||
'address_id': repair.address_id.id,
|
||||
'location_id': location_id,
|
||||
'location_dest_id': output_id,
|
||||
'tracking_id': False,
|
||||
'state': 'draft',
|
||||
'note': line.notes,
|
||||
}
|
||||
move_id = self.pool.get('stock.move').create(cr, uid, vals)
|
||||
proc_id = self.pool.get('mrp.procurement').create(cr, uid, {
|
||||
'name': repair.name or 'Repair',
|
||||
'origin': repair.name,
|
||||
'date_planned': date_planned,
|
||||
'product_id': line.product_id.id,
|
||||
'product_qty': line.product_uom_qty,
|
||||
'product_uom': line.product_uom.id,
|
||||
'location_id': repair.location_id.id,
|
||||
'procure_method': 'make_to_stock' ,# NEEDS TO BE CHANGED
|
||||
'move_id': line.id,
|
||||
})
|
||||
wf_service = netsvc.LocalService("workflow")
|
||||
wf_service.trg_validate(uid, 'mrp.procurement', proc_id, 'button_confirm', cr)
|
||||
|
||||
elif line.product_id and line.product_id.product_tmpl_id.type=='service':
|
||||
proc_id = self.pool.get('mrp.procurement').create(cr, uid, {
|
||||
@@ -169,7 +189,7 @@ class mrp_repair(osv.osv):
|
||||
'origin': repair.name,
|
||||
'date_planned': date_planned,
|
||||
'product_id': line.product_id.id,
|
||||
'product_qty': line.product_qty,
|
||||
'product_qty': line.product_uom_qty,
|
||||
'product_uom': line.product_uom.id,
|
||||
'location_id': repair.location_id.id,
|
||||
'procure_method': 'make_to_stock' ,# NEEDS TO BE CHANGED
|
||||
@@ -193,11 +213,10 @@ mrp_repair()
|
||||
|
||||
|
||||
class repair_operation(osv.osv):
|
||||
_inherit = 'stock.move'
|
||||
# _name = 'repair.operation'
|
||||
_description = 'Repair Operations'
|
||||
_name = 'mrp.repair.lines'
|
||||
_description = 'Repair Operations'
|
||||
|
||||
def _get_price(self, cr, uid, ids, name, arg, context={}):
|
||||
def _get_price(self, cr, uid, ids, name, arg, context={}):
|
||||
res = {}
|
||||
for val in self.browse(cr, uid, ids):
|
||||
if val.repair_id:
|
||||
@@ -220,18 +239,53 @@ class repair_operation(osv.osv):
|
||||
res[val.id] = price
|
||||
return res
|
||||
|
||||
|
||||
_columns = {
|
||||
'repair_id': fields.many2one('mrp.repair', 'Repair Order Ref',ondelete='cascade', select=True),
|
||||
'type': fields.selection([('add','Add'),('remove','Remove')],'Type'),
|
||||
'invoice': fields.boolean('Invoice'),
|
||||
'repair_price': fields.function(_get_price, method=True, store= True, type='float', string='Price'),
|
||||
def _amount_line_net(self, cr, uid, ids, field_name, arg, context):
|
||||
res = {}
|
||||
for line in self.browse(cr, uid, ids):
|
||||
res[line.id] = line.price_unit * (1 - (line.discount or 0.0) / 100.0)
|
||||
return res
|
||||
|
||||
def _amount_line(self, cr, uid, ids, field_name, arg, context):
|
||||
res = {}
|
||||
cur_obj=self.pool.get('res.currency')
|
||||
for line in self.browse(cr, uid, ids):
|
||||
res[line.id] = line.price_unit * line.product_uom_qty * (1 - (line.discount or 0.0) / 100.0)
|
||||
cur = line.repair_id.pricelist_id.currency_id
|
||||
res[line.id] = cur_obj.round(cr, uid, cur, res[line.id])
|
||||
return res
|
||||
_columns = {
|
||||
'name' : fields.char('Name',size=24),
|
||||
'repair_id': fields.many2one('mrp.repair', 'Repair Order Ref',ondelete='cascade', select=True),
|
||||
'type': fields.selection([('add','Add'),('remove','Remove')],'Type'),
|
||||
'invoice': fields.boolean('Invoice'),
|
||||
'delay': fields.float('Delivery Delay', required=True),
|
||||
'product_id': fields.many2one('product.product', 'Product', domain=[('sale_ok','=',True)], required=True),
|
||||
'invoiced': fields.boolean('Invoiced'),
|
||||
'procurement_id': fields.many2one('mrp.procurement', 'Procurement'),
|
||||
'price_unit': fields.function(_get_price, method=True, store= True, type='float', string='Price'),
|
||||
'price_net': fields.function(_amount_line_net, method=True, string='Net Price'),
|
||||
'price_subtotal': fields.function(_amount_line, method=True, string='Subtotal'),
|
||||
'tax_id': fields.many2many('account.tax', 'sale_order_tax', 'order_line_id', 'tax_id', 'Taxes'),
|
||||
'property_ids': fields.many2many('mrp.property', 'sale_order_line_property_rel', 'order_id', 'property_id', 'Properties'),
|
||||
'address_allotment_id' : fields.many2one('res.partner.address', 'Allotment Partner'),
|
||||
'product_uom_qty': fields.float('Quantity (UoM)', digits=(16,2), required=True),
|
||||
'product_uom': fields.many2one('product.uom', 'Product UoM', required=True),
|
||||
'product_uos_qty': fields.float('Quantity (UOS)'),
|
||||
'product_uos': fields.many2one('product.uom', 'Product UOS'),
|
||||
'product_packaging': fields.many2one('product.packaging', 'Packaging'),
|
||||
'move_ids': fields.one2many('stock.move', 'sale_line_id', 'Inventory Moves', readonly=True),
|
||||
'discount': fields.float('Discount (%)', digits=(16,2)),
|
||||
'notes': fields.text('Notes'),
|
||||
'th_weight' : fields.float('Weight'),
|
||||
'location_id': fields.many2one('stock.location', 'Source Location', required=True, select=True),
|
||||
'location_dest_id': fields.many2one('stock.location', 'Dest. Location', required=True, select=True),
|
||||
'state': fields.selection([('draft','Draft'),('confirmed','Confirmed'),('done','Done'),('cancel','Canceled')], 'Status', required=True, readonly=True),
|
||||
}
|
||||
|
||||
|
||||
def product_id_change(self, cr, uid, ids, pricelist, product, uom=False, product_qty = 0,partner_id=False ):
|
||||
def product_id_change(self, cr, uid, ids, pricelist, product, uom=False, product_uom_qty = 0,partner_id=False ):
|
||||
if not product:
|
||||
return {'value': {'product_qty' : 0.0, 'product_uom': False},'domain': {'product_uom': []}}
|
||||
return {'value': {'product_uom_qty' : 0.0, 'product_uom': False},'domain': {'product_uom': []}}
|
||||
product_obj = self.pool.get('product.product').browse(cr, uid, product)
|
||||
result = {}
|
||||
warning = {}
|
||||
@@ -249,7 +303,7 @@ class repair_operation(osv.osv):
|
||||
}
|
||||
else:
|
||||
price = self.pool.get('product.pricelist').price_get(cr, uid, [pricelist],
|
||||
product, product_qty or 1.0, partner_id, {
|
||||
product, product_uom_qty or 1.0, partner_id, {
|
||||
'uom': uom,
|
||||
})[pricelist]
|
||||
if price is False:
|
||||
@@ -260,12 +314,12 @@ class repair_operation(osv.osv):
|
||||
"You have to change either the product, the quantity or the pricelist."
|
||||
}
|
||||
else:
|
||||
result.update({'repair_price': price})
|
||||
result.update({'price_unit': price})
|
||||
|
||||
return {'value': result , 'domain' :domain, 'warning':warning}
|
||||
|
||||
|
||||
def onchange_operation_type(self, cr, uid, ids, type ):
|
||||
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]
|
||||
@@ -275,9 +329,11 @@ class repair_operation(osv.osv):
|
||||
if type == 'remove':
|
||||
return {'value':{'location_id': produc_id , 'location_dest_id' : stock_id}}
|
||||
|
||||
_defaults = {
|
||||
_defaults = {
|
||||
'name' : lambda *a: 'Repair Operation',
|
||||
'state': lambda *a: 'draft',
|
||||
}
|
||||
|
||||
repair_operation()
|
||||
|
||||
class mrp_repair_fee(osv.osv):
|
||||
@@ -287,14 +343,14 @@ class mrp_repair_fee(osv.osv):
|
||||
'repair_id': fields.many2one('mrp.repair', 'Repair Order Ref', required=True, ondelete='cascade', select=True),
|
||||
'name': fields.char('Description', size=8, required=True, select=True),
|
||||
'product_id': fields.many2one('product.product', 'Product', required=True),
|
||||
'product_qty': fields.float('Quantity', digits=(16,2), required=True),
|
||||
'product_uom_qty': fields.float('Quantity', digits=(16,2), required=True),
|
||||
'price_unit': fields.float('Unit Price', required=True),
|
||||
'product_uom': fields.many2one('product.uom', 'Product UoM', required=True),
|
||||
}
|
||||
|
||||
def product_id_change(self, cr, uid, ids, product, uom=False):
|
||||
if not product:
|
||||
return {'value': {'product_qty' : 0.0, 'product_uom': False},'domain': {'product_uom': []}}
|
||||
return {'value': {'product_uom_qty' : 0.0, 'product_uom': False},'domain': {'product_uom': []}}
|
||||
|
||||
product_obj = self.pool.get('product.product').browse(cr, uid, product)
|
||||
result = {}
|
||||
@@ -306,4 +362,11 @@ class mrp_repair_fee(osv.osv):
|
||||
|
||||
mrp_repair_fee()
|
||||
|
||||
|
||||
class stock_move(osv.osv):
|
||||
_inherit = "stock.move"
|
||||
_columns = {
|
||||
'state': fields.selection([('draft','Draft'),('waiting','Waiting'),('confirmed','Confirmed'),('assigned','Assigned'),('done','Done'),('cancel','cancel'),('in_repair','In Repair')], 'Status',),# readonly=True, select=True),
|
||||
'repair_ids' : fields.one2many('mrp.repair', 'move_id', 'Repairs'),
|
||||
}
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
<field name="arch" type="xml">
|
||||
<form string="Repairs order">
|
||||
<group col="4" colspan="4">
|
||||
<field name="name"/>
|
||||
<newline/>
|
||||
<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)" />
|
||||
@@ -34,24 +36,26 @@
|
||||
<field colspan="4" mode="tree,form" name="operations" nolabel="1" widget="one2many_list">
|
||||
<form string="Operations">
|
||||
<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_id" on_change="product_id_change(parent.pricelist_id,product_id,product_uom,product_uom_qty, parent.partner_id)"/>
|
||||
<field name="product_uom_qty" string="Qty"/>
|
||||
<field name="product_uom" string="UoM"/>
|
||||
<field name="repair_price"/>
|
||||
<field name="prodlot_id"/>
|
||||
<field name="price_unit"/>
|
||||
<field name="discount"/>
|
||||
<field name="price_subtotal"/>
|
||||
<field name="delay"/>
|
||||
<field name="location_id"/>
|
||||
<field name="location_dest_id"/>
|
||||
<field name="invoice"/>
|
||||
<field name="state"/>
|
||||
</form>
|
||||
<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="type" on_change="onchange_operation_type(type)"/>
|
||||
<field name="product_id" on_change="product_id_change(parent.pricelist_id,product_id,product_uom,product_uom_qty, parent.partner_id)"/>
|
||||
<field name="product_uom_qty" string="Qty"/>
|
||||
<field name="product_uom" string="UoM"/>
|
||||
<field name="repair_price"/>
|
||||
<field name="prodlot_id"/>
|
||||
<field name="location_id"/>
|
||||
<field name="location_dest_id"/>
|
||||
<field name="discount"/>
|
||||
<field name="price_unit"/>
|
||||
<field name="price_net"/>
|
||||
<field name="price_subtotal"/>
|
||||
<field name="invoice"/>
|
||||
</tree>
|
||||
</field>
|
||||
@@ -74,13 +78,13 @@
|
||||
<field colspan="4" mode="tree,form" name="fees_lines" nolabel="1" widget="one2many_list">
|
||||
<form string="Fees Line">
|
||||
<field name="product_id" on_change="product_id_change(product_id,product_uom)" />
|
||||
<field name="product_qty" string="Qty"/>
|
||||
<field name="product_uom_qty" string="Qty"/>
|
||||
<field name="product_uom" string="UoM" /> <!--on_change="product_id_change(product_id,product_uom)" /> -->
|
||||
<field name="price_unit"/>
|
||||
</form>
|
||||
<tree string="Fees lines"> <!-- editable="bottom"> -->
|
||||
<field name="product_id"/>
|
||||
<field name="product_qty" string="Qty"/>
|
||||
<field name="product_uom_qty" string="Qty"/>
|
||||
<field name="product_uom" string="UoM"/>
|
||||
<field name="price_unit"/>
|
||||
</tree>
|
||||
|
||||
Reference in New Issue
Block a user