diff --git a/addons/account/report/partner_balance.py b/addons/account/report/partner_balance.py
index acb0a552e37..3b8ecd6ec10 100644
--- a/addons/account/report/partner_balance.py
+++ b/addons/account/report/partner_balance.py
@@ -42,12 +42,18 @@ class partner_balance(report_sxw.rml_parse):
'sum_scredit': self._sum_scredit,
'solde_debit': self._solde_balance_debit,
'solde_credit': self._solde_balance_credit,
+ 'get_company': self._get_company,
+ 'get_currency': self._get_currency,
})
def preprocess(self, objects, data, ids):
- self.cr.execute('select distinct partner_id from account_move_line where partner_id is not null and date>=%s and date<=%s and period_id in (SELECT id FROM account_period WHERE fiscalyear_id=%d)', (data['form']['date1'], data['form']['date2'], data['form']['fiscalyear']))
+ self.cr.execute('select distinct line.partner_id \
+ from account_move_line AS line, account_account AS account \
+ where line.partner_id is not null and line.date>=%s and line.date<=%s \
+ and line.period_id in (SELECT id FROM account_period WHERE fiscalyear_id=%d) \
+ AND line.account_id = account.id AND account.company_id = %d', (data['form']['date1'], data['form']['date2'], data['form']['fiscalyear'], data['form']['company_id']))
new_ids = [id for (id,) in self.cr.fetchall()]
- self.cr.execute("SELECT a.id FROM account_account a LEFT JOIN account_account_type t ON (a.type=t.code) WHERE t.partner_account=TRUE")
+ self.cr.execute("SELECT a.id FROM account_account a LEFT JOIN account_account_type t ON (a.type=t.code) WHERE t.partner_account=TRUE AND a.company_id = %d", (data['form']['company_id'],))
self.account_ids = ','.join([str(a) for (a,) in self.cr.fetchall()])
self.partner_ids = ','.join(map(str, new_ids))
objects = self.pool.get('res.partner').browse(self.cr, self.uid, new_ids)
@@ -168,6 +174,12 @@ class partner_balance(report_sxw.rml_parse):
def _solde_balance_credit(self):
debit, credit = self._sum_debit(), self._sum_credit()
return credit > debit and credit - debit
-
-report_sxw.report_sxw('report.account.partner.balance', 'res.partner', 'addons/account/report/partner_balance.rml',parser=partner_balance)
+
+ def _get_company(self, form):
+ return pooler.get_pool(self.cr.dbname).get('res.company').browse(self.cr, self.uid, form['company_id']).name
+
+ def _get_currency(self, form):
+ return pooler.get_pool(self.cr.dbname).get('res.company').browse(self.cr, self.uid, form['company_id']).currency_id.name
+
+report_sxw.report_sxw('report.account.partner.balance', 'res.partner', 'addons/account/report/partner_balance.rml',parser=partner_balance, header=False)
diff --git a/addons/account/report/partner_balance.rml b/addons/account/report/partner_balance.rml
index cb429bbebaf..8611c37e7d7 100644
--- a/addons/account/report/partner_balance.rml
+++ b/addons/account/report/partner_balance.rml
@@ -44,18 +44,18 @@
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
@@ -76,101 +76,101 @@
Third party balance
- From [[ data['form']['date1'] ]]
- to [[ data['form']['date2'] ]]
+ From [[ data['form']['date1'] ]]
+ to [[ data['form']['date2'] ]]
|
|
- [[ company.name ]]
+ [[ get_company(data['form']) ]]
|
-
+
|
- Currency: [[ company.currency_id.name ]]
+ Currency: [[ get_currency(data['form']) ]]
|
- Printing date: [[ time.strftime('%Y-%m-%d') ]] at [[ time.strftime('%H:%M:%S') ]]
-
+ Printing date: [[ time.strftime('%Y-%m-%d') ]] at [[ time.strftime('%H:%M:%S') ]]
+
|
- Account number
+ Account number
|
- Account name
+ Account name
|
- Transactions
+ Transactions
|
- Balances
+ Balances
|
- In dispute
+ In dispute
|
-
+
|
-
+
|
- Debit
+ Debit
|
- Credit
+ Credit
|
- Debit
+ Debit
|
- Credit
+ Credit
|
-
+
|
-
+
|
- [[ repeatIn(lines(), 'a') ]][[ a['ref'] ]]
+ [[ repeatIn(lines(), 'a') ]][[ a['ref'] ]]
|
- [[ a['name'] ]]
+ [[ a['name'] ]]
|
- [[ '%.2f' % a['debit'] ]]
+ [[ '%.2f' % a['debit'] ]]
|
- [[ '%.2f' % a['credit'] ]]
+ [[ '%.2f' % a['credit'] ]]
|
- [[ '%.2f' % a['sdebit'] ]]
+ [[ '%.2f' % a['sdebit'] ]]
|
- [[ '%.2f' % a['scredit'] ]]
+ [[ '%.2f' % a['scredit'] ]]
|
- [[ '%.2f' % (a['enlitige'] or 0.0) ]]
+ [[ '%.2f' % (a['enlitige'] or 0.0) ]]
|
@@ -180,53 +180,53 @@
|
- Grand total
+ Grand total
|
- [[ '%.2f' % sum_debit() ]]
+ [[ '%.2f' % sum_debit() ]]
|
- [[ '%.2f' % sum_credit() ]]
+ [[ '%.2f' % sum_credit() ]]
|
- [[ '%.2f' % sum_sdebit() ]]
+ [[ '%.2f' % sum_sdebit() ]]
|
- [[ '%.2f' % sum_scredit() ]]
+ [[ '%.2f' % sum_scredit() ]]
|
- [[ '%.2f' % sum_litige() ]]
+ [[ '%.2f' % sum_litige() ]]
|
|
- Balance
+ Balance
|
-
+
|
-
+
|
- [[ '%.2f' % solde_debit() ]]
+ [[ '%.2f' % solde_debit() ]]
|
- [[ '%.2f' % solde_credit() ]]
+ [[ '%.2f' % solde_credit() ]]
|
-
+
|
-
-
+
+
diff --git a/addons/account/wizard/wizard_partner_balance_report.py b/addons/account/wizard/wizard_partner_balance_report.py
index d7c6a90306c..0112639b86c 100644
--- a/addons/account/wizard/wizard_partner_balance_report.py
+++ b/addons/account/wizard/wizard_partner_balance_report.py
@@ -31,13 +31,16 @@ import pooler
dates_form = '''
'''
dates_fields = {
+ 'company_id': {'string': 'Company', 'type': 'many2one', 'relation': 'res.company', 'required': True},
'fiscalyear': {'string': 'Fiscal year', 'type': 'many2one', 'relation': 'account.fiscalyear', 'required': True},
'date1': {'string':'Start of period', 'type':'date', 'required':True, 'default': lambda *a: time.strftime('%Y-01-01')},
'date2': {'string':'End of period', 'type':'date', 'required':True, 'default': lambda *a: time.strftime('%Y-%m-%d')},
@@ -47,6 +50,14 @@ class wizard_report(wizard.interface):
def _get_defaults(self, cr, uid, data, context):
fiscalyear_obj = pooler.get_pool(cr.dbname).get('account.fiscalyear')
data['form']['fiscalyear'] = fiscalyear_obj.find(cr, uid)
+
+ user = pooler.get_pool(cr.dbname).get('res.users').browse(cr, uid, uid, context=context)
+ if user.company_id:
+ company_id = user.company_id.id
+ else:
+ company_id = pooler.get_pool(cr.dbname).get('res.company').search(cr, uid, [('parent_id', '=', False)])[0]
+ data['form']['company_id'] = company_id
+
return data['form']
states = {