Browse Source

TVA par taux + Correctif calcul tva.

Philippe Le Brouster 9 years ago
parent
commit
faeb23708e
3 changed files with 36 additions and 35 deletions
  1. 0 1
      bin/himport
  2. 0 15
      himports/dolibarrAlchemy.py
  3. 36 19
      himports/dolibarrAlchemyHledger.py

+ 0 - 1
bin/himport

@@ -122,7 +122,6 @@ def do_sqlalchemy(options):
     dolibarr.connect()
 
     if options['pdb']:
-        from ptpdb import set_trace
         s = dolibarr.session
         b = s.query(Bank).all()[10]
         set_trace()

+ 0 - 15
himports/dolibarrAlchemy.py

@@ -21,7 +21,6 @@ Base = declarative_base(cls=DeferredReflection)
 class Bank(Base):
     __tablename__ = "llx_bank"
     id = Column("rowid", Integer, primary_key=True)
-    amount = Column(Float)
 
     fk_account = Column('fk_account', Integer, ForeignKey('llx_bank_account.rowid'))
     account = relationship("BankAccount", backref="entries", lazy="subquery")
@@ -105,8 +104,6 @@ class CotisationsSociales(Base):
     __tablename__ = "llx_chargesociales"
     id = Column("rowid", Integer, primary_key=True)
 
-    amount = Column(Float)
-
     fk_type = Column('fk_type', Integer, ForeignKey('llx_c_chargesociales.id'))
     type = relationship(
         "CCotisationsSociales", backref="cotisations_sociales",
@@ -215,9 +212,6 @@ class Product(Base):
 class FactureFourn(Base):
     __tablename__ = "llx_facture_fourn"
     id = Column("rowid", Integer, primary_key=True)
-    total_ht = Column(Float)
-    total_ttc = Column(Float)
-    total_tva = Column(Float)
 
     fk_soc = Column(Integer, ForeignKey('llx_societe.rowid'))
     societe = relationship(
@@ -235,9 +229,6 @@ class FactureFourn(Base):
 class Facture(Base):
     __tablename__ = "llx_facture"
     id = Column("rowid", Integer, primary_key=True)
-    total = Column(Float)
-    total_ttc = Column(Float)
-    tva = Column(Float)
 
     fk_soc = Column(Integer, ForeignKey('llx_societe.rowid'))
     societe = relationship(
@@ -255,9 +246,6 @@ class Facture(Base):
 class FactureDet(Base):
     __tablename__ = "llx_facturedet"
     id = Column("rowid", Integer, primary_key=True)
-    total_ht = Column(Float)
-    total_ttc = Column(Float)
-    total_tva = Column(Float)
 
     fk_facture = Column(Integer, ForeignKey('llx_facture.rowid'))
     facture = relationship(
@@ -283,9 +271,6 @@ class FactureDet(Base):
 class FactureFournDet(Base):
     __tablename__ = "llx_facture_fourn_det"
     id = Column("rowid", Integer, primary_key=True)
-    total_ht = Column(Float)
-    total_ttc = Column(Float)
-    tva = Column(Float)
 
     fk_facture_fourn = Column(Integer, ForeignKey('llx_facture_fourn.rowid'))
     facture = relationship(

+ 36 - 19
himports/dolibarrAlchemyHledger.py

@@ -3,6 +3,8 @@ from __future__ import unicode_literals
 
 import settings
 
+import decimal
+
 from himports.dolibarrAlchemy import *
 
 
@@ -54,6 +56,10 @@ class HledgerEntry(object):
 
         return str(date.year)
 
+    @staticmethod
+    def _value(value):
+        return '{number:.{digits}f}'.format(number=value, digits=4)
+
 
 class HledgerJournal(object):
 
@@ -155,19 +161,20 @@ class HledgerBankEntry(HledgerEntry):
 
         s += "    %(account)s \t %(amount)s\n" % {
             'account': settings.get_ledger_account(ba_code),
-            'amount': -e.amount
+            'amount': self._value(-e.amount)
         }
         s += "    %(account)s \t %(amount)s\n" % {
             'account': settings.get_ledger_account(third_code),
-            'amount': e.amount
+            'amount': self._value(e.amount)
         }
+        
         if e.url_payment_supplier:
             for f in e.url_payment_supplier.payment_supplier.factures:
                 tvas = HledgerSupplierEntry.get_tva_paiement_amounts(f.facture, journal="bank")
                 for k in tvas:
                     s += "    %(account_tva)s \t %(amount_tva)s\n" % {
                         'account_tva': settings.get_ledger_account(k),
-                        'amount_tva': tvas[k]
+                        'amount_tva': self._value(tvas[k] * (f.amount / f.facture.total_ttc))
                     }
         elif e.url_payment:
             for f in e.url_payment.payment.factures:
@@ -175,7 +182,7 @@ class HledgerBankEntry(HledgerEntry):
                 for k in tvas:
                     s += "    %(account_tva)s \t %(amount_tva)s\n" % {
                         'account_tva': settings.get_ledger_account(k),
-                        'amount_tva': tvas[k]
+                        'amount_tva': self._value(tvas[k] * (f.amount / f.facture.total_ttc))
                     }
         else:
             pass
@@ -242,7 +249,11 @@ class HledgerFactureEntry(HledgerEntry):
     
     @classmethod
     def get_tva_regul_account(cls, ed):
-        return settings.get('PC_REFS')['tva_regul']
+        tx = int(float(ed.tva_tx) * 100)
+        
+        key = "tva_regul_%s" % (tx,)
+
+        return settings.get('PC_REFS')[key]
 
     # Calcul de la tva à décaisser à paiement de la facture
     #
@@ -301,23 +312,23 @@ class HledgerSupplierEntry(HledgerFactureEntry):
         }
 
         s_code = self.get_supplier_code(self.e)
-        s += "    %(compte_tiers)s    %(amount_ttc)s\n" % {
+        s += "    %(compte_tiers)s \t %(amount_ttc)s\n" % {
             'compte_tiers': settings.get_ledger_account(s_code),
-            'amount_ttc': e.total_ttc,
+            'amount_ttc': self._value(e.total_ttc),
         }
 
         for ed in e.details:
             p_code = self.get_product_account_code(ed)
-            s += "    %(compte_produit)s   %(amount_ht)s\n" % {
+            s += "    %(compte_produit)s \t %(amount_ht)s\n" % {
                 'compte_produit': settings.get_ledger_account(p_code),
-                'amount_ht': -ed.total_ht
+                'amount_ht': self._value(-ed.total_ht)
             }
         
         tvas = self.get_tva_facture_amounts(self.e, journal="supplier")
         for k in tvas:
-            s += "    %(compte_tva)s  %(amount_tva)s\n" % {
+            s += "    %(compte_tva)s \t %(amount_tva)s\n" % {
                 'compte_tva': settings.get_ledger_account(k),
-                'amount_tva': tvas[k],
+                'amount_tva': self._value(tvas[k]),
             }
 
         return s
@@ -325,10 +336,14 @@ class HledgerSupplierEntry(HledgerFactureEntry):
     @classmethod
     def get_tva_account(cls, ed):
         p_code = cls.get_product_account_code(ed)
+        tx = int(float(ed.tva_tx) * 100)
+        
         if p_code.startswith("2"):
-            tva_account = settings.get('PC_REFS')['tva_deductible']
+            prefix = 'tva_deductible'
         else:
-            tva_account = settings.get('PC_REFS')['tva_deductible_immo']
+            prefix = 'tva_deductible_immo'
+        key = "%s_%s" % (prefix, tx)
+        tva_account = settings.get('PC_REFS')[key]
         return tva_account
 
     @classmethod
@@ -369,7 +384,7 @@ class HledgerSellEntry(HledgerFactureEntry):
         s_code = self.get_client_code(self.e)
         s += "    %(compte_tiers)s    %(amount_ttc)s\n" % {
             'compte_tiers': settings.get_ledger_account(s_code),
-            'amount_ttc': -e.total_ttc,
+            'amount_ttc': self._value(-e.total_ttc),
 
         }
         
@@ -378,7 +393,7 @@ class HledgerSellEntry(HledgerFactureEntry):
             p_code = self.get_product_account_code(ed)
             s += "    %(compte_produit)s   %(amount_ht)s\n" % {
                 'compte_produit': settings.get_ledger_account(p_code),
-                'amount_ht': ed.total_ht
+                'amount_ht': self._value(ed.total_ht)
             }
 
         # lignes pour la tva
@@ -386,14 +401,16 @@ class HledgerSellEntry(HledgerFactureEntry):
         for k in tvas:
             s += "    %(compte_tva)s  %(amount_tva)s\n" % {
                 'compte_tva': settings.get_ledger_account(k),
-                'amount_tva': tvas[k],
+                'amount_tva': self._value(tvas[k]),
             }
 
         return s
     
     @classmethod
     def get_tva_account(cls, ed):
-        return settings.get('PC_REFS')['tva_collecte']
+        tx = int(float(ed.tva_tx) * 100)
+        key = "tva_collecte_%s" % (tx,)
+        return settings.get('PC_REFS')[key]
 
     def getMissingPC(self):
         e = self.e
@@ -499,12 +516,12 @@ class HledgerSocialEntry(HledgerEntry):
 
         s += "    %(account)s \t %(amount)s\n" % {
             'account': settings.get_ledger_account(third_code),
-            'amount': e.amount
+            'amount': self._value(e.amount)
         }
 
         s += "    %(account)s \t %(amount)s\n" % {
             'account': settings.get_ledger_account(s_code),
-            'amount': -e.amount
+            'amount': self._value(-e.amount)
         }
 
         return s