[merge] mrp repair improvements

bzr revid: fp@openerp.com-20120806192536-dhv3xz10xemy4zlb
This commit is contained in:
Fabien Pinckaers 2012-08-06 21:25:36 +02:00
commit f814648e4b
2 changed files with 139 additions and 71 deletions

View File

@ -28,6 +28,7 @@ import decimal_precision as dp
class mrp_repair(osv.osv):
_name = 'mrp.repair'
_inherit = 'mail.thread'
_description = 'Repair Order'
def _amount_untaxed(self, cr, uid, ids, field_name, arg, context=None):
@ -119,16 +120,16 @@ class mrp_repair(osv.osv):
'partner_id' : fields.many2one('res.partner', 'Partner', select=True, help='Choose partner for whom the order will be invoiced and delivered.'),
'address_id': fields.many2one('res.partner', 'Delivery Address', domain="[('parent_id','=',partner_id)]"),
'default_address_id': fields.function(_get_default_address, type="many2one", relation="res.partner"),
'prodlot_id': fields.many2one('stock.production.lot', 'Lot Number', select=True, domain="[('product_id','=',product_id)]"),
'prodlot_id': fields.many2one('stock.production.lot', 'Lot Number', select=True, states={'draft':[('readonly',False)]},domain="[('product_id','=',product_id)]"),
'state': fields.selection([
('draft','Quotation'),
('cancel','Cancel'),
('cancel','Cancelled'),
('confirmed','Confirmed'),
('under_repair','Under Repair'),
('ready','Ready to Repair'),
('2binvoiced','To be Invoiced'),
('invoice_except','Invoice Exception'),
('done','Done')
('done','Repaired')
], 'Status', readonly=True,
help=' * The \'Draft\' state is used when a user is encoding a new and unconfirmed repair order. \
\n* The \'Confirmed\' state is used when a user confirms the repair order. \
@ -219,7 +220,7 @@ class mrp_repair(osv.osv):
@return: Dictionary of values.
"""
data = {}
data['value'] = {}
data['value'] = {'guarantee_limit': False, 'location_id': False, 'prodlot_id': False, 'partner_id': False}
if not prod_id:
return data
if move_id:
@ -229,6 +230,7 @@ class mrp_repair(osv.osv):
data['value']['guarantee_limit'] = limit.strftime('%Y-%m-%d')
data['value']['location_id'] = move.location_dest_id.id
data['value']['location_dest_id'] = move.location_dest_id.id
data['value']['prodlot_id'] = move.prodlot_id.id
if move.partner_id:
data['value']['partner_id'] = move.partner_id.id
else:
@ -329,12 +331,11 @@ class mrp_repair(osv.osv):
self.write(cr, uid, [o.id], {'state': '2binvoiced'})
else:
self.write(cr, uid, [o.id], {'state': 'confirmed'})
if not o.operations:
raise osv.except_osv(_('Error !'),_('You cannot confirm a repair order which has no line.'))
for line in o.operations:
if line.product_id.track_production and not line.prodlot_id:
raise osv.except_osv(_('Warning'), _("Serial number is required for operation line with product '%s'") % (line.product_id.name))
mrp_line_obj.write(cr, uid, [l.id for l in o.operations], {'state': 'confirmed'})
self.set_confirm_send_note(cr, uid, ids)
return True
def action_cancel(self, cr, uid, ids, context=None):
@ -343,12 +344,18 @@ class mrp_repair(osv.osv):
"""
mrp_line_obj = self.pool.get('mrp.repair.line')
for repair in self.browse(cr, uid, ids, context=context):
mrp_line_obj.write(cr, uid, [l.id for l in repair.operations], {'state': 'cancel'}, context=context)
if not repair.invoiced:
mrp_line_obj.write(cr, uid, [l.id for l in repair.operations], {'state': 'cancel'}, context=context)
else:
raise osv.except_osv(_('Warning!'),_('Repair order is already invoiced.'))
self.write(cr,uid,ids,{'state':'cancel'})
self.set_cancel_send_note(cr, uid, ids, context)
return True
def wkf_invoice_create(self, cr, uid, ids, *args):
return self.action_invoice_create(cr, uid, ids)
self.action_invoice_create(cr, uid, ids)
self.set_toinvoiced_send_note(cr, uid, ids)
return True
def action_invoice_create(self, cr, uid, ids, group=False, context=None):
""" Creates invoice(s) for repair order.
@ -463,6 +470,7 @@ class mrp_repair(osv.osv):
self.pool.get('mrp.repair.line').write(cr, uid, [l.id for
l in repair.operations], {'state': 'confirmed'}, context=context)
self.write(cr, uid, [repair.id], {'state': 'ready'})
self.set_ready_send_note(cr, uid, ids, context)
return True
def action_repair_start(self, cr, uid, ids, context=None):
@ -474,6 +482,7 @@ class mrp_repair(osv.osv):
repair_line.write(cr, uid, [l.id for
l in repair.operations], {'state': 'confirmed'}, context=context)
repair.write({'state': 'under_repair'})
self.set_start_send_note(cr, uid, ids, context)
return True
def action_repair_end(self, cr, uid, ids, context=None):
@ -538,7 +547,6 @@ class mrp_repair(osv.osv):
'name': repair.name,
'picking_id': picking,
'product_id': repair.product_id.id,
'product_qty': move.product_uom_qty or 1.0,
'product_uom': repair.product_id.uom_id.id,
'prodlot_id': repair.prodlot_id and repair.prodlot_id.id or False,
'partner_id': repair.address_id and repair.address_id.id or False,
@ -552,8 +560,52 @@ class mrp_repair(osv.osv):
res[repair.id] = picking
else:
self.write(cr, uid, [repair.id], {'state': 'done'})
self.set_done_send_note(cr, uid, [repair.id], context)
return res
def create(self, cr, uid, vals, context=None):
repair_id = super(mrp_repair, self).create(cr, uid, vals, context=context)
self.create_send_note(cr, uid, [repair_id], context=context)
return repair_id
def create_send_note(self, cr, uid, ids, context=None):
for repair in self.browse(cr, uid, ids, context):
message = _("Repair Order for <em>%s</em> has been <b>created</b>." % (repair.product_id.name))
self.message_append_note(cr, uid, [repair.id], body=message, context=context)
return True
def set_start_send_note(self, cr, uid, ids, context=None):
for repair in self.browse(cr, uid, ids, context):
message = _("Repair Order for <em>%s</em> has been <b>started</b>." % (repair.product_id.name))
self.message_append_note(cr, uid, [repair.id], body=message, context=context)
return True
def set_toinvoiced_send_note(self, cr, uid, ids, context=None):
for repair in self.browse(cr, uid, ids, context):
message = _("Draft Invoice of %s %s <b>waiting for validation</b>.") % (repair.invoice_id.amount_total, repair.invoice_id.currency_id.symbol)
self.message_append_note(cr, uid, [repair.id], body=message, context=context)
return True
def set_confirm_send_note(self, cr, uid, ids, context=None):
for repair in self.browse(cr, uid, ids, context):
message = _( "Repair Order for <em>%s</em> has been <b>accepted</b>." % (repair.product_id.name))
self.message_append_note(cr, uid, [repair.id], body=message, context=context)
return True
def set_cancel_send_note(self, cr, uid, ids, context=None):
message = _("Repair has been <b>cancelled</b>.")
self.message_append_note(cr, uid, ids, body=message, context=context)
return True
def set_ready_send_note(self, cr, uid, ids, context=None):
message = _("Repair Order is now <b>ready</b> to repair.")
self.message_append_note(cr, uid, ids, body=message, context=context)
return True
def set_done_send_note(self, cr, uid, ids, context=None):
message = _("Repair Order is <b>closed</b>.")
self.message_append_note(cr, uid, ids, body=message, context=context)
return True
mrp_repair()
@ -643,7 +695,7 @@ class mrp_repair_line(osv.osv, ProductChangeMixin):
'price_unit': fields.float('Unit Price', required=True, digits_compute= dp.get_precision('Sale Price')),
'price_subtotal': fields.function(_amount_line, string='Subtotal',digits_compute= dp.get_precision('Sale Price')),
'tax_id': fields.many2many('account.tax', 'repair_operation_line_tax', 'repair_operation_line_id', 'tax_id', 'Taxes'),
'product_uom_qty': fields.float('Quantity (Unit of Measure)', digits=(16,2), required=True),
'product_uom_qty': fields.float('Quantity', digits_compute= dp.get_precision('Product UoS'), required=True),
'product_uom': fields.many2one('product.uom', 'Product Unit of Measure', required=True),
'prodlot_id': fields.many2one('stock.production.lot', 'Lot Number',domain="[('product_id','=',product_id)]"),
'invoice_line_id': fields.many2one('account.invoice.line', 'Invoice Line', readonly=True),
@ -654,7 +706,7 @@ class mrp_repair_line(osv.osv, ProductChangeMixin):
('draft','Draft'),
('confirmed','Confirmed'),
('done','Done'),
('cancel','Canceled')], 'Status', required=True, readonly=True,
('cancel','Cancelled')], 'Status', required=True, readonly=True,
help=' * The \'Draft\' state is set automatically as draft when repair order in draft state. \
\n* The \'Confirmed\' state is set automatically as confirm when repair order in confirm state. \
\n* The \'Done\' state is set automatically when repair order is completed.\

View File

@ -13,8 +13,8 @@
<field name="move_id"/>
<field name="partner_id"/>
<field name="address_id"/>
<field name="location_id"/>
<field name="location_dest_id"/>
<field name="location_id" groups="stock.group_locations"/>
<field name="location_dest_id" groups="stock.group_locations"/>
<field name="company_id" groups="base.group_multi_company" invisible="1"/>
<field name="guarantee_limit"/>
<field name="state"/>
@ -36,15 +36,15 @@
<button name="action_invoice_create" states="2binvoiced" string="Make Invoice" class="oe_highlight"/>
<button name="invoice_recreate" states="invoice_except" string="Recreate Invoice"/>
<button name="invoice_corrected" states="invoice_except" string="Invoice Corrected"/>
<button name="%(action_cancel_repair)d" states="confirmed,2binvoiced,ready,under_repair" string="Cancel Repair" type="action"/>
<button name="%(action_cancel_repair)d" states="invoice_except" string="Cancel Repair" type="action"/>
<button name="action_cancel" states="confirmed,2binvoiced,ready,under_repair" string="Cancel Repair" type="object" attrs="{'invisible':[('invoice_method','!=','none')]}"/>
<button name="action_cancel" states="invoice_except" string="Cancel Repair" type="object" attrs="{'invisible':[('invoice_method','!=','none')]}"/>
<button name="cancel" states="draft" string="Cancel Repair"/>
<field name="state" widget="statusbar" statusbar_visible="draft,confirmed,ready" />
<field name="state" widget="statusbar" statusbar_visible="draft,confirmed,done"/>
</header>
<sheet string="Repairs order">
<label for="product_id" class="oe_edit_only"/>
<h1>
<field name="product_id" on_change="onchange_product_id(product_id)"/>
<field name="product_id" on_change="onchange_product_id(product_id)" domain="[('type','!=','service')]"/>
</h1>
<label for="name" class="oe_edit_only"/>
<h2>
@ -52,16 +52,17 @@
</h2>
<group>
<group>
<field name="partner_id" on_change="onchange_partner_id(partner_id,address_id)"/>
<field name="address_id" attrs="{'readonly':[('deliver_bool','=', False)]}"/>
<field name="prodlot_id" on_change="onchange_lot_id(prodlot_id,product_id)"/>
<field name="move_id" on_change="onchange_move_id(product_id, move_id)"/>
<field name="partner_id" on_change="onchange_partner_id(partner_id,address_id)" attrs="{'required':[('invoice_method','!=','none')]}"/>
<field name="address_id" attrs="{'readonly':[('deliver_bool','=', False)]}" groups="sale.group_delivery_invoice_address"/>
<field name="move_id" on_change="onchange_move_id(product_id, move_id)" context="{'default_product_id':product_id}"/>
<field name="location_id" attrs="{'readonly':[('deliver_bool','=', False)], 'required':[('deliver_bool','=', True)]}" groups="stock.group_locations"/>
<field name="prodlot_id" on_change="onchange_lot_id(prodlot_id,product_id)" groups="stock.group_production_lot" string="Serial Number"/>
</group>
<group>
<field name="guarantee_limit"/>
<field name="deliver_bool"/>
<field name="repaired"/>
<field name="invoiced"/>
<field name="guarantee_limit" />
<field name="repaired" groups="base.group_no_one"/>
<field name="invoiced" groups="base.group_no_one"/>
</group>
</group>
<notebook>
@ -71,22 +72,23 @@
<notebook>
<page string="Repair Line">
<group col="4">
<field name="name" colspan="4"/>
<field name="name"/>
<field name="product_id" on_change="product_id_change(parent.pricelist_id,product_id,product_uom,product_uom_qty, parent.partner_id)"/>
<field name='prodlot_id'/>
<field name="product_uom_qty" string="Qty" />
<field name="product_uom" string="Unit of Measure"/>
<label for="product_uom_qty"/>
<div>
<field name="product_uom_qty" class="oe_inline"/>
<field name="product_uom" class="oe_inline" groups="product.group_uom"/>
</div>
<field name="price_unit"/>
<field name="price_subtotal"/>
<field name="location_id"/>
<field name="location_dest_id"/>
<field name="type" on_change="onchange_operation_type(type,parent.guarantee_limit,parent.company_id,context)"/>
<field name="to_invoice"/>
<field name="tax_id" widget="many2many_tags" domain="[('parent_id','=',False),('type_tax_use','&lt;&gt;','purchase')]"/>
<field name="invoiced"/>
<field name='prodlot_id' groups="stock.group_production_lot" string="Serial Number"/>
<field name="location_id" groups="stock.group_locations"/>
<field name="location_dest_id" groups="stock.group_locations"/>
</group>
<separator colspan="4" string="States"/>
<field name="state"/>
</page>
<page string="History">
<group>
@ -100,60 +102,70 @@
<field name="type" on_change="onchange_operation_type(type,parent.guarantee_limit,parent.company_id,context)"/>
<field name="product_id" on_change="product_id_change(parent.pricelist_id,product_id,product_uom,product_uom_qty, parent.partner_id)"/>
<field name='name'/>
<field name="prodlot_id" />
<field name="location_id"/>
<field name="location_dest_id"/>
<field name="product_uom_qty" string="Qty"/>
<field name="product_uom" string="Unit of Measure"/>
<field name="prodlot_id" groups="stock.group_production_lot" string="Serial Number"/>
<field name="location_id" groups="stock.group_locations"/>
<field name="location_dest_id" groups="stock.group_locations"/>
<field name="product_uom_qty" string="Quantity"/>
<field name="product_uom" string="Unit of Measure" groups="product.group_uom"/>
<field name="price_unit"/>
<field name="tax_id"/>
<field name="tax_id" widget="many2many_tags"/>
<field name="to_invoice"/>
<field name="price_subtotal"/>
</tree>
</field>
<group class="oe_subtotal_footer">
<group class="oe_subtotal_footer oe_right">
<field name="amount_untaxed" sum="Untaxed amount"/>
<field name="amount_tax"/>
<field name="amount_total" sum="Total amount"/>
<button name="button_dummy" states="draft" string="Compute" type="object" icon="terp-stock_format-scientific"/>
<field name="amount_total" sum="Total amount" class="oe_subtotal_footer_separator"/>
</group>
<button name="button_dummy" states="draft" string="Compute" type="object" icon="terp-stock_format-scientific"/>
<div class="oe_clear"/>
</page>
<page string="Invoicing">
<group col="4">
<field name="invoice_method"/>
<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')]}"/>
<field name="partner_invoice_id" attrs="{'readonly':[('invoice_method','=', 'none')]}"/>
</group>
<!-- <field name="invoice_id"/> -->
<field name="fees_lines">
<form string="Fees" version="7.0">
<notebook>
<page string="Fees Line">
<group col="4">
<field name='name'/>
<field name="product_id" on_change="product_id_change(parent.pricelist_id,product_id,product_uom,product_uom_qty, parent.partner_id,parent.guarantee_limit)" colspan="4"/>
<field name="product_uom_qty" string="Qty"/>
<field name="product_uom" string="Unit of Measure" />
<field name="price_unit"/>
<field name="price_subtotal"/>
<field name="to_invoice"/>
<field name="invoiced"/>
<field widget="many2many_tags" name="tax_id" domain="[('parent_id','=',False),('type_tax_use','&lt;&gt;','purchase')]"/>
</group>
</page>
<page string="History">
<label for="name" class="oe_edit_only"/>
<h2>
<field name="name"/>
</h2>
<group string="Product Information">
<group>
<field name="to_invoice"/>
<field name="product_id" on_change="product_id_change(parent.pricelist_id,product_id,product_uom,product_uom_qty, parent.partner_id,parent.guarantee_limit)"/>
<label for="product_uom_qty"/>
<div>
<field name="product_uom_qty" string="Quantity" class="oe_inline"/>
<field name="product_uom" groups="product.group_uom" class="oe_inline"/>
</div>
</group>
<group>
<field name="price_unit"/>
<field widget="many2many_tags" name="tax_id" domain="[('parent_id','=',False),('type_tax_use','&lt;&gt;','purchase')]"/>
<field name="price_subtotal"/>
</group>
</group>
<group string="History">
<group>
<field name="invoiced"/>
</group>
<group>
<field name="invoice_line_id" />
</page>
</notebook>
</group>
</group>
</form>
<tree string="Fees" editable="bottom">
<field name="product_id" on_change="product_id_change(parent.pricelist_id,product_id,product_uom,product_uom_qty, parent.partner_id,parent.guarantee_limit)"/>
<field name='name'/>
<field name="product_uom_qty" string="Qty"/>
<field name="product_uom" string="Unit of Measure"/>
<field name="product_uom_qty" string="Quantity"/>
<field name="product_uom" string="Unit of Measure" groups="product.group_uom"/>
<field name="price_unit"/>
<field name="to_invoice"/>
<field name="price_subtotal"/>
@ -161,22 +173,26 @@
</field>
</page>
<page string="Extra Info">
<group col="4">
<field name="invoice_id"/>
<field name="picking_id"/>
<field name="location_id"/>
<field name="location_dest_id" attrs="{'readonly':[('deliver_bool','=', False)], 'required':[('deliver_bool','=', True)]}"/>
<field name="company_id" groups="base.group_multi_company" widget="selection"/>
<group>
<group>
<field name="picking_id"/>
<field name="invoice_id"/>
<field name="company_id" groups="base.group_multi_company" widget="selection"/>
</group>
<group>
<field name="location_dest_id" attrs="{'readonly':[('deliver_bool','=', False)], 'required':[('deliver_bool','=', True)]}" groups="stock.group_locations"/>
</group>
</group>
</page>
<page string="Notes">
<separator string="Internal Notes"/>
<field name="internal_notes"/>
<separator string="Quotation Notes"/>
<field name="quotation_notes"/>
<field name="internal_notes" placeholder="Add internal notes..."/>
<field name="quotation_notes" placeholder="Add quotation notes..."/>
</page>
</notebook>
</sheet>
<div class="oe_chatter">
<field name="message_ids" widget="mail_thread"/>
</div>
</form>
</field>
</record>