← Back to team overview

openobject-italia-core-devs team mailing list archive

[Merge] lp:~enlightx/openobject-italia/7.0_fix_1261357 into lp:openobject-italia/7.0

 

Davide Corio has proposed merging lp:~enlightx/openobject-italia/7.0_fix_1261357 into lp:openobject-italia/7.0.

Requested reviews:
  OpenERP Italia core devs (openobject-italia-core-devs)
Related bugs:
  Bug #1261357 in OpenERP Italia: "[7.0] l10n_it_withholding_tax, movimenti contabili errati con pagamenti differenti dal netto"
  https://bugs.launchpad.net/openobject-italia/+bug/1261357

For more details, see:
https://code.launchpad.net/~enlightx/openobject-italia/7.0_fix_1261357/+merge/199294

In questo branch ho variato alcune cose riguardanti le personalizzazioni fatte al voucher per la gestione della ritenuta d'acconto.

Sul modulo ufficiali ci sono problemi quando l'importo del pagamento differisce dal netto a pagare riportato sulla fattura.

Con questa versione dovrebbe essere possibile usare il conto di storno sul voucher pagamento per registrare eventuali sbilanci (es: commissioni bancarie).

NB: penso che ciò che ho scritto possa essere semplificato, quindi attendo miglioramenti su questo branch
-- 
https://code.launchpad.net/~enlightx/openobject-italia/7.0_fix_1261357/+merge/199294
Your team OpenERP Italia core devs is requested to review the proposed merge of lp:~enlightx/openobject-italia/7.0_fix_1261357 into lp:openobject-italia/7.0.
=== modified file 'l10n_it_withholding_tax/account.py'
--- l10n_it_withholding_tax/account.py	2013-05-09 14:30:36 +0000
+++ l10n_it_withholding_tax/account.py	2013-12-17 14:44:56 +0000
@@ -108,11 +108,52 @@
 
 class account_voucher(orm.Model):
     _inherit = "account.voucher"
+
+    def _get_wht_amount(self, cr, uid, ids, field_name, arg, context=None):
+        res = {}
+        invoice_obj = self.pool.get('account.invoice')
+        wht_amount = 0
+        for voucher in self.browse(cr, uid, ids, context):
+            for line in voucher.line_ids:
+                move_id = line.move_line_id.move_id.id
+                invoice_id = invoice_obj.search(
+                    cr, uid, [('move_id', '=', move_id)]
+                )
+                if invoice_id:
+                    wht_amount += invoice_obj.browse(
+                        cr, uid, invoice_id[0]
+                        ).withholding_amount
+            res[voucher.id] = wht_amount
+        return res
+    
+    def _get_writeoff_amount(self, cr, uid, ids, name, args, context=None):
+        if not ids: return {}
+        currency_obj = self.pool.get('res.currency')
+        res = {}
+        debit = credit = 0.0
+        for voucher in self.browse(cr, uid, ids, context=context):
+            sign = voucher.type == 'payment' and -1 or 1
+            for l in voucher.line_dr_ids:
+                debit += l.amount
+            for l in voucher.line_cr_ids:
+                credit += l.amount
+            currency = voucher.currency_id or voucher.company_id.currency_id
+            wht_amount = voucher.withholding_amount
+            wo_amount = currency_obj.round(cr, uid, currency, voucher.amount - sign * (credit - debit))
+            if wo_amount > 0:
+                wo_amount -= wht_amount
+            elif wo_amount < 0:
+                wo_amount += wht_amount
+            res[voucher.id] = wo_amount
+        return res
     
     _columns = {
         'withholding_move_ids': fields.many2many('account.move', 'voucher_withholding_move_rel', 'voucher_id', 'move_id', 'Withholding Tax Entries', readonly=True),
+        'writeoff_move_id': fields.many2many('account.move', 'voucher_writeoff_move_rel', 'voucher_id', 'move_id', 'Write-off move', readonly=True),
+        'withholding_amount': fields.function(_get_wht_amount, type="float", method=True, string='Withholding amount'),
+        'writeoff_amount': fields.function(_get_writeoff_amount, string='Difference Amount', type='float', readonly=True, help="Computed as the difference between the amount stated in the voucher and the sum of allocation on the voucher lines."),
         }
-        
+
     def reconcile_withholding_move(self, cr, uid, invoice, wh_move, context=None):
         line_pool=self.pool.get('account.move.line')
         rec_ids = []
@@ -123,6 +164,17 @@
             if wh_line.account_id.type == 'payable' and invoice.company_id.withholding_account_id and invoice.company_id.withholding_account_id.id != wh_line.account_id.id and not wh_line.reconcile_id:
                 rec_ids.append(wh_line.id)
         return line_pool.reconcile_partial(cr, uid, rec_ids, type='auto', context=context)
+
+    def reconcile_writeoff_move(self, cr, uid, invoice, wo_move, context=None):
+        line_pool=self.pool.get('account.move.line')
+        rec_ids = []
+        for inv_move_line in invoice.move_id.line_id:
+            if inv_move_line.account_id.type == 'payable' and not inv_move_line.reconcile_id:
+                rec_ids.append(inv_move_line.id)
+        for wo_line in wo_move.line_id:
+            if wo_line.account_id.type == 'payable' and not wo_line.reconcile_id:
+                rec_ids.append(wo_line.id)
+        return line_pool.reconcile_partial(cr, uid, rec_ids, type='auto', context=context)
     
     def action_move_line_create(self, cr, uid, ids, context=None):
         res = super(account_voucher,self).action_move_line_create(cr, uid, ids, context)
@@ -136,7 +188,9 @@
             amounts_by_invoice = super(account_voucher,self).allocated_amounts_grouped_by_invoice(cr, uid,voucher, context)
             for inv_id in amounts_by_invoice:
                 invoice = inv_pool.browse(cr, uid, inv_id, context)
-                if invoice.withholding_amount:
+                if not invoice.withholding_amount:
+                    return res
+                else:
                     # only for supplier payments
                     if voucher.type != 'payment':
                         raise orm.except_orm(_('Error'), _('Can\'t handle withholding tax with voucher of type other than payment'))
@@ -149,11 +203,10 @@
                     if not invoice.company_id.authority_partner_id:
                         raise orm.except_orm(_('Error'), _('The company does not have an associated Tax Authority partner') )
                     # compute the new amount proportionally to paid amount
-                    new_line_amount = curr_pool.round(cr, uid, voucher.company_id.currency_id, ((amounts_by_invoice[invoice.id]['allocated'] + amounts_by_invoice[invoice.id]['write-off']) / invoice.net_pay) * invoice.withholding_amount)
-                    
+                    wht_amount = invoice.withholding_amount
                     # compute the due date
                     due_list = term_pool.compute(
-                        cr, uid, invoice.company_id.withholding_payment_term_id.id, new_line_amount,
+                        cr, uid, invoice.company_id.withholding_payment_term_id.id, wht_amount,
                         date_ref=voucher.date or invoice.date_invoice, context=context)
                     if len(due_list) > 1:
                         raise orm.except_orm(_('Error'),
@@ -165,6 +218,7 @@
                             % invoice.company_id.withholding_payment_term_id.name)
                             
                     period_ids = priod_obj.find(cr, uid, dt=voucher.date, context=context)
+
                     new_move = {
                         'journal_id': invoice.company_id.withholding_journal_id.id,
                         'period_id': period_ids and period_ids[0] or False,
@@ -174,7 +228,7 @@
                                 'name': invoice.number,
                                 'account_id': invoice.account_id.id,
                                 'partner_id': invoice.partner_id.id,
-                                'debit': new_line_amount,
+                                'debit': wht_amount,
                                 'credit': 0.0,
                                 }),
                             (0,0,{
@@ -182,7 +236,7 @@
                                 'account_id': invoice.company_id.withholding_account_id.id,
                                 'partner_id': invoice.company_id.authority_partner_id.id,
                                 'debit': 0.0,
-                                'credit': new_line_amount,
+                                'credit': wht_amount,
                                 'date_maturity': due_list[0][0],
                                 }),
                             ]
@@ -190,6 +244,35 @@
                     move_id = self.pool.get('account.move').create(cr, uid, new_move, context=context)
                     self.reconcile_withholding_move(cr, uid, invoice, move_pool.browse(cr, uid, move_id, context), context)
                     voucher.write({'withholding_move_ids': [(4, move_id)]})
+                    amount_unreconciled = 0.0
+                    for dr_line in voucher.line_dr_ids:
+                        amount_unreconciled += dr_line.amount_unreconciled
+                    wo_amount = amount_unreconciled-voucher.amount-voucher.withholding_amount
+                    if voucher.amount != invoice.net_pay:
+                        wo_move = {
+                            'journal_id': voucher.journal_id.id,
+                            'period_id': period_ids and period_ids[0] or False,
+                            'date': voucher.date,
+                            'line_id': [
+                                (0,0,{
+                                    'name': invoice.number,
+                                    'account_id': invoice.account_id.id,
+                                    'partner_id': invoice.partner_id.id,
+                                    'debit': wo_amount,
+                                    'credit': 0.0,
+                                    }),
+                                (0,0,{
+                                    'name': voucher.comment,
+                                    'account_id': voucher.writeoff_acc_id.id,
+                                    'partner_id': invoice.partner_id.id,
+                                    'debit': 0.0,
+                                    'credit': wo_amount,
+                                    }),
+                                ]
+                            }
+                        wo_move_id = self.pool.get('account.move').create(cr, uid, wo_move, context=context)
+                        self.reconcile_writeoff_move(cr, uid, invoice, move_pool.browse(cr, uid, wo_move_id, context), context)
+                        voucher.write({'writeoff_move_id': [(4, wo_move_id)]})
         return res
 
     def cancel_voucher(self, cr, uid, ids, context=None):

=== modified file 'l10n_it_withholding_tax/account_view.xml'
--- l10n_it_withholding_tax/account_view.xml	2013-04-17 12:47:39 +0000
+++ l10n_it_withholding_tax/account_view.xml	2013-12-17 14:44:56 +0000
@@ -66,6 +66,19 @@
                 </field>
             </field>
         </record>
+
+        <!-- Supplier Payment -->
+        
+        <record model="ir.ui.view" id="view_vendor_payment_form_wht">
+            <field name="name">account.voucher.payment.form.wht</field>
+            <field name="model">account.voucher</field>
+            <field name="inherit_id" ref="account_voucher.view_vendor_payment_form"/>
+            <field name="arch" type="xml">
+                <field name="writeoff_amount" position="after">
+                    <field name="withholding_amount"/>
+                </field>
+            </field>
+        </record>
         
     </data>
 </openerp>


Follow ups