Browse Source

[ADD] initialize wizard from context

pull/508/head
Iryna Vyshnevska 6 years ago
parent
commit
1329d752d9
  1. 17
      account_financial_report_qweb/tests/test_general_ledger.py
  2. 17
      account_financial_report_qweb/tests/test_open_items.py
  3. 20
      account_financial_report_qweb/wizard/general_ledger_wizard.py
  4. 20
      account_financial_report_qweb/wizard/open_items_wizard.py

17
account_financial_report_qweb/tests/test_general_ledger.py

@ -499,3 +499,20 @@ class TestGeneralLedgerReport(common.TransactionCase):
self.assertEqual(lines['unaffected'].final_debit, 500)
self.assertEqual(lines['unaffected'].final_credit, 0)
self.assertEqual(lines['unaffected'].final_balance, 500)
def test_partner_filter(self):
partner_1 = self.env.ref('base.res_partner_1')
partner_2 = self.env.ref('base.res_partner_2')
partner_3 = self.env.ref('base.res_partner_3')
partner_4 = self.env.ref('base.res_partner_4')
partner_1.write({'is_company': False,
'parent_id': partner_2.id})
partner_3.write({'is_company': False})
expected_list = [partner_2.id, partner_3.id, partner_4.id]
context = {'active_ids':
[partner_1.id, partner_2.id, partner_3.id, partner_4.id],
'active_model': 'res.partner'}
wizard = self.env["general.ledger.report.wizard"].with_context(context)
self.assertEqual(wizard._default_partners(), expected_list)

17
account_financial_report_qweb/tests/test_open_items.py

@ -40,3 +40,20 @@ class TestOpenItems(a_t_f_c.AbstractTestForeignCurrency):
{'hide_account_at_0': True},
{'only_posted_moves': True, 'hide_account_at_0': True},
]
def test_partner_filter(self):
partner_1 = self.env.ref('base.res_partner_1')
partner_2 = self.env.ref('base.res_partner_2')
partner_3 = self.env.ref('base.res_partner_3')
partner_4 = self.env.ref('base.res_partner_4')
partner_1.write({'is_company': False,
'parent_id': partner_2.id})
partner_3.write({'is_company': False})
expected_list = [partner_2.id, partner_3.id, partner_4.id]
context = {'active_ids':
[partner_1.id, partner_2.id, partner_3.id, partner_4.id],
'active_model': 'res.partner'}
wizard = self.env["open.items.report.wizard"].with_context(context)
self.assertEqual(wizard._default_partners(), expected_list)

20
account_financial_report_qweb/wizard/general_ledger_wizard.py

@ -55,6 +55,7 @@ class GeneralLedgerReportWizard(models.TransientModel):
partner_ids = fields.Many2many(
comodel_name='res.partner',
string='Filter partners',
default=lambda self: self._default_partners(),
)
journal_ids = fields.Many2many(
comodel_name="account.journal",
@ -71,6 +72,7 @@ class GeneralLedgerReportWizard(models.TransientModel):
)
foreign_currency = fields.Boolean(
string='Show foreign currency',
default=lambda self: self._default_foreign_currency(),
help='Display foreign currency for move lines, unless '
'account currency is not setup through chart of accounts '
'will display initial and final balance in that currency.'
@ -80,6 +82,24 @@ class GeneralLedgerReportWizard(models.TransientModel):
string='Filter accounts',
)
def _default_foreign_currency(self):
if self.env.user.has_group('base.group_multi_currency'):
return True
def _default_partners(self):
context = self.env.context
if context.get('active_ids') and context.get('active_model') \
== 'res.partner':
partner_ids = context['active_ids']
corp_partners = self.env['res.partner'].browse(partner_ids). \
filtered(lambda p: p.parent_id)
partner_ids = set(partner_ids) - set(corp_partners.ids)
partner_ids |= set(corp_partners.mapped('parent_id.id'))
return list(partner_ids)
@api.depends('date_from')
def _compute_fy_start_date(self):
for wiz in self.filtered('date_from'):

20
account_financial_report_qweb/wizard/open_items_wizard.py

@ -44,9 +44,11 @@ class OpenItemsReportWizard(models.TransientModel):
partner_ids = fields.Many2many(
comodel_name='res.partner',
string='Filter partners',
default=lambda self: self._default_partners(),
)
foreign_currency = fields.Boolean(
string='Show foreign currency',
default=lambda self: self._default_foreign_currency(),
help='Display foreign currency for move lines, unless '
'account currency is not setup through chart of accounts '
'will display initial and final balance in that currency.'
@ -77,6 +79,24 @@ class OpenItemsReportWizard(models.TransientModel):
('company_id', '=', False)]
return res
def _default_foreign_currency(self):
if self.env.user.has_group('base.group_multi_currency'):
return True
def _default_partners(self):
context = self.env.context
if context.get('active_ids') and context.get('active_model')\
== 'res.partner':
partner_ids = context['active_ids']
corp_partners = self.env['res.partner'].browse(partner_ids).\
filtered(lambda p: p.parent_id)
partner_ids = set(partner_ids) - set(corp_partners.ids)
partner_ids |= set(corp_partners.mapped('parent_id.id'))
return list(partner_ids)
@api.onchange('receivable_accounts_only', 'payable_accounts_only')
def onchange_type_accounts_only(self):
"""Handle receivable/payable accounts only change."""

Loading…
Cancel
Save