Harry (OpenERP) has proposed merging 
lp:~openerp-dev/openobject-addons/trunk-mrp-repair-apa into 
lp:openobject-addons.

Requested reviews:
  OpenERP Core Team (openerp)

For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-mrp-repair-apa/+merge/115092

review view of Repair
-- 
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-mrp-repair-apa/+merge/115092
Your team OpenERP R&D Team is subscribed to branch 
lp:~openerp-dev/openobject-addons/trunk-mrp-repair-apa.
=== modified file 'mrp_repair/mrp_repair.py'
--- mrp_repair/mrp_repair.py	2012-06-07 14:59:10 +0000
+++ mrp_repair/mrp_repair.py	2012-07-16 10:03:57 +0000
@@ -28,6 +28,7 @@
 
 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 @@
         'partner_id' : fields.many2one('res.partner', 'Partner', select=True, help='This field allow you to choose the parner that 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. \
@@ -139,7 +140,7 @@
         'location_id': fields.many2one('stock.location', 'Current Location', select=True, readonly=True, states={'draft':[('readonly',False)]}),
         'location_dest_id': fields.many2one('stock.location', 'Delivery Location', readonly=True, states={'draft':[('readonly',False)]}),
         'move_id': fields.many2one('stock.move', 'Move',required=True, domain="[('product_id','=',product_id)]", readonly=True, states={'draft':[('readonly',False)]}),
-        'guarantee_limit': fields.date('Guarantee limit', help="The guarantee limit is computed as: last move date + warranty defined on selected product. If the current date is below the guarantee limit, each operation and fee you will add will be set as 'not to invoiced' by default. Note that you can change manually afterwards."),
+        'guarantee_limit': fields.date('Guarantee limit', states={'draft':[('readonly',False)]},help="The guarantee limit is computed as: last move date + warranty defined on selected product. If the current date is below the guarantee limit, each operation and fee you will add will be set as 'not to invoiced' by default. Note that you can change manually afterwards."),
         'operations' : fields.one2many('mrp.repair.line', 'repair_id', 'Operation Lines', readonly=True, states={'draft':[('readonly',False)]}),
         'pricelist_id': fields.many2one('product.pricelist', 'Pricelist', help='The pricelist comes from the selected partner, by default.'),
         'partner_invoice_id':fields.many2one('res.partner', 'Invoicing Address'),
@@ -155,7 +156,7 @@
         'internal_notes': fields.text('Internal Notes'),
         'quotation_notes': fields.text('Quotation Notes'),
         'company_id': fields.many2one('res.company', 'Company'),
-        'deliver_bool': fields.boolean('Deliver', help="Check this box if you want to manage the delivery once the product is repaired. If cheked, it will create a picking with selected product. Note that you can select the locations in the Info tab, if you have the extended view."),
+        'deliver_bool': fields.boolean('Deliver', states={'draft':[('readonly',False)]},help="Check this box if you want to manage the delivery once the product is repaired. If cheked, it will create a picking with selected product. Note that you can select the locations in the Info tab, if you have the extended view."),
         'invoiced': fields.boolean('Invoiced', readonly=True),
         'repaired': fields.boolean('Repaired', readonly=True),
         'amount_untaxed': fields.function(_amount_untaxed, string='Untaxed Amount',
@@ -219,7 +220,7 @@
         @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 @@
             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 @@
                 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 @@
         """
         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 repair.invoiced or repair.invoice_method == 'none':
+                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 not 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 @@
             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 @@
             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 @@
                     '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,7 +560,42 @@
                 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):
+        return self.message_append_note(cr, uid, ids, body=_("Repair has been <b>created</b>."), context=context)
+    
+    def set_start_send_note(self, cr, uid, ids, context=None):
+        message = _("Repair has been <b>Started</b>.")
+        return self.message_append_note(cr, uid, ids, body=message, context=context)
+    
+    def set_toinvoiced_send_note(self, cr, uid, ids, context=None):
+        for repair in self.browse(cr,uid,ids,context):
+            message = _("Invoice is created with <b>%s<b> reference.") % (repair.invoice_id.origin)
+            return self.message_append_note(cr, uid, ids, body=message, context=context)
+    
+    def set_confirm_send_note(self, cr, uid, ids, context=None):
+        message = _("Repair order has been <b>Confirmed</b>.")
+        return self.message_append_note(cr, uid, ids, body=message, context=context)
+    
+    def set_cancel_send_note(self, cr, uid, ids, context=None):
+        message = _("Repair has been <b>cancelled</b>.")
+        return self.message_append_note(cr, uid, ids, body=message, context=context)
+    
+    def set_ready_send_note(self, cr, uid, ids, context=None):
+        message = _("Repair is now <b>Ready</b>.")
+        return self.message_append_note(cr, uid, ids, body=message, context=context)
+
+    def set_done_send_note(self, cr, uid, ids, context=None):
+        message = _("Repair is now <b>Done</b>.")
+        return self.message_append_note(cr, uid, ids, body=message, context=context)
+
 
 
 mrp_repair()
@@ -643,7 +686,7 @@
         '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=(16,2), 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 +697,7 @@
                     ('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.\

=== modified file 'mrp_repair/mrp_repair_view.xml'
--- mrp_repair/mrp_repair_view.xml	2012-06-29 09:32:56 +0000
+++ mrp_repair/mrp_repair_view.xml	2012-07-16 10:03:57 +0000
@@ -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"/>
@@ -162,21 +174,25 @@
                     </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 col="2">
+                                <field name="picking_id"/>
+                                <field name="invoice_id"/>
+                                <field name="company_id" groups="base.group_multi_company" widget="selection"/>
+                            </group>
+                            <group col="2">
+                                <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>
+                <footer>
+                    <field name="message_ids" widget="ThreadView"/>
+                </footer>
             </form>
         </field>
     </record>

_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help   : https://help.launchpad.net/ListHelp

Reply via email to