[IMP] mrp_repair: usability and refactoring

bzr revid: qdp-launchpad@openerp.com-20140127163339-mncm92w3cilfzyxy
This commit is contained in:
Quentin (OpenERP) 2014-01-27 17:33:39 +01:00
parent e1ddf7b056
commit f62c70832e
2 changed files with 26 additions and 14 deletions

View File

@ -152,8 +152,8 @@ class mrp_repair(osv.osv):
("after_repair","After Repair")
], "Invoice Method",
select=True, required=True, states={'draft':[('readonly',False)]}, readonly=True, help='Selecting \'Before Repair\' or \'After Repair\' will allow you to generate invoice before or after the repair is done respectively. \'No invoice\' means you don\'t want to generate invoice for this repair order.'),
'invoice_id': fields.many2one('account.invoice', 'Invoice', readonly=True),
'move_id': fields.many2one('stock.move', 'Move',readonly=True, help="Move created by the repair order"),
'invoice_id': fields.many2one('account.invoice', 'Invoice', readonly=True, track_visibility="onchange"),
'move_id': fields.many2one('stock.move', 'Move',readonly=True, help="Move created by the repair order", track_visibility="onchange"),
'fees_lines': fields.one2many('mrp.repair.fee', 'repair_id', 'Fees Lines', readonly=True, states={'draft':[('readonly',False)]}),
'internal_notes': fields.text('Internal Notes'),
'quotation_notes': fields.text('Quotation Notes'),
@ -177,15 +177,24 @@ class mrp_repair(osv.osv):
}),
}
def _default_stock_location(self, cr, uid, context=None):
try:
warehouse = self.pool.get('ir.model.data').get_object(cr, uid, 'stock', 'warehouse0')
return warehouse.lot_stock_id.id
except:
return False
_defaults = {
'state': lambda *a: 'draft',
'name': lambda obj, cr, uid, context: obj.pool.get('ir.sequence').get(cr, uid, 'mrp.repair'),
'invoice_method': lambda *a: 'none',
'company_id': lambda self, cr, uid, context: self.pool.get('res.company')._company_default_get(cr, uid, 'mrp.repair', context=context),
'pricelist_id': lambda self, cr, uid,context : self.pool.get('product.pricelist').search(cr, uid, [('type','=','sale')])[0],
'pricelist_id': lambda self, cr, uid, context: self.pool.get('product.pricelist').search(cr, uid, [('type', '=', 'sale')])[0],
'product_qty': 1.0,
'location_id': _default_stock_location,
}
_sql_constraints = [
('name', 'unique (name)', 'The name of the Repair Order must be unique!'),
]
@ -467,6 +476,7 @@ class mrp_repair(osv.osv):
move_obj = self.pool.get('stock.move')
repair_line_obj = self.pool.get('mrp.repair.line')
for repair in self.browse(cr, uid, ids, context=context):
move_ids = []
for move in repair.operations:
move_id = move_obj.create(cr, uid, {
'name': move.name,
@ -479,7 +489,7 @@ class mrp_repair(osv.osv):
'location_dest_id': move.location_dest_id.id,
'state': 'assigned',
})
move_obj.action_done(cr, uid, [move_id], context=context)
move_ids.append(move_id)
repair_line_obj.write(cr, uid, [move.id], {'move_id': move_id, 'state': 'done'}, context=context)
move_id = move_obj.create(cr, uid, {
'name': repair.name,
@ -491,7 +501,8 @@ class mrp_repair(osv.osv):
'location_dest_id': repair.location_dest_id.id,
'restrict_lot_id': repair.lot_id.id,
})
move_obj.action_done(cr, uid, [move_id], context=context)
move_ids.append(move_id)
move_obj.action_done(cr, uid, move_ids, context=context)
self.write(cr, uid, [repair.id], {'state': 'done', 'move_id': move_id}, context=context)
res[repair.id] = move_id
return res

View File

@ -49,15 +49,15 @@
<field name="product_qty" class="oe_inline"/>
<field name="product_uom" groups="product.group_uom" on_change="onchange_product_uom(product_id, product_uom)" class="oe_inline"/>
</div>
<field name="lot_id" domain="[('product_id','=',product_id]" context="{'default_product_id': product_id}" groups="stock.track_grouping_lot"/>
<field name="lot_id" domain="[('product_id', '=', product_id)]" context="{'default_product_id': product_id}" groups="stock.group_tracking_lot"/>
<field name="partner_id" on_change="onchange_partner_id(partner_id,address_id)" attrs="{'required':[('invoice_method','!=','none')]}"/>
<field name="address_id" groups="sale.group_delivery_invoice_address"/>
<field name="location_id" on_change="onchange_location_id(location_id)" groups="stock.group_locations"/>
</group>
<group>
<field name="location_id" on_change="onchange_location_id(location_id)" groups="stock.group_locations" domain="[('usage', 'in', ('internal', 'customer'))]"/>
<field name="location_dest_id" groups="stock.group_locations" domain="[('usage', 'in', ('internal', 'customer'))]"/>
<field name="company_id" groups="base.group_multi_company" widget="selection"/>
<field name="guarantee_limit"/>
<field name="repaired" groups="base.group_no_one"/>
<field name="invoiced" groups="base.group_no_one"/>
</group>
</group>
<notebook>
@ -122,13 +122,15 @@
<page string="Invoicing">
<group col="4">
<field name="invoice_method"/>
<field name="invoice_id" context="{'form_view_ref': 'account.invoice_form'}"/>
<field name="partner_invoice_id" attrs="{'readonly':[('invoice_method','=', 'none')],'required':[('invoice_method','!=','none')]}" groups="sale.group_delivery_invoice_address"/>
<field
name="pricelist_id" groups="product.group_sale_pricelist" context="{'product_id':product_id}"
attrs="{'readonly':[('invoice_method','=', 'none')]}"/>
</group>
<!-- <field name="invoice_id"/> -->
<field name="fees_lines">
<separator string="Fees Lines"/>
<field name="fees_lines" attrs="{'readonly': [('invoice_method','=', 'none')]}">
<form string="Fees" version="7.0">
<label for="name" class="oe_edit_only"/>
<h2>
@ -170,15 +172,14 @@
</tree>
</field>
</page>
<page string="Extra Info">
<page string="Extra Info" groups="base.group_no_one">
<group>
<group>
<field name="move_id"/>
<field name="invoice_id" context="{'form_view_ref': 'account.invoice_form'}"/>
<field name="company_id" groups="base.group_multi_company" widget="selection"/>
</group>
<group>
<field name="location_dest_id" groups="stock.group_locations"/>
<field name="repaired"/>
<field name="invoiced"/>
</group>
</group>
</page>