Ajay Chauhan(OpenERP) has proposed merging 
lp:~openerp-dev/openobject-addons/trunk-addons_issue_sale_button_visibility-cha 
into lp:~openerp-dev/openobject-addons/trunk-addons_issue_sales-mdi.

Requested reviews:
  OpenERP R&D Team (openerp-dev)

For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-addons_issue_sale_button_visibility-cha/+merge/123882

Hello,

    I have made function field to get 'View Invoice' button on view when at 
least one invoice is created for that sale order & modified function for 
'invoiced' field to get 'Create Invoice' button in our preferred scenario.

 Scenario: 
    1> confirm sale order with order policy != On Delivery Order.
    2> create invoice with some order line select one line & paid that invoice.
    3> Now we should have both buttons 'View invoice' & 'Create Invoice' to 
create the invoice for           remaining order lines.       

Thanks,
Ajay Chauhan      
-- 
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-addons_issue_sale_button_visibility-cha/+merge/123882
Your team OpenERP R&D Team is requested to review the proposed merge of 
lp:~openerp-dev/openobject-addons/trunk-addons_issue_sale_button_visibility-cha 
into lp:~openerp-dev/openobject-addons/trunk-addons_issue_sales-mdi.
=== modified file 'sale/sale.py'
--- sale/sale.py	2012-09-12 04:43:12 +0000
+++ sale/sale.py	2012-09-12 05:08:15 +0000
@@ -145,6 +145,21 @@
                 res[sale.id] = 0.0
         return res
 
+    def _get_invoiced_amount(self, cr, uid, sale, context=None):
+        invoiced_amount = 0
+        for invoice in sale.invoice_ids:
+            if invoice.state!='cancel':
+                invoiced_amount += invoice.amount_total
+        return invoiced_amount
+
+    def _invoice_exists(self, cursor, user, ids, name, arg, context=None):
+        res = {}
+        for sale in self.browse(cursor, user, ids, context=context):
+            res[sale.id] = False
+            if sale.invoice_ids:
+                res[sale.id] = True
+        return res
+
     def _invoiced(self, cursor, user, ids, name, arg, context=None):
         res = {}
         for sale in self.browse(cursor, user, ids, context=context):
@@ -156,7 +171,7 @@
                     if invoice.state != 'paid':
                         res[sale.id] = False
                         break
-            if not invoice_existence:
+            if not invoice_existence or sale.state == 'manual':
                 res[sale.id] = False
         return res
 
@@ -245,6 +260,8 @@
         'invoiced_rate': fields.function(_invoiced_rate, string='Invoiced', type='float'),
         'invoiced': fields.function(_invoiced, string='Paid',
             fnct_search=_invoiced_search, type='boolean', help="It indicates that an invoice has been paid."),
+        'invoice_exists': fields.function(_invoice_exists, string='Invoiced',
+            fnct_search=_invoiced_search, type='boolean', help="It indicates that sale order has at least one invoice."),
         'note': fields.text('Terms and conditions'),
 
         'amount_untaxed': fields.function(_amount_all, digits_compute= dp.get_precision('Account'), string='Untaxed Amount',
@@ -518,33 +535,22 @@
         This function returns an action that display existing invoices of given sale order ids. It can either be a in a list or in a form view, if there is only one invoice to show.
         '''
         mod_obj = self.pool.get('ir.model.data')
-        result = {
-            'name': _('Cutomer Invoice'),
-            'view_type': 'form',
-            'res_model': 'account.invoice',
-            'context': "{'type':'out_invoice', 'journal_type': 'sale'}",
-            'type': 'ir.actions.act_window',
-            'nodestroy': True,
-            'target': 'current',
-        }
+        act_obj = self.pool.get('ir.actions.act_window')
+
+        result = mod_obj.get_object_reference(cr, uid, 'account', 'action_invoice_tree1')
+        id = result and result[1] or False
+        result = act_obj.read(cr, uid, [id], context=context)[0]
         #compute the number of invoices to display
         inv_ids = []
         for so in self.browse(cr, uid, ids, context=context):
             inv_ids += [invoice.id for invoice in so.invoice_ids]
         #choose the view_mode accordingly
-        if len(inv_ids)>1:
-            res = mod_obj.get_object_reference(cr, uid, 'account', 'invoice_tree')
-            result.update({
-                'view_mode': 'tree,form',
-                'res_id': inv_ids or False
-            })
+        if len(inv_ids) > 1:
+            result['domain'] = "[('id','in',["+','.join(map(str, inv_ids))+"])]"
         else:
             res = mod_obj.get_object_reference(cr, uid, 'account', 'invoice_form')
-            result.update({
-                'view_mode': 'form',
-                'res_id': inv_ids and inv_ids[0] or False,
-            })
-        result.update(view_id = res and res[1] or False)
+            result['views'] = [(res and res[1] or False, 'form')]
+            result['res_id'] = inv_ids and inv_ids[0] or False
         return result
 
 

=== modified file 'sale/sale_view.xml'
--- sale/sale_view.xml	2012-09-12 04:43:12 +0000
+++ sale/sale_view.xml	2012-09-12 05:08:15 +0000
@@ -163,7 +163,7 @@
                             <button name="action_button_confirm" states="draft" string="Confirm" type="object"/>
                             <button name="action_button_confirm" states="sent" string="Confirm" class="oe_highlight" type="object"/>
                             <button name="action_view_invoice" string="View Invoice" type="object" class="oe_highlight"
-                              attrs="{'invisible': ['|','|',('state', '!=','progress'), ('invoiced', '=', True),('order_policy','=','picking')]}"/>
+                              attrs="{'invisible': ['|', '|', '|', ('state', 'not in',('progress','manual')), ('invoiced', '=', True), ('invoice_exists', '=', False), ('order_policy','=','picking')]}"/>
                             <button name="action_view_delivery" string="View Delivery Order" type="object" class="oe_highlight"
                               attrs="{'invisible': ['|','|','|',('picking_ids','=',False),('picking_ids','=',[]), ('state', 'not in', ('progress','manual')),('shipped','=',True)]}"/>
                             <button name="%(action_view_sale_advance_payment_inv)d" string="Create Invoice"
@@ -320,6 +320,7 @@
                                 <group>
                                     <field name="invoiced"/>
                                     <field name="shipped"/>
+                                    <field name="invoice_exists"/>
                                 </group>
                             </group>
                         </page>

_______________________________________________
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