mardi 10 avril 2012

Compta OpenERP, TVA intra-communautaire

Actuellement, mon collègue et moi travaillons sur un module permettant d'exporter la comptabilité d'OpenERP vers Winbooks. Bien entendu, comme les deux ne fonctionnent pas de la même façon, nous avons du surmonter quelques difficultés, dont la TVA intra-communautaire.

Gérer une TVA intra-communautaire est presque équivalent à utiliser une TVA de 0%.
Et c'est à ce moment que les façons de travailler d'OpenERP et de Winbooks divergent. Alors que Winbooks a besoin d'une écriture comptable indiquant qu'il s'agit d'une TVA de 0%, OpenERP ne se fatigue même pas à créer une entrée dans le journal. Résultat, au moment de l'import vers Winbooks: ERREUR !

Problème: dans OpenERP, il manque une écriture comptable pour indiquer qu'il y a une TVA à 0%.

Solution: pour une fois, OpenERP a prévu le coup et ne requiert pas de modifier le coeur du système... En effet, il existe un hook, c'est-à-dire une méthode prévue pour être surchargée, qui est appelée juste avant que les "account.move.line" ne soient créées.


def finalize_invoice_move_lines(self, cr, uid, invoice_browse, move_lines):
    """finalize_invoice_move_lines(cr, uid, invoice, move_lines) -> move_lines
    Hook method to be overridden in additional modules to verify and possibly alter the
    move lines to be created by an invoice, for special cases.
    :param invoice_browse: browsable record of the invoice that is generating the move lines
    :param move_lines: list of dictionaries with the account.move.lines (as for create())
    :return: the (possibly updated) final move_lines to create for this invoice
    """
    return move_lines

Nous avons donc surchargé cette méthode afin d'ajouter une écriture comptable et résoudre notre problème:


# -*- coding: utf-8 -*-
##############################################################################
#    This module is developed by Idealis Consulting SPRL    
#    Copyright (C) 2011 Idealis Consulting SPRL (). All Rights Reserved
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see .
##############################################################################

from osv import fields, osv
from datetime import time, datetime

class invoice(osv.osv):
    _inherit = 'account.invoice'
    
    def finalize_invoice_move_lines(self, cr, uid, invoice_browse, move_lines):
        """finalize_invoice_move_lines(cr, uid, invoice, move_lines) -> move_lines
        Hook method to be overridden in additional modules to verify and possibly alter the
        move lines to be created by an invoice, for special cases.
        :param invoice_browse: browsable record of the invoice that is generating the move lines
        :param move_lines: list of dictionaries with the account.move.lines (as for create())
        :return: the (possibly updated) final move_lines to create for this invoice
        """
        if invoice_browse.fiscal_position and invoice_browse.fiscal_position.id != 1:
            account = False
            if invoice_browse.journal_id.type in ['sale', 'sale_refund']:
                account = self.pool.get('account.account').search(cr, uid, [('code', '=', '451000')])
            elif invoice_browse.journal_id.type in ['purchase', 'purchase_refund']:
                account = self.pool.get('account.account').search(cr, uid, [('code', '=', '411000')])
                
            if account:
                line = {
                    'name': invoice_browse.name or '/',
                    'partner_id': invoice_browse.partner_id.id,
                    'journal_id': invoice_browse.journal_id.id,
                    'account_id': account[0],
                    'invoice': invoice_browse.id,
                    'debit': 0.0,
                    'credit': 0.0,
                    'quantity': 1,
                    'tax_amount': 0.0,
                    'amount_currency': 0,
                }
                move_lines.append((0, 0, line))
        return move_lines
invoice()

Aucun commentaire:

Enregistrer un commentaire