Saurang Suthar(OpenERP) has proposed merging 
lp:~openerp-dev/openobject-addons/trunk-advance_invoice-ssu into 
lp:openobject-addons.

Requested reviews:
  Saurang Suthar(OpenERP) (ssu-openerp)
  OpenERP Core Team (openerp)

For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-advance_invoice-ssu/+merge/102087

Hello,


Improved Advance Invoice.

Optimized more wizard steps.

Now amount can be set as percentage or fixed rate by selection.

Improved the product selection filter.

Set value of product named Advance as default value.


Thank you.
Saurang - ssu
-- 
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-advance_invoice-ssu/+merge/102087
Your team OpenERP R&D Team is subscribed to branch 
lp:~openerp-dev/openobject-addons/trunk-advance_invoice-ssu.
=== modified file 'product/product_view.xml'
--- product/product_view.xml	2012-04-05 16:55:29 +0000
+++ product/product_view.xml	2012-04-16 11:12:31 +0000
@@ -9,7 +9,7 @@
             <field name="type">search</field>
             <field name="arch" type="xml">
                 <search string="Product">
-                   <filter string="Services" icon="terp-accessories-archiver" domain="[('type','=','service')]"/>
+                   <filter string="Services" name="services" icon="terp-accessories-archiver" domain="[('type','=','service')]"/>
                    <filter string="Products" icon="terp-accessories-archiver" domain="['|',('type','=','product'),('type','=','consu')]" help="Both stockable and consumable products"/>
                    <separator orientation="vertical"/>
                    <filter string="To Sell" name="filter_to_sell" icon="terp-accessories-archiver-minus" domain="[('sale_ok','=',1)]"/>

=== modified file 'sale/sale_data.xml'
--- sale/sale_data.xml	2011-10-16 01:28:00 +0000
+++ sale/sale_data.xml	2012-04-16 11:12:31 +0000
@@ -25,6 +25,5 @@
         </record>
 
         <function eval="('default',False,'shop_id', [('sale.order', False)], shop, True, False, False, False, True)" id="sale_default_set" model="ir.values" name="set"/>
-
     </data>
 </openerp>

=== modified file 'sale/sale_demo.xml'
--- sale/sale_demo.xml	2012-03-20 05:22:58 +0000
+++ sale/sale_demo.xml	2012-04-16 11:12:31 +0000
@@ -253,12 +253,6 @@
             <field name="delay">15</field>
         </record>
         
-        <!-- Run all schedulers -->
-        <function model="procurement.order" name="run_scheduler"/>
-
-        <!-- sale advance demo.. -->
-        <!-- Demo Data for Product -->
-        
         <record id="advance_product_0" model="product.product">
             <field name="name">Advance</field>
             <field name="categ_id" ref="product.cat1"/>
@@ -268,7 +262,15 @@
             <field name="supply_method">produce</field>
             <field name="uom_id" ref="product.uom_day"/>
             <field name="uom_po_id" ref="product.uom_day"/>
-        </record>
+        </record>        
+        
+        <!-- Run all schedulers -->
+        <function model="procurement.order" name="run_scheduler"/>
+
+        <!-- sale advance demo.. -->
+        <!-- Demo Data for Product -->
+        
+
 
     <record id="base.user_demo" model="res.users">
         <field eval="[(4, ref('base.group_sale_salesman'))]" name="groups_id"/>

=== modified file 'sale/wizard/sale_make_invoice_advance.py'
--- sale/wizard/sale_make_invoice_advance.py	2012-04-03 20:57:06 +0000
+++ sale/wizard/sale_make_invoice_advance.py	2012-04-16 11:12:31 +0000
@@ -24,16 +24,48 @@
 class sale_advance_payment_inv(osv.osv_memory):
     _name = "sale.advance.payment.inv"
     _description = "Sales Advance Payment Invoice"
+    
     _columns = {
-        'product_id': fields.many2one('product.product', 'Advance Product', required=True,
+        'product_id': fields.many2one('product.product', 'Advance Product', required=False,
             help="Select a product of type service which is called 'Advance Product'. You may have to create it and set it as a default value on this field."),
         'amount': fields.float('Advance Amount', digits=(16, 2), required=True, help="The amount to be invoiced in advance."),
         'qtty': fields.float('Quantity', digits=(16, 2), required=True),
+        'pay_type':fields.selection([('percentage','Percentage'), ('fixed','Fixed')], 'Pay Type', required=True),        
     }
+    
     _defaults = {
-        'qtty': 1.0
+        'qtty': 1.0,
+        'pay_type': 'fixed',
     }
 
+    def onchange_pay_type(self, cr, uid, ids, pay_type, context=None): 
+        if pay_type == 'percentage':
+            return {'value': {'amount':0,'product_id':False }}       
+        else:
+            return {'value': {'amount':0}}
+
+    def onchange_advance_product(self, cr, uid, ids, prod_id):
+        if prod_id:
+            product = self.pool.get('product.product').browse(cr, uid, prod_id)
+            return {'value': {'amount': product.list_price}}
+        else:
+            return {'value': {'amount': 0}}
+        
+    def default_get(self, cr, uid, fields, context=None):
+        if context is None:
+            context = {}
+        record_id = context and context.get('active_id', False) or False
+        res = super(sale_advance_payment_inv, self).default_get(cr, uid, fields, context=context)
+        data_obj = self.pool.get('ir.model.data')
+        try:
+            res_id = data_obj._get_id(cr, uid, 'sale', 'advance_product_0')
+            if res_id:
+                    product_id = data_obj.browse(cr, uid, res_id, context=context).res_id
+            if product_id:
+                res.update({'product_id':product_id})
+        finally:
+            return res
+    
     def create_invoices(self, cr, uid, ids, context=None):
         """
              To create invoices.
@@ -47,13 +79,14 @@
              @return:
 
         """
+        
         list_inv = []
         obj_sale = self.pool.get('sale.order')
         obj_lines = self.pool.get('account.invoice.line')
         inv_obj = self.pool.get('account.invoice')
         if context is None:
             context = {}
-
+        
         for sale_adv_obj in self.browse(cr, uid, ids, context=context):
             for sale in obj_sale.browse(cr, uid, context.get('active_ids', []), context=context):
                 create_ids = []
@@ -64,23 +97,50 @@
                         _("You cannot make an advance on a sales order \
                              that is defined as 'Automatic Invoice after delivery'."))
                 val = obj_lines.product_id_change(cr, uid, [], sale_adv_obj.product_id.id,
-                        uom = False, partner_id = sale.partner_id.id, fposition_id = sale.fiscal_position.id)
+                        uom = False, partner_id = sale.partner_id.id, fposition_id = sale.fiscal_position.id)                
                 res = val['value']
+                
+                if not sale_adv_obj.product_id.id :
+                    prop = self.pool.get('ir.property').get(cr, uid,
+                                         'property_account_income_categ', 'product.category',
+                                         context=context)
+                    account_id = prop and prop.id or False
+                    account_id = self.pool.get('account.fiscal.position').map_account(cr, uid, sale.fiscal_position.id or False, account_id)
+                    res['account_id'] = account_id
+                    if not res.get('account_id'):
+                        raise osv.except_osv(_('Configuration Error !'),
+                                _('There is no income account defined '))
+                
                 if not res.get('account_id'):
                     raise osv.except_osv(_('Configuration Error !'),
                                 _('There is no income account defined ' \
                                         'for this product: "%s" (id:%d)') % \
                                         (sale_adv_obj.product_id.name, sale_adv_obj.product_id.id,))
                 
+                final_amount = 0    
+                if sale_adv_obj.amount <= 0.00:
+                    raise osv.except_osv(_('Data Insufficient !'),
+                        _('Please check the Advance Amount, it should not be 0 or less!'))
+                else:
+                    if sale_adv_obj.pay_type == 'percentage':
+                        final_amount = sale.amount_total * sale_adv_obj.amount / 100
+                    else:
+                        final_amount = sale_adv_obj.amount
+                
+                if res.get('invoice_line_tax_id'):
+                    res['invoice_line_tax_id'] = [(6, 0, res.get('invoice_line_tax_id'))]
+                else:
+                    res['invoice_line_tax_id'] = False      
+                              
                 line_id = obj_lines.create(cr, uid, {
-                    'name': res.get('name'),
+                    'name': res.get('name') or ("%s %s %s "%(sale_adv_obj.amount,sale_adv_obj.pay_type,"Advance.")),
                     'account_id': res['account_id'],
-                    'price_unit': sale_adv_obj.amount,
-                    'quantity': sale_adv_obj.qtty,
+                    'price_unit': final_amount,
+                    'quantity': sale_adv_obj.qtty or 1.0,
                     'discount': False,
-                    'uos_id': res.get('uos_id'),
+                    'uos_id': res.get('uos_id') or False,
                     'product_id': sale_adv_obj.product_id.id,
-                    'invoice_line_tax_id': [(6, 0, res.get('invoice_line_tax_id'))],
+                    'invoice_line_tax_id': res.get('invoice_line_tax_id'),
                     'account_analytic_id': sale.project_id.id or False,
                     #'note':'',
                 })
@@ -112,38 +172,29 @@
         # If not, the advance will be deduced when generating the final invoice
         #
                 if sale.order_policy == 'picking':
-                    self.pool.get('sale.order.line').create(cr, uid, {
+                    vals = {
                         'order_id': sale.id,
-                        'name': res.get('name'),
-                        'price_unit': -sale_adv_obj.amount,
-                        'product_uom_qty': sale_adv_obj.qtty,
-                        'product_uos_qty': sale_adv_obj.qtty,
-                        'product_uos': res.get('uos_id'),
-                        'product_uom': res.get('uos_id'),
-                        'product_id': sale_adv_obj.product_id.id,
+                        'name': res.get('name')  or ("%s %s %s "%(sale_adv_obj.amount,sale_adv_obj.pay_type,"Advance.")),
+                        'price_unit': -final_amount,
+                        'product_uom_qty': sale_adv_obj.qtty or 1.0,
+                        'product_uos_qty': sale_adv_obj.qtty or 1.0,
+                        'product_uos': res.get('uos_id') or False,
+                        'product_id': sale_adv_obj.product_id.id or False,
                         'discount': False,
-                        'tax_id': [(6, 0, res.get('invoice_line_tax_id'))],
-                    }, context)
+                        'tax_id': res.get('invoice_line_tax_id'),
+                    }
+                    if res.get('uos_id'):
+                        vals.update({'product_uom': res.get('uos_id')})
+                    self.pool.get('sale.order.line').create(cr, uid, vals, context)
 
         context.update({'invoice_id':list_inv})
 
-        return {
-            'name': 'Open Invoice',
-            'view_type': 'form',
-            'view_mode': 'form',
-            'res_model': 'sale.open.invoice',
-            'type': 'ir.actions.act_window',
-            'target': 'new',
-            'context': context
-        }
-
-sale_advance_payment_inv()
-
-class sale_open_invoice(osv.osv_memory):
-    _name = "sale.open.invoice"
-    _description = "Sales Open Invoice"
-
-    def open_invoice(self, cr, uid, ids, context=None):
+        if context['open_invoices'] == True:
+            return self.open_invoices( cr, uid, ids, context=context)
+        else:
+            return {'type': 'ir.actions.act_window_close'}            
+
+    def open_invoices(self, cr, uid, ids, context=None):
 
         """
              To open invoice.
@@ -176,6 +227,6 @@
             'type': 'ir.actions.act_window',
          }
 
-sale_open_invoice()
+sale_advance_payment_inv()
 
 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

=== modified file 'sale/wizard/sale_make_invoice_advance.xml'
--- sale/wizard/sale_make_invoice_advance.xml	2011-01-14 00:11:01 +0000
+++ sale/wizard/sale_make_invoice_advance.xml	2012-04-16 11:12:31 +0000
@@ -7,15 +7,24 @@
             <field name="type">form</field>
             <field name="arch" type="xml">
                 <form string="Advance Invoice">
-                    <field name="product_id"/>
+                	<group colspan="2">
+                    	<field name="product_id" on_change="onchange_advance_product(product_id)" context="{'search_default_services':1}" attrs="{'invisible': [('pay_type','=','percentage')]}" />
+                    </group>
                     <newline />
-                    <field name="qtty" invisible="1"/>
-                    <field name="amount"/>
+                    <group colspan="2">
+                    	
+                    	<field name="qtty" invisible="1"/>
+                   		<field name="amount"/>
+                    	<field name="pay_type" nolabel="1" attrs="{'readonly': [('product_id','=',51)]}" on_change="onchange_pay_type(pay_type)"/>
+                    </group>
                     <newline />
                     <separator string="" colspan="4"/>
-                    <label string=""  colspan="2" />
-                    <button special="cancel" string="Cancel" icon="gtk-cancel"/>
-                    <button name="create_invoices" string="Create Invoice" type="object" icon="gtk-go-forward"/>
+                    <label string="" colspan="6" />
+                    <group colspan="4">
+                    	<button special="cancel" string="Cancel" icon="gtk-cancel"/>
+                    	<button name="create_invoices" string="Create Invoice" type="object" icon="gtk-go-forward" context="{'open_invoices': False}"/>
+                    	<button name="create_invoices" string="Create and view Invoice" type="object" icon="terp-camera_test" context="{'open_invoices': True}" />
+                    </group>
                 </form>
             </field>
         </record>
@@ -28,31 +37,5 @@
             <field name="view_mode">form</field>
             <field name="target">new</field>
         </record>
-
-        <record id="view_sale_open_invoice" model="ir.ui.view">
-            <field name="name">Open Invoice</field>
-            <field name="model">sale.open.invoice</field>
-            <field name="type">form</field>
-            <field name="arch" type="xml">
-                <form string="Invoices">
-                    <label string="You invoice has been successfully created!" />
-                    <newline />
-                    <separator string="" colspan="4"/>
-                    <group colspan="4">
-                        <button special="cancel" string="Close" icon="gtk-cancel"/>
-                        <button name="open_invoice" string="Open Invoice" type="object" icon="gtk-go-forward"/>
-                    </group>
-                 </form>
-            </field>
-        </record>
-
-        <record id="action_view_sale_open_invoice" model="ir.actions.act_window">
-            <field name="name">Open Invoice</field>
-            <field name="type">ir.actions.act_window</field>
-            <field name="res_model">sale.open.invoice</field>
-            <field name="view_type">form</field>
-            <field name="view_mode">form</field>
-            <field name="target">new</field>
-        </record>
     </data>
 </openerp>

_______________________________________________
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