Browse Source

[ADD] initialize wizard from context

pull/512/head
Iryna Vushnevska 6 years ago
committed by Iryna Vyshnevska
parent
commit
5919a538e4
  1. 17
      account_financial_report/tests/test_general_ledger.py
  2. 16
      account_financial_report/tests/test_open_items.py
  3. 20
      account_financial_report/wizard/general_ledger_wizard.py
  4. 20
      account_financial_report/wizard/open_items_wizard.py

17
account_financial_report/tests/test_general_ledger.py

@ -493,3 +493,20 @@ class TestGeneralLedgerReport(common.TransactionCase):
self.assertEqual(lines['unaffected'].final_debit, 500) self.assertEqual(lines['unaffected'].final_debit, 500)
self.assertEqual(lines['unaffected'].final_credit, 0) self.assertEqual(lines['unaffected'].final_credit, 0)
self.assertEqual(lines['unaffected'].final_balance, 500) 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)

16
account_financial_report/tests/test_open_items.py

@ -39,3 +39,19 @@ class TestOpenItems(a_t_f_c.AbstractTestForeignCurrency):
{'hide_account_at_0': True}, {'hide_account_at_0': True},
{'only_posted_moves': True, '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/wizard/general_ledger_wizard.py

@ -58,6 +58,7 @@ class GeneralLedgerReportWizard(models.TransientModel):
partner_ids = fields.Many2many( partner_ids = fields.Many2many(
comodel_name='res.partner', comodel_name='res.partner',
string='Filter partners', string='Filter partners',
default=lambda self: self._default_partners(),
) )
analytic_tag_ids = fields.Many2many( analytic_tag_ids = fields.Many2many(
comodel_name='account.analytic.tag', comodel_name='account.analytic.tag',
@ -80,9 +81,26 @@ class GeneralLedgerReportWizard(models.TransientModel):
string='Show foreign currency', string='Show foreign currency',
help='Display foreign currency for move lines, unless ' help='Display foreign currency for move lines, unless '
'account currency is not setup through chart of accounts ' 'account currency is not setup through chart of accounts '
'will display initial and final balance in that currency.'
'will display initial and final balance in that currency.',
default=lambda self: self._default_foreign_currency(),
) )
def _default_foreign_currency(self):
return self.env.user.has_group('base.group_multi_currency')
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') @api.depends('date_from')
def _compute_fy_start_date(self): def _compute_fy_start_date(self):
for wiz in self.filtered('date_from'): for wiz in self.filtered('date_from'):

20
account_financial_report/wizard/open_items_wizard.py

@ -44,14 +44,32 @@ class OpenItemsReportWizard(models.TransientModel):
partner_ids = fields.Many2many( partner_ids = fields.Many2many(
comodel_name='res.partner', comodel_name='res.partner',
string='Filter partners', string='Filter partners',
default=lambda self: self._default_partners(),
) )
foreign_currency = fields.Boolean( foreign_currency = fields.Boolean(
string='Show foreign currency', string='Show foreign currency',
help='Display foreign currency for move lines, unless ' help='Display foreign currency for move lines, unless '
'account currency is not setup through chart of accounts ' 'account currency is not setup through chart of accounts '
'will display initial and final balance in that currency.'
'will display initial and final balance in that currency.',
default=lambda self: self._default_foreign_currency(),
) )
def _default_foreign_currency(self):
return self.env.user.has_group('base.group_multi_currency')
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('company_id') @api.onchange('company_id')
def onchange_company_id(self): def onchange_company_id(self):
"""Handle company change.""" """Handle company change."""

Loading…
Cancel
Save