← Back to team overview

openerp-dev-web team mailing list archive

[Merge] lp:~openerp-dev/openobject-addons/6.0-bug-783496-pso into lp:openobject-addons/6.0

 

Priyesh (Open ERP) has proposed merging lp:~openerp-dev/openobject-addons/6.0-bug-783496-pso into lp:openobject-addons/6.0.

Requested reviews:
  OpenERP Core Team (openerp)
Related bugs:
  Bug #783496 in OpenERP Addons: "Account_voucher : Onchange of amount removes all manually added lines"
  https://bugs.launchpad.net/openobject-addons/+bug/783496

For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/6.0-bug-783496-pso/+merge/61917

Hello,

Fixed issue: Onchange of amount removes all manually added lines
             Improved onchange_partner_id method of voucher

Thanks,
pso
-- 
https://code.launchpad.net/~openerp-dev/openobject-addons/6.0-bug-783496-pso/+merge/61917
Your team OpenERP R&D Team is subscribed to branch lp:~openerp-dev/openobject-addons/6.0-bug-783496-pso.
=== modified file 'account_voucher/account_voucher.py'
--- account_voucher/account_voucher.py	2011-05-20 10:29:05 +0000
+++ account_voucher/account_voucher.py	2011-05-23 06:33:50 +0000
@@ -393,7 +393,7 @@
 
         return default
 
-    def onchange_partner_id(self, cr, uid, ids, partner_id, journal_id, price, currency_id, ttype, date, context=None):
+    def onchange_partner_id(self, cr, uid, ids, partner_id, journal_id, price, currency_id, ttype, date, lines_ids=[], context=None):
         """price
         Returns a dict that contains new values and context
 
@@ -412,9 +412,14 @@
             context_multi_currency.update({'date': date})
 
         line_pool = self.pool.get('account.voucher.line')
-        line_ids = ids and line_pool.search(cr, uid, [('voucher_id', '=', ids[0])]) or False
-        if line_ids:
-            line_pool.unlink(cr, uid, line_ids)
+        flag = False
+        if lines_ids:
+            flag = True
+
+        if not flag:
+            line_ids = ids and line_pool.search(cr, uid, [('voucher_id', '=', ids[0])]) or False
+            if line_ids:
+                line_pool.unlink(cr, uid, line_ids)
 
         currency_pool = self.pool.get('res.currency')
         move_line_pool = self.pool.get('account.move.line')
@@ -462,15 +467,17 @@
             total_credit = price or 0.0
             account_type = 'receivable'
 
-        if not context.get('move_line_ids', False):
-            domain = [('state','=','valid'), ('account_id.type', '=', account_type), ('reconcile_id', '=', False), ('partner_id', '=', partner_id)]
-            if context.get('invoice_id', False):
-	            domain.append(('invoice', '=', context['invoice_id']))
-            ids = move_line_pool.search(cr, uid, domain, context=context)    
-        else:
-            ids = context['move_line_ids']
-        ids.reverse()
-        moves = move_line_pool.browse(cr, uid, ids, context=context)
+        moves = []
+        if not flag:
+            if not context.get('move_line_ids', False):
+                domain = [('state','=','valid'), ('account_id.type', '=', account_type), ('reconcile_id', '=', False), ('partner_id', '=', partner_id)]
+                if context.get('invoice_id', False):
+    	            domain.append(('invoice', '=', context['invoice_id']))
+                ids = move_line_pool.search(cr, uid, domain, context=context)
+            else:
+                ids = context['move_line_ids']
+            ids.reverse()
+            moves = move_line_pool.browse(cr, uid, ids, context=context)
 
         company_currency = journal.company_id.currency_id.id
         if company_currency != currency_id and ttype == 'payment':
@@ -485,6 +492,7 @@
                 continue
             total_credit += line.credit or 0.0
             total_debit += line.debit or 0.0
+
         for line in moves:
             if line.credit and line.reconcile_partial_id and ttype == 'receipt':
                 continue
@@ -507,26 +515,40 @@
                 amount = min(amount_unreconciled, currency_pool.compute(cr, uid, company_currency, currency_id, abs(total_debit), context=context_multi_currency))
                 rs['amount'] = amount
                 total_debit -= amount
+                default['value']['line_dr_ids'].append(rs)
             else:
                 amount = min(amount_unreconciled, currency_pool.compute(cr, uid, company_currency, currency_id, abs(total_credit), context=context_multi_currency))
                 rs['amount'] = amount
                 total_credit -= amount
-
+                default['value']['line_cr_ids'].append(rs)
             default['value']['line_ids'].append(rs)
-            if rs['type'] == 'cr':
-                default['value']['line_cr_ids'].append(rs)
-            else:
-                default['value']['line_dr_ids'].append(rs)
-
-            if ttype == 'payment' and len(default['value']['line_cr_ids']) > 0:
-                default['value']['pre_line'] = 1
-            elif ttype == 'receipt' and len(default['value']['line_dr_ids']) > 0:
-                default['value']['pre_line'] = 1
-            default['value']['writeoff_amount'] = self._compute_writeoff_amount(cr, uid, default['value']['line_dr_ids'], default['value']['line_cr_ids'], price)
+
+        if flag:
+            for line in lines_ids:
+                if line[2]['type'] == 'cr':
+                    amount = min(line[2]['amount_unreconciled'], currency_pool.compute(cr, uid, company_currency, currency_id, abs(total_credit), context=context_multi_currency))
+                    if line[1]:
+                        line_pool.write(cr, uid, [line[1]], {'amount' :amount})
+                    line[2]['amount'] = amount
+                    total_credit -= amount
+                    default['value']['line_cr_ids'].append(line[2])
+                else:
+                    amount = min(line[2]['amount_unreconciled'], currency_pool.compute(cr, uid, company_currency, currency_id, abs(total_debit), context=context_multi_currency))
+                    if line[1]:
+                        line_pool.write(cr, uid, [line[1]], {'amount' :amount})
+                    line[2]['amount'] = amount
+                    total_debit -= amount
+                    default['value']['line_dr_ids'].append(line[2])
+
+        if ttype == 'payment' and len(default['value']['line_cr_ids']) > 0:
+            default['value']['pre_line'] = 1
+        elif ttype == 'receipt' and len(default['value']['line_dr_ids']) > 0:
+            default['value']['pre_line'] = 1
+        default['value']['writeoff_amount'] = self._compute_writeoff_amount(cr, uid, default['value']['line_dr_ids'], default['value']['line_cr_ids'], price)
 
         return default
 
-    def onchange_date(self, cr, uid, ids, partner_id, journal_id, price, currency_id, ttype, date, context=None):
+    def onchange_date(self, cr, uid, ids, partner_id, journal_id, price, currency_id, ttype, date, line_ids, context=None):
         """
         @param date: latest value from user input for field date
         @param args: other arguments
@@ -534,7 +556,7 @@
         @return: Returns a dict which contains new values, and context
         """
         period_pool = self.pool.get('account.period')
-        res = self.onchange_partner_id(cr, uid, ids, partner_id, journal_id, price, currency_id, ttype, date, context=context)
+        res = self.onchange_partner_id(cr, uid, ids, partner_id, journal_id, price, currency_id, ttype, date, line_ids, context=context)
         pids = period_pool.search(cr, uid, [('date_start', '<=', date), ('date_stop', '>=', date)])
         if pids:
             if not 'value' in res:

=== modified file 'account_voucher/voucher_payment_receipt_view.xml'
--- account_voucher/voucher_payment_receipt_view.xml	2011-05-09 09:20:00 +0000
+++ account_voucher/voucher_payment_receipt_view.xml	2011-05-23 06:33:50 +0000
@@ -88,14 +88,14 @@
             <field name="arch" type="xml">
                 <form string="Bill Payment">
                     <group col="6" colspan="4">
-                        <field name="partner_id" required="1" on_change="onchange_partner_id(partner_id, journal_id, amount, currency_id, type, date, context)" context="{'invoice_currency':currency_id}" string="Supplier"/>
-                        <field name="amount" on_change="onchange_partner_id(partner_id, journal_id, amount, currency_id, type, date, context)"/>
+                        <field name="partner_id" required="1" on_change="onchange_partner_id(partner_id, journal_id, amount, currency_id, type, date, line_ids, context)" context="{'invoice_currency':currency_id}" string="Supplier"/>
+                        <field name="amount" on_change="onchange_partner_id(partner_id, journal_id, amount, currency_id, type, date, line_ids, context)"/>
                         <field name="journal_id"
                             domain="[('type','in',['bank', 'cash'])]"
                             widget="selection" select="1"
-                            on_change="onchange_partner_id(partner_id, journal_id, amount, currency_id, type, date, context)"
+                            on_change="onchange_partner_id(partner_id, journal_id, amount, currency_id, type, date, line_ids, context)"
                             string="Payment Method"/>
-                        <field name="date" select="1" on_change="onchange_date(partner_id, journal_id, amount, currency_id, type, date, context)"/>
+                        <field name="date" select="1" on_change="onchange_date(partner_id, journal_id, amount, currency_id, type, date, line_ids, context)"/>
                         <field name="reference" select="1" string="Payment Ref"/>
                         <field name="name" colspan="2"/>
                         <field name="account_id"
@@ -151,14 +151,14 @@
             <field name="arch" type="xml">
                 <form string="Bill Payment">
                     <group col="6" colspan="4">
-                        <field name="partner_id" domain="[('supplier','=',True)]" required="1" on_change="onchange_partner_id(partner_id, journal_id, amount, currency_id, type, date, context)" context="{'invoice_currency':currency_id}" string="Supplier"/>
-                        <field name="amount" on_change="onchange_partner_id(partner_id, journal_id, amount, currency_id, type, date, context)"/>
+                        <field name="partner_id" domain="[('supplier','=',True)]" required="1" on_change="onchange_partner_id(partner_id, journal_id, amount, currency_id, type, date, line_dr_ids, context)" context="{'invoice_currency':currency_id}" string="Supplier"/>
+                        <field name="amount" on_change="onchange_partner_id(partner_id, journal_id, amount, currency_id, type, date, line_dr_ids, context)"/>
                         <field name="journal_id"
                             domain="[('type','in',['bank', 'cash'])]"
                             widget="selection" select="1"
-                            on_change="onchange_partner_id(partner_id, journal_id, amount, currency_id, type, date, context)"
+                            on_change="onchange_partner_id(partner_id, journal_id, amount, currency_id, type, date, line_dr_ids, context)"
                             string="Payment Method"/>
-                        <field name="date" select="1" on_change="onchange_date(partner_id, journal_id, amount, currency_id, type, date, context)"/>
+                        <field name="date" select="1" on_change="onchange_date(partner_id, journal_id, amount, currency_id, type, date, line_dr_ids, context)"/>
                         <field name="reference" select="1" string="Payment Ref"/>
                         <field name="name" colspan="2"/>
                         <field name="company_id" select="1" widget="selection" groups="base.group_multi_company"/>
@@ -288,23 +288,23 @@
             <field name="arch" type="xml">
                 <form string="Customer Payment">
                     <group col="6" colspan="4">
-                        <field name="partner_id" required="1" on_change="onchange_partner_id(partner_id, journal_id, amount, currency_id, type, date, context)" string="Customer"/>
+                        <field name="partner_id" required="1" on_change="onchange_partner_id(partner_id, journal_id, amount, currency_id, type, date, line_cr_ids, context)" string="Customer"/>
                         <field name="amount"
                             string="Paid Amount"
-                            on_change="onchange_partner_id(partner_id, journal_id, amount, currency_id, type, date, context)"/>
+                            on_change="onchange_partner_id(partner_id, journal_id, amount, currency_id, type, date, line_cr_ids, context)"/>
                         <field name="journal_id"
                             domain="[('type','in',['bank', 'cash'])]"
                             widget="selection" select="1"
-                            on_change="onchange_partner_id(partner_id, journal_id, amount, currency_id, type, date, context)"
+                            on_change="onchange_partner_id(partner_id, journal_id, amount, currency_id, type, date, line_cr_ids, context)"
                             string="Payment Method"/>
-                        <field name="date" select="1" on_change="onchange_date(partner_id, journal_id, amount, currency_id, type, date, context)"/>
+                        <field name="date" select="1" on_change="onchange_date(partner_id, journal_id, amount, currency_id, type, date, line_cr_ids, context)"/>
                         <field name="reference" select="1" string="Payment Ref"/>
                         <field name="name" colspan="2"/>
                         <field name="company_id" select="1" widget="selection" groups="base.group_multi_company"/>
                         <field name="account_id"
                             widget="selection"
                             invisible="True"/>
-                        <field name="pre_line" invisible="1"/>
+                        <field name="pre_line"/>
                         <field name="type" invisible="True"/>
                     </group>
                     <notebook colspan="4">
@@ -379,7 +379,7 @@
                                    <field name="amount_currency"/>
                                    <field name="currency_id"/>
                                </tree>
-                            </field> 
+                            </field>
                         </page>
                     </notebook>
                     <group col="10" colspan="4">

=== modified file 'account_voucher/voucher_sales_purchase_view.xml'
--- account_voucher/voucher_sales_purchase_view.xml	2011-03-01 11:49:27 +0000
+++ account_voucher/voucher_sales_purchase_view.xml	2011-05-23 06:33:50 +0000
@@ -96,8 +96,8 @@
             <field name="arch" type="xml">
                 <form string="Sales Receipt">
                     <group col="6" colspan="4">
-                        <field name="partner_id" required="1" on_change="onchange_partner_id(partner_id, journal_id, amount, currency_id, type, date)" string="Customer"/>
-                        <field name="date" on_change="onchange_date(partner_id, journal_id, amount, currency_id, type, date)"/>
+                        <field name="partner_id" required="1" on_change="onchange_partner_id(partner_id, journal_id, amount, currency_id, type, date, line_cr_ids)" string="Customer"/>
+                        <field name="date" on_change="onchange_date(partner_id, journal_id, amount, currency_id, type, date, line_cr_ids)"/>
                         <field name="journal_id" domain="[('type','in',['sale','sale_refund'])]" widget="selection" on_change="onchange_journal(journal_id, line_cr_ids, tax_id, partner_id)"/>
                         <field name="number"/>
                         <field name="name" colspan="2"/>
@@ -222,8 +222,8 @@
             <field name="arch" type="xml">
                 <form string="Supplier Voucher">
                     <group col="6" colspan="4">
-                        <field name="partner_id" domain="[('supplier','=',True)]" required="1" string="Supplier" on_change="onchange_partner_id(partner_id, journal_id, amount, currency_id, type, date)"/>
-                        <field name="date" string="Bill Date" select="1" on_change="onchange_date(partner_id, journal_id, amount, currency_id, type, date)"/>
+                        <field name="partner_id" domain="[('supplier','=',True)]" required="1" string="Supplier" on_change="onchange_partner_id(partner_id, journal_id, amount, currency_id, type, date, line_dr_ids)"/>
+                        <field name="date" string="Bill Date" select="1" on_change="onchange_date(partner_id, journal_id, amount, currency_id, type, date, line_dr_ids)"/>
                         <field name="journal_id" domain="[('type','in',['purchase','purchase_refund'])]" widget="selection" select="1" on_change="onchange_journal(journal_id, line_dr_ids, tax_id, partner_id)"/>
                         <field name="number"/>
                         <field name="name" colspan="2"/>


Follow ups