Browse Source

add the ability to disable value-added taxes

Philippe Le Brouster 7 years ago
parent
commit
ee3b1c3839
3 changed files with 71 additions and 46 deletions
  1. 1 0
      himport.conf.template
  2. 66 44
      himports/dolibarrAlchemyHledger.py
  3. 4 2
      himports/settings.py

+ 1 - 0
himport.conf.template

@@ -44,6 +44,7 @@ ACCOUNTING_YEARS = {
 
 #
 # TVA_TYPE : Sort of value-added tax. Possible values :
+              - 'none' : the value added tax is not handled.
 #             - 'standard' : the value added tax is on delivery for goods (billing date), on payment for services (payment date).
 #             - 'service_sur_debit' : the value added tax is on delivery for goods (billing date), and on billing date for services.
 TVA_TYPE = "standard"

+ 66 - 44
himports/dolibarrAlchemyHledger.py

@@ -217,25 +217,25 @@ class HledgerBankEntry(HledgerEntry):
             'account': settings.get_ledger_account(third_code),
             'amount': self._value(e.amount)
         }
-
-        if e.url_payment_supplier:
-            for f in e.url_payment_supplier.payment_supplier.factures:
-                tvas = HledgerSupplierEntry.get_tva_payment_amounts(self.dolibarr_alchemy, 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': self._value(tvas[k] * (f.amount / f.facture.total_ttc))
-                    }
-        elif e.url_payment:
-            for f in e.url_payment.payment.factures:
-                tvas = HledgerSellEntry.get_tva_payment_amounts(self.dolibarr_alchemy, 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': self._value(tvas[k] * (f.amount / f.facture.total_ttc))
-                    }
-        else:
-            pass
+        if self.tva_type != 'none':
+            if e.url_payment_supplier:
+                for f in e.url_payment_supplier.payment_supplier.factures:
+                    tvas = HledgerSupplierEntry.get_tva_payment_amounts(self.dolibarr_alchemy, 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': self._value(tvas[k] * (f.amount / f.facture.total_ttc))
+                        }
+            elif e.url_payment:
+                for f in e.url_payment.payment.factures:
+                    tvas = HledgerSellEntry.get_tva_payment_amounts(self.dolibarr_alchemy, 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': self._value(tvas[k] * (f.amount / f.facture.total_ttc))
+                        }
+            else:
+                pass
 
         return s
 
@@ -382,19 +382,30 @@ class HledgerSupplierEntry(HledgerBillingEntry):
             'amount_ttc': self._value(e.total_ttc),
         }
 
-        for ed in e.details:
-            p_code = self.get_product_account_code(ed)
-            s += "    %(compte_produit)s \t %(amount_ht)s\n" % {
-                'compte_produit': settings.get_ledger_account(p_code),
-                'amount_ht': self._value(-ed.total_ht)
-            }
-
-        tvas = self.get_tva_billing_amounts(self.dolibarr_alchemy, self.e, journal="supplier")
-        for k in tvas:
-            s += "    %(compte_tva)s \t %(amount_tva)s\n" % {
-                'compte_tva': settings.get_ledger_account(k),
-                'amount_tva': self._value(tvas[k]),
-            }
+        # lignes compte fournisseur
+        if self.tva_type == 'none':
+            for ed in e.details:
+                p_code = self.get_product_account_code(ed)
+                s += "    %(compte_produit)s \t %(amount_ttc)s\n" % {
+                    'compte_produit': settings.get_ledger_account(p_code),
+                    'amount_ttc': self._value(-ed.total_ttc)
+                }
+        else:
+            for ed in e.details:
+                p_code = self.get_product_account_code(ed)
+                s += "    %(compte_produit)s \t %(amount_ht)s\n" % {
+                    'compte_produit': settings.get_ledger_account(p_code),
+                    'amount_ht': self._value(-ed.total_ht)
+                }
+
+        # value-added tax
+        if self.tva_type != 'none':
+            tvas = self.get_tva_billing_amounts(self.dolibarr_alchemy, self.e, journal="supplier")
+            for k in tvas:
+                s += "    %(compte_tva)s \t %(amount_tva)s\n" % {
+                    'compte_tva': settings.get_ledger_account(k),
+                    'amount_tva': self._value(tvas[k]),
+                }
 
         return s
 
@@ -469,20 +480,31 @@ class HledgerSellEntry(HledgerBillingEntry):
         }
 
         # lignes pour compte de produits
-        for ed in e.details:
-            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': self._value(ed.total_ht)
-            }
+        if self.tva_type == 'none':
+            for ed in e.details:
+                p_code = self.get_product_account_code(ed)
+
+                s += "    %(compte_produit)s   %(amount_ttc)s\n" % {
+                    'compte_produit': settings.get_ledger_account(p_code),
+                    'amount_ttc': self._value(ed.total_ttc)
+                }
+        else:
+            for ed in e.details:
+                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': self._value(ed.total_ht)
+                }
 
         # lignes pour la tva
-        tvas = self.get_tva_billing_amounts(self.dolibarr_alchemy, self.e, journal="sell")
-        for k in tvas:
-            s += "    %(compte_tva)s  %(amount_tva)s\n" % {
-                'compte_tva': settings.get_ledger_account(k),
-                'amount_tva': self._value(tvas[k]),
-            }
+        if self.tva_type != 'none':
+            tvas = self.get_tva_billing_amounts(self.dolibarr_alchemy, self.e, journal="sell")
+            for k in tvas:
+                s += "    %(compte_tva)s  %(amount_tva)s\n" % {
+                    'compte_tva': settings.get_ledger_account(k),
+                    'amount_tva': self._value(tvas[k]),
+                }
 
         return s
 

+ 4 - 2
himports/settings.py

@@ -28,6 +28,8 @@ def get_ledger_account(code):
 
 
 __settings = {}
+
+
 for conf_file in CONF_FILES:
     if os.path.isfile(conf_file):
         with open(conf_file) as f:
@@ -55,5 +57,5 @@ if 'ACCOUNTING_YEARS' in __settings:
         ) for (year, dbegin, dend) in __settings['ACCOUNTING_YEARS']]
 
 if 'TVA_TYPE' not in __settings or\
-        __settings['TVA_TYPE'] not in ["standard", "service_sur_debit"]:
-    raise Exception("need TVA_TYPE settings either: standard | service_sur_debit")
+        __settings['TVA_TYPE'] not in ["standard", "service_sur_debit", "none"]:
+    raise Exception("need TVA_TYPE settings either: standard | service_sur_debit | none")