|
@@ -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
|