diff --git a/addons/im_livechat/report/im_livechat_report_operator_views.xml b/addons/im_livechat/report/im_livechat_report_operator_views.xml
index 677191cf4b5..a7b4d271cd9 100644
--- a/addons/im_livechat/report/im_livechat_report_operator_views.xml
+++ b/addons/im_livechat/report/im_livechat_report_operator_views.xml
@@ -36,7 +36,6 @@
-
diff --git a/addons/l10n_fr_fec/wizard/account_fr_fec.py b/addons/l10n_fr_fec/wizard/account_fr_fec.py
index 5b5bcc0fc88..237f8f06162 100644
--- a/addons/l10n_fr_fec/wizard/account_fr_fec.py
+++ b/addons/l10n_fr_fec/wizard/account_fr_fec.py
@@ -170,8 +170,9 @@ class AccountFrFec(models.TransientModel):
'''
sql_query += '''
- GROUP BY aml.account_id
+ GROUP BY aml.account_id, aat.type
HAVING sum(aml.balance) != 0
+ AND aat.type not in ('receivable', 'payable')
'''
formatted_date_from = self.date_from.replace('-', '')
date_from = datetime.strptime(self.date_from, DEFAULT_SERVER_DATE_FORMAT)
@@ -209,6 +210,64 @@ class AccountFrFec(models.TransientModel):
unaffected_earnings_results[5] = unaffected_earnings_account.name
w.writerow([s.encode("utf-8") for s in unaffected_earnings_results])
+ # INITIAL BALANCE - receivable/payable
+ sql_query = '''
+ SELECT
+ 'OUV' AS JournalCode,
+ 'Balance initiale' AS JournalLib,
+ 'OUVERTURE/' || %s AS EcritureNum,
+ %s AS EcritureDate,
+ MIN(aa.code) AS CompteNum,
+ replace(MIN(aa.name), '|', '/') AS CompteLib,
+ CASE WHEN rp.ref IS null OR rp.ref = ''
+ THEN COALESCE('ID ' || rp.id, '')
+ ELSE rp.ref
+ END
+ AS CompAuxNum,
+ COALESCE(replace(rp.name, '|', '/'), '') AS CompAuxLib,
+ '-' AS PieceRef,
+ %s AS PieceDate,
+ '/' AS EcritureLib,
+ replace(CASE WHEN sum(aml.balance) <= 0 THEN '0,00' ELSE to_char(SUM(aml.balance), '999999999999999D99') END, '.', ',') AS Debit,
+ replace(CASE WHEN sum(aml.balance) >= 0 THEN '0,00' ELSE to_char(-SUM(aml.balance), '999999999999999D99') END, '.', ',') AS Credit,
+ '' AS EcritureLet,
+ '' AS DateLet,
+ %s AS ValidDate,
+ '' AS Montantdevise,
+ '' AS Idevise,
+ MIN(aa.id) AS CompteID
+ FROM
+ account_move_line aml
+ LEFT JOIN account_move am ON am.id=aml.move_id
+ LEFT JOIN res_partner rp ON rp.id=aml.partner_id
+ JOIN account_account aa ON aa.id = aml.account_id
+ LEFT JOIN account_account_type aat ON aa.user_type_id = aat.id
+ WHERE
+ am.date < %s
+ AND am.company_id = %s
+ AND aat.include_initial_balance = 't'
+ AND (aml.debit != 0 OR aml.credit != 0)
+ '''
+
+ # For official report: only use posted entries
+ if self.export_type == "official":
+ sql_query += '''
+ AND am.state = 'posted'
+ '''
+
+ sql_query += '''
+ GROUP BY aml.account_id, aat.type, rp.ref, rp.id
+ HAVING sum(aml.balance) != 0
+ AND aat.type in ('receivable', 'payable')
+ '''
+ self._cr.execute(
+ sql_query, (formatted_date_year, formatted_date_from, formatted_date_from, formatted_date_from, self.date_from, company.id))
+
+ for row in self._cr.fetchall():
+ listrow = list(row)
+ account_id = listrow.pop()
+ w.writerow([s.encode("utf-8") for s in listrow])
+
# LINES
sql_query = '''
SELECT