[IMP]: improve to the voucher module
authorMantavya Gajjar <mga@tinyerp.com>
Mon, 30 Aug 2010 13:23:02 +0000 (18:53 +0530)
committerMantavya Gajjar <mga@tinyerp.com>
Mon, 30 Aug 2010 13:23:02 +0000 (18:53 +0530)
bzr revid: mga@tinyerp.com-20100830132302-md1qsa232otuetrd

addons/account_voucher/__openerp__.py
addons/account_voucher/voucher.py
addons/account_voucher/voucher_payment_receipt_view.xml
addons/account_voucher/voucher_sales_purchase_view.xml
addons/account_voucher/voucher_view.xml
addons/account_voucher/wizard/account_voucher_unreconcile.py
addons/account_voucher/wizard/account_voucher_unreconcile_view.xml

index d02011d..9bb8913 100644 (file)
@@ -44,8 +44,8 @@
         "wizard/account_voucher_open_view.xml",
         "wizard/account_voucher_unreconcile_view.xml",
         "voucher_view.xml",
-        "voucher_sales_purchase_view.xml",
         "voucher_payment_receipt_view.xml",
+        "voucher_sales_purchase_view.xml",
         "voucher_wizard.xml",
     ],
     "test" : [
index 4cc4443..df30539 100644 (file)
@@ -101,7 +101,7 @@ class account_voucher(osv.osv):
         'line_dr_ids':fields.one2many('account.voucher.line','voucher_id','Debits',
             domain=[('type','=','dr')], context={'default_type':'dr'}, readonly=True, states={'draft':[('readonly',False)]}),
         'period_id': fields.many2one('account.period', 'Period', required=True, readonly=True, states={'draft':[('readonly',False)]}),
-        'narration':fields.text('Narration', readonly=True, states={'draft':[('readonly',False)]}),
+        'narration':fields.text('Notes', readonly=True, states={'draft':[('readonly',False)]}),
         'currency_id': fields.many2one('res.currency', 'Currency', required=True, readonly=True, states={'draft':[('readonly',False)]}),
         'company_id': fields.many2one('res.company', 'Company', required=True),
         'state':fields.selection(
@@ -120,7 +120,7 @@ class account_voucher(osv.osv):
         'number': fields.related('move_id', 'name', type="char", readonly=True, string='Number'),
         'move_id':fields.many2one('account.move', 'Account Entry'),
         'move_ids': fields.related('move_id','line_id', type='many2many', relation='account.move.line', string='Journal Items', readonly=True),
-        'partner_id':fields.many2one('res.partner', 'Partner', readonly=True, states={'draft':[('readonly',False)]}),
+        'partner_id':fields.many2one('res.partner', 'Partner', change_default=1, readonly=True, states={'draft':[('readonly',False)]}),
         'audit': fields.related('move_id','to_check', type='boolean', relation='account.move', string='Audit Complete ?'),
         'pay_now':fields.selection([
             ('pay_now','Pay Directly'),
@@ -143,7 +143,52 @@ class account_voucher(osv.osv):
         'company_id': lambda self,cr,uid,c: self.pool.get('res.company')._company_default_get(cr, uid, 'account.voucher',context=c),
         'tax_id': _get_tax,
     }
-
+    
+    def compute_tax(self, cr, uid, ids, context={}):
+        tax_pool = self.pool.get('account.tax')
+        partner_pool = self.pool.get('res.partner')
+        position_pool = self.pool.get('account.fiscal.position')
+        voucher_line_pool = self.pool.get('account.voucher.line')
+        voucher_pool = self.pool.get('account.voucher')
+        
+        for voucher in voucher_pool.browse(cr, uid, ids, context):
+            voucher_amount = 0.0
+            for line in voucher.line_ids:
+                voucher_amount += line.untax_amount or line.amount
+                line.amount = line.untax_amount
+                voucher_line_pool.write(cr, uid, [line.id], {'amount':line.untax_amount, 'untax_amount':line.untax_amount})
+                
+            if not voucher.tax_id:
+                continue
+            
+            tax = [tax_pool.browse(cr, uid, voucher.tax_id.id)]
+            partner = partner_pool.browse(cr, uid, voucher.partner_id.id) or False
+            taxes = position_pool.map_tax(cr, uid, partner and partner.property_account_position or False, tax)
+            tax = tax_pool.browse(cr, uid, taxes)
+            
+            total = voucher_amount
+            total_tax = 0.0
+            
+            if not tax[0].price_include:
+                for tax_line in tax_pool.compute_all(cr, uid, tax, voucher_amount, 1).get('taxes'):
+                    total_tax += tax_line.get('amount')
+                total += total_tax
+            else:
+                line_ids2 = []
+                for line in voucher.line_ids:
+                    line_total = 0.0
+                    line_tax = 0.0
+                    
+                    for tax_line in tax_pool.compute_all(cr, uid, tax, line.untax_amount or line.amount, 1).get('taxes'):
+                        line_tax += tax_line.get('amount')
+                        line_total += tax_line.get('price_unit')
+                    total_tax += line_tax
+                    untax_amount = line.untax_amount or line.amount
+                    voucher_line_pool.write(cr, uid, [line.id], {'amount':line_total, 'untax_amount':untax_amount})
+            
+            self.write(cr, uid, [voucher.id], {'amount':total, 'tax_amount':total_tax})
+        return True
+            
     # TODO: review this code.
     def onchange_price(self, cr, uid, ids, line_ids, tax_id, partner_id=False, context={}):
         tax_pool = self.pool.get('account.tax')
@@ -162,45 +207,16 @@ class account_voucher(osv.osv):
         total_tax = 0.0
         
         for line in line_ids:
+            line_amount = 0.0
+            if line[1]:
+                line_amount = voucher_line_pool.browse(cr, uid, line[1]).untax_amount
+            else:
+                line_amount = line[2].get('amount')
             voucher_line_ids += [line[1]]
-            voucher_total += line[2].get('amount')
+            voucher_total += line_amount
         
         total = voucher_total
         
-        if tax_id:
-            tax = [tax_pool.browse(cr, uid, tax_id)]
-            
-            if partner_id:
-                partner = partner_pool.browse(cr, uid, partner_id) or False
-                taxes = position_pool.map_tax(cr, uid, partner and partner.property_account_position or False, tax)
-                tax = tax_pool.browse(cr, uid, taxes)
-            
-            if not tax[0].price_include:
-                for tax_line in tax_pool.compute_all(cr, uid, tax, voucher_total, 1).get('taxes'):
-                    total_tax += tax_line.get('amount')
-                total += total_tax
-            else:
-                line_ids2 = []
-                for line in line_ids:
-                    line_total = 0.0
-                    line_tax = 0.0
-                    operation = line[0]
-                    rec_id = line[1]
-                    rec = line[2]
-                    for tax_line in tax_pool.compute_all(cr, uid, tax, rec.get('amount'), 1).get('taxes'):
-                        line_tax += tax_line.get('amount')
-                        line_total += tax_line.get('price_unit')
-                    total_tax += line_tax
-                    if rec_id:
-                        voucher_line_pool.write(cr, uid, [rec_id], {'amount':line_total})
-                        line_ids2 += [rec_id]
-                    else:
-                        rec.update({
-                            'amount':line_total
-                        })
-                res.update({
-                    'line_ids':line_ids2
-                })
         res.update({
             'amount':total,
             'tax_amount':total_tax
@@ -486,6 +502,8 @@ class account_voucher(osv.osv):
                     'move_id':move_id,
                     'partner_id':inv.partner_id.id,
                     'currency_id':inv.currency_id.id,
+                    'analytic_account_id':line.account_analytic_id and line.account_analytic_id.id or False,
+                    'quantity':1
                 }
                 if (line.type=='dr'):
                     line_total += amount
@@ -563,7 +581,10 @@ class account_voucher(osv.osv):
         default.update({
             'state':'draft',
             'number':False,
-            'move_id':False
+            'move_id':False,
+            'line_cr_ids':False,
+            'line_dr_ids':False,
+            'reference':False
         })
         if 'date' not in default:
             default['date'] = time.strftime('%Y-%m-%d')
@@ -606,6 +627,8 @@ account_voucher()
 class account_voucher_line(osv.osv):
     _name = 'account.voucher.line'
     _description = 'Voucher Lines'
+    _order = "move_line_id"
+    
     def _compute_balance(self, cr, uid, ids, name, args, context=None):
         res = {}
         for line in self.browse(cr, uid, ids):
@@ -623,6 +646,7 @@ class account_voucher_line(osv.osv):
         'name':fields.char('Description', size=256),
         'account_id':fields.many2one('account.account','Account', required=True),
         'partner_id':fields.related('voucher_id', 'partner_id', type='many2one', relation='res.partner', string='Partner'),
+        'untax_amount':fields.float('Untax Amount'),
         'amount':fields.float('Amount'),
         'type':fields.selection([('dr','Debit'),('cr','Credit')], 'Cr/Dr'),
         'account_analytic_id':  fields.many2one('account.analytic.account', 'Analytic Account'),
index 4ffba53..4e2dc62 100644 (file)
@@ -33,7 +33,7 @@
                                         on_change="onchange_move_line_id(move_line_id)"
                                         domain="[('account_id.type','=','payable'), ('reconcile_id','=', False), ('partner_id','=',parent.partner_id)]"
                                         />
-                                    <field name="account_id"  domain="[('type','=','payable')]"/>
+                                    <field name="account_id" groups="base.group_extended" domain="[('type','=','payable')]"/>
                                     <field name="date_original" readonly="1"/>
                                     <field name="date_due" readonly="1"/>
                                     <field name="amount_original" readonly="1"/>
@@ -44,7 +44,7 @@
                             <field name="line_cr_ids" colspan="4" nolabel="1" attrs="{'invisible': [('pre_line','=',False)]}" default_get="{'journal_id':journal_id, 'partner_id':partner_id}">
                                 <tree string="Credits" editable="bottom">
                                     <field name="move_line_id"/>
-                                    <field name="account_id"  domain="[('type','=','receivable')]"/>
+                                    <field name="account_id" groups="base.group_extended" domain="[('type','=','receivable')]"/>
                                     <field name="date_original"/>
                                     <field name="amount_original"/>
                                     <field name="amount" sum="Payment"/>
@@ -61,7 +61,7 @@
                                 <field name="number"/>
                             </group>
                         </page>
-                        <page string="Journal Items">
+                        <page string="Journal Items" groups="base.group_extended" attrs="{'invisible': [('state','!=','posted')]}">
                             <group col="6" colspan="4">
                                 <field name="company_id" select="1" widget="selection" groups="base.group_multi_company"/>
                                 <field name="period_id"/>
@@ -73,8 +73,8 @@
                     </notebook>
                     <group col="10" colspan="4">
                         <field name="state"/>
-                        <button name="proforma_voucher" string="Create" states="draft" icon="terp-document-new"/>
                         <button name="cancel_voucher" string="Cancel" states="draft,proforma"  icon="gtk-cancel"/>
+                        <button name="proforma_voucher" string="Create" states="draft" icon="terp-camera_test"/>
                         <button name="action_cancel_draft" type="object" states="cancel" string="Set to Draft" icon="terp-stock_effects-object-colorize"/>
                         <button name="%(action_view_account_voucher_unreconcile)d" string="Unreconcile" type="action" states="posted" icon="terp-stock_effects-object-colorize"/>
                     </group>
                                         on_change="onchange_move_line_id(move_line_id)"
                                         domain="[('account_id.type','in',('receivable','payable')), ('reconcile_id','=', False), ('partner_id','=',parent.partner_id)]"
                                         />
-                                    <field name="account_id"  domain="[('type','=','receivable')]"/>
+                                    <field name="account_id"  groups="base.group_extended" domain="[('type','=','receivable')]"/>
                                     <field name="date_original" readonly="1"/>
                                     <field name="date_due" readonly="1"/>
                                     <field name="amount_original" readonly="1"/>
                             <field name="line_dr_ids" colspan="4" nolabel="1" attrs="{'invisible': [('pre_line','=',False)]}" default_get="{'journal_id':journal_id, 'partner_id':partner_id}">
                                 <tree string="Credits" editable="bottom">
                                     <field name="move_line_id"/>
-                                    <field name="account_id"  domain="[('type','=','receivable')]"/>
+                                    <field name="account_id"  groups="base.group_extended" domain="[('type','=','receivable')]"/>
                                     <field name="date_original"/>
                                     <field name="amount_original"/>
                                     <field name="amount" sum="Payment"/>
                                 <field name="number"/>
                             </group>
                         </page>
-                        <page string="Journal Items" groups="base.group_extended">
+                        <page string="Journal Items" groups="base.group_extended" attrs="{'invisible': [('state','!=','posted')]}">
                             <group col="6" colspan="4">
                                 <field name="company_id" select="1" widget="selection" groups="base.group_multi_company"/>
                                 <field name="period_id"/>
                     </notebook>
                     <group col="10" colspan="4">
                         <field name="state"/>
-                        <button name="proforma_voucher" string="Post" states="draft" icon="terp-document-new"/>
                         <button name="cancel_voucher" string="Cancel" states="draft,proforma"  icon="gtk-cancel"/>
+                        <button name="proforma_voucher" string="Post" states="draft" icon="terp-camera_test"/>
                         <button name="action_cancel_draft" type="object" states="cancel" string="Set to Draft" icon="terp-stock_effects-object-colorize"/>
                         <button name="%(action_view_account_voucher_unreconcile)d" string="Unreconcile" type="action" states="posted" icon="terp-stock_effects-object-colorize"/>
                     </group>
index f795ec1..31dc8f5 100644 (file)
@@ -1,6 +1,23 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <openerp>
     <data>
+        
+<!--        <act_window-->
+<!--            id="act_pay_voucher"-->
+<!--            name="Sales Payment"-->
+<!--            context="{'partner_id': partner_id, 'type':'receipt', 'journal_type':'bank'}"-->
+<!--            res_model="account.voucher"-->
+<!--            src_model="account.voucher"/>-->
+<!--        <record id="act_pay_voucher" model="ir.actions.act_window">-->
+<!--            <field name="name">Sales Payment</field>-->
+<!--            <field name="res_model">account.voucher.open</field>-->
+<!--            <field name="view_type">form</field>-->
+<!--            <field name="domain">[('journal_id.type', 'in', ['bank', 'cash']), ('type','=','receipt'), ('partner_id','=',partner_id)]</field>-->
+<!--            <field name="context">{'journal_type':'bank', 'type':'receipt', 'partner_id': partner_id}</field>-->
+<!--            <field name="view_id" ref="account_open_vouchers_view"/>-->
+<!--            <field name="target">new</field>-->
+<!--        </record>-->
+        
         <record model="ir.ui.view" id="view_sale_receipt_form">
             <field name="name">account.voucher.sale.form</field>
             <field name="model">account.voucher</field>
                                     <field name="pay_now" on_change="onchange_payment(pay_now, journal_id, partner_id)" required="1"/>
                                     <field name="account_id" 
                                          attrs="{'invisible':[('pay_now','!=','pay_now')]}"
-                                          domain="[('user_type.report_type','=','asset')]"/>
+                                          domain="[('user_type.report_type','=','asset'), ('type','=','other')]"/>
                                          <!-- should select income accounts only. Or use the journal for this ? -->
                                     <field name="reference"
                                          attrs="{'invisible':[('pay_now','!=','pay_now')]}"
                                     />
                                 </group>
-                                <group col="3" colspan="1">
-                                    <separator string="Total" colspan="3"/>
-                                    <field name="tax_id" on_change="onchange_price(line_cr_ids, tax_id, partner_id)" widget="selection" domain="[('type_tax_use','in',('sale','all'))]"/><field name="tax_amount" on_change="onchange_price(line_ids, tax_id, partner_id)" nolabel="1"/>
+                                <group col="4" colspan="1">
+                                    <separator string="Total" colspan="4"/>
+                                    <field name="tax_id" on_change="onchange_price(line_cr_ids, tax_id, partner_id)" widget="selection" domain="[('type_tax_use','in',('sale','all'))]"/><field name="tax_amount" on_change="onchange_price(line_ids, tax_id, partner_id)" nolabel="1"/><button type="object" icon="terp-stock_format-scientific" name="compute_tax" string="Compute Tax" attrs="{'invisible': [('state','!=','draft')]}"/>
                                     <label colspan="1" string=""/><field name="amount" string="Total"/>
                                 </group>
                             </group>
                         </page>
-                        <page string="Journal Items" groups="base.group_extended">
+                        <page string="Journal Items" groups="base.group_extended" attrs="{'invisible': [('state','!=','posted')]}">
                             <group col="6" colspan="4">
                                 <field name="company_id" select="1" widget="selection" groups="base.group_multi_company"/>
                                 <field name="period_id"/>
@@ -60,8 +77,9 @@
                     </notebook>
                     <group col="10" colspan="4">
                         <field name="state"/>
-                        <button name="proforma_voucher" string="Post" states="draft" icon="terp-document-new"/>
                         <button name="cancel_voucher" string="Cancel" states="draft,proforma"  icon="gtk-cancel"/>
+                        <button name="proforma_voucher" string="Post" states="draft" icon="terp-camera_test"/>
+<!--                        <button name="%(action_vendor_receipt)d" type="action" string="Pay"/>-->
                         <button name="action_cancel_draft" type="object" states="cancel" string="Set to Draft" icon="terp-stock_effects-object-colorize"/>
                         <button name="%(action_view_account_voucher_unreconcile)d" string="Cancel" type="action" states="posted" icon="terp-stock_effects-object-colorize"/>
                     </group>
                                 </group>
                             </group>
                         </page>
-                        <page string="Journal Items">
+                        <page string="Journal Items" groups="base.group_extended" attrs="{'invisible': [('state','!=','posted')]}">
                             <group col="6" colspan="4">
                                 <field name="company_id" select="1" widget="selection" groups="base.group_multi_company"/>
                                 <field name="period_id"/>
                     </notebook>
                     <group col="10" colspan="4">
                         <field name="state"/>
-                        <button name="proforma_voucher" string="Post" states="draft" icon="terp-document-new"/>
                         <button name="cancel_voucher" string="Cancel" states="draft,proforma"  icon="gtk-cancel"/>
+                        <button name="proforma_voucher" string="Post" states="draft" icon="terp-camera_test"/>
                         <button name="action_cancel_draft" type="object" states="cancel" string="Set to Draft" icon="terp-stock_effects-object-colorize"/>
                         <button name="%(action_view_account_voucher_unreconcile)d" string="Cancel" type="action" states="posted" icon="terp-stock_effects-object-colorize"/>
                     </group>
index b7d66e7..bd081fc 100644 (file)
@@ -12,7 +12,7 @@
                     <field name="reference"/>
                     <field name="partner_id"/>
                     <field name="journal_id"/>
-                    <field name="period_id" invisible="context.get('visible', False)"/>
+                    <field name="period_id" groups="base.group_extended" invisible="context.get('visible', True)"/>
                     <field name="amount" sum="Total Amount"/>
                     <field name="state"/>
                     <button name="proforma_voucher" string="Post" states="draft" icon="terp-document-new"/>
                         <filter icon="terp-camera_test" string="Posted" domain="[('state','=','posted')]" help="Posted Vouchers"/>
                         <separator orientation="vertical"/>
                         <filter icon="terp-stock_effects-object-colorize" string="To Review" domain="[('state','=','posted')]" groups="base.group_extended" help="To Review"/>
-                        <filter icon="gtk-cancel" string="Cancel" domain="[('state','=','cancel')]" help="Cancel Vouchers" groups="base.group_extended"/>
                         <separator orientation="vertical"/>
                         <field name="date" select='1'/>
                         <field name="number" select='1'/>
                         <field name="partner_id" select='1'/>
+                    </group>
+                    <newline/>
+                    <group col='8' colspan='4'>
                         <field name="journal_id" widget="selection" select="1"/>
                         <field name="period_id" select="1"/>
                     </group>
-<!--                    <newline/>-->
-<!--                    <group col='8' colspan='4'>-->
-<!--                        <field name="journal_id" widget="selection" select="1"/>-->
-<!--                        <field name="period_id" select="1"/>-->
-<!--                    </group>-->
                     <newline/>
                     <group expand="0" string="Group By..." colspan="12" col="10">
                         <filter string="Partner" icon="terp-partner" domain="[]" context="{'group_by':'partner_id'}"/>
index fdb51bb..30cda89 100644 (file)
@@ -49,12 +49,10 @@ class account_voucher_unreconcile(osv.osv_memory):
                     recs += [line.reconcile_id.id]
                 if line.reconcile_partial_id:
                     recs += [line.reconcile_partial_id.id]
-                
             #for rec in recs:
             reconcile_pool.unlink(cr, uid, recs)
-            
-            if res.remove:
-                voucher_pool.cancel_voucher(cr, uid, [context.get('active_id')], context)
+#            if res.remove:
+            voucher_pool.cancel_voucher(cr, uid, [context.get('active_id')], context)
 #                wf_service = netsvc.LocalService("workflow")
 #                wf_service.trg_validate(uid, 'account.voucher', context.get('active_id'), 'cancel_voucher', cr)
             
index 3f8dd9c..138aaec 100644 (file)
@@ -11,8 +11,6 @@
                 <separator colspan="4" string="Unreconciliation transactions" />
                 <label string="If you unreconciliate transactions, you must also verify all the actions that are linked to those transactions because they will not be disable" colspan="2"/>
                 <separator colspan="4"/>
-                <field name="remove"/>
-                <separator colspan="4"/>
                 <button special="cancel" string="Cancel" icon="gtk-cancel"/>
                 <button name="trans_unrec" default_focus="1" string="Unreconcile" type="object" icon="gtk-ok"/>
              </form>