Browse Source

Black, isort, etc...

pull/619/head
Andrea 5 years ago
parent
commit
e5f5de9df5
  1. 2
      .isort.cfg
  2. 11
      account_tax_balance/__manifest__.py
  3. 56
      account_tax_balance/models/account_move.py
  4. 14
      account_tax_balance/models/account_move_line.py
  5. 138
      account_tax_balance/models/account_tax.py
  6. 309
      account_tax_balance/tests/test_account_tax_balance.py
  7. 84
      account_tax_balance/wizard/open_tax_balances.py

2
.isort.cfg

@ -9,4 +9,4 @@ line_length=88
known_odoo=odoo
known_odoo_addons=odoo.addons
sections=FUTURE,STDLIB,THIRDPARTY,ODOO,ODOO_ADDONS,FIRSTPARTY,LOCALFOLDER
known_third_party=
known_third_party=dateutil

11
account_tax_balance/__manifest__.py

@ -10,19 +10,14 @@
"category": "Invoices & Payments",
"website": "https://github.com/OCA/account-financial-reporting",
"author": "Agile Business Group, Therp BV, Tecnativa, ACSONE SA/NV, "
"Odoo Community Association (OCA)",
"Odoo Community Association (OCA)",
"license": "AGPL-3",
"installable": True,
"depends": [
"account",
"date_range",
],
"depends": ["account", "date_range"],
"data": [
"wizard/open_tax_balances_view.xml",
"views/account_move_view.xml",
"views/account_tax_view.xml",
],
"images": [
"images/tax_balance.png",
]
"images": ["images/tax_balance.png"],
}

56
account_tax_balance/models/account_move.py

@ -5,44 +5,48 @@ from odoo import api, fields, models
class AccountMove(models.Model):
_inherit = 'account.move'
_inherit = "account.move"
@api.model
def _selection_move_type(self):
return [
('other', 'Other'),
('liquidity', 'Liquidity'),
('receivable', 'Receivable'),
('receivable_refund', 'Receivable refund'),
('payable', 'Payable'),
('payable_refund', 'Payable refund'),
("other", "Other"),
("liquidity", "Liquidity"),
("receivable", "Receivable"),
("receivable_refund", "Receivable refund"),
("payable", "Payable"),
("payable_refund", "Payable refund"),
]
move_type = fields.Selection(
selection='_selection_move_type',
compute='_compute_move_type', store=True, readonly=True)
selection="_selection_move_type",
compute="_compute_move_type",
store=True,
readonly=True,
)
@api.depends(
'line_ids.account_id.internal_type', 'line_ids.balance',
'line_ids.account_id.user_type_id.type'
"line_ids.account_id.internal_type",
"line_ids.balance",
"line_ids.account_id.user_type_id.type",
)
def _compute_move_type(self):
def _balance_get(line_ids, internal_type):
return sum(line_ids.filtered(
lambda x: x.account_id.internal_type == internal_type).mapped(
'balance'))
return sum(
line_ids.filtered(
lambda x: x.account_id.internal_type == internal_type
).mapped("balance")
)
for move in self:
internal_types = move.line_ids.mapped('account_id.internal_type')
if 'liquidity' in internal_types:
move.move_type = 'liquidity'
elif 'payable' in internal_types:
balance = _balance_get(move.line_ids, 'payable')
move.move_type = (
'payable' if balance < 0 else 'payable_refund')
elif 'receivable' in internal_types:
balance = _balance_get(move.line_ids, 'receivable')
move.move_type = (
'receivable' if balance > 0 else 'receivable_refund')
internal_types = move.line_ids.mapped("account_id.internal_type")
if "liquidity" in internal_types:
move.move_type = "liquidity"
elif "payable" in internal_types:
balance = _balance_get(move.line_ids, "payable")
move.move_type = "payable" if balance < 0 else "payable_refund"
elif "receivable" in internal_types:
balance = _balance_get(move.line_ids, "receivable")
move.move_type = "receivable" if balance > 0 else "receivable_refund"
else:
move.move_type = 'other'
move.move_type = "other"

14
account_tax_balance/models/account_move_line.py

@ -6,17 +6,21 @@ from odoo import models
class AccountMoveLine(models.Model):
_inherit = 'account.move.line'
_inherit = "account.move.line"
def init(self):
res = super().init()
self._cr.execute("""
self._cr.execute(
"""
SELECT indexname FROM pg_indexes
WHERE indexname = 'account_move_line_date_tax_line_id_idx'
""")
"""
)
if not self._cr.fetchone():
self._cr.execute("""
self._cr.execute(
"""
CREATE INDEX account_move_line_date_tax_line_id_idx
ON account_move_line (date, tax_line_id)
""")
"""
)
return res

138
account_tax_balance/models/account_tax.py

@ -6,25 +6,17 @@ from odoo import _, api, fields, models
class AccountTax(models.Model):
_inherit = 'account.tax'
_inherit = "account.tax"
balance = fields.Float(
string="Total Balance", compute="_compute_balance",
)
base_balance = fields.Float(
string="Total Base Balance", compute="_compute_balance",
)
balance_regular = fields.Float(
string="Balance", compute="_compute_balance",
)
balance = fields.Float(string="Total Balance", compute="_compute_balance")
base_balance = fields.Float(string="Total Base Balance", compute="_compute_balance")
balance_regular = fields.Float(string="Balance", compute="_compute_balance")
base_balance_regular = fields.Float(
string="Base Balance", compute="_compute_balance",
)
balance_refund = fields.Float(
string="Balance Refund", compute="_compute_balance",
string="Base Balance", compute="_compute_balance"
)
balance_refund = fields.Float(string="Balance Refund", compute="_compute_balance")
base_balance_refund = fields.Float(
string="Base Balance Refund", compute="_compute_balance",
string="Base Balance Refund", compute="_compute_balance"
)
has_moves = fields.Boolean(
string="Has balance in period",
@ -35,10 +27,10 @@ class AccountTax(models.Model):
def get_context_values(self):
context = self.env.context
return (
context.get('from_date', fields.Date.context_today(self)),
context.get('to_date', fields.Date.context_today(self)),
context.get('company_ids', [self.env.user.company_id.id]),
context.get('target_move', 'posted'),
context.get("from_date", fields.Date.context_today(self)),
context.get("to_date", fields.Date.context_today(self)),
context.get("company_ids", [self.env.user.company_id.id]),
context.get("target_move", "posted"),
)
def _account_tax_ids_with_moves(self):
@ -71,8 +63,7 @@ class AccountTax(models.Model):
)
)
"""
self.env.cr.execute(
req, (company_ids, from_date, to_date, company_ids))
self.env.cr.execute(req, (company_ids, from_date, to_date, company_ids))
return [r[0] for r in self.env.cr.fetchall()]
def _compute_has_moves(self):
@ -82,129 +73,132 @@ class AccountTax(models.Model):
@api.model
def _is_unsupported_search_operator(self, operator):
return operator != '='
return operator != "="
@api.model
def _search_has_moves(self, operator, value):
if self._is_unsupported_search_operator(operator) or not value:
raise ValueError(_("Unsupported search operator"))
ids_with_moves = self._account_tax_ids_with_moves()
return [('id', 'in', ids_with_moves)]
return [("id", "in", ids_with_moves)]
def _compute_balance(self):
for tax in self:
tax.balance_regular = tax.compute_balance(
tax_or_base='tax', move_type='regular')
tax_or_base="tax", move_type="regular"
)
tax.base_balance_regular = tax.compute_balance(
tax_or_base='base', move_type='regular')
tax_or_base="base", move_type="regular"
)
tax.balance_refund = tax.compute_balance(
tax_or_base='tax', move_type='refund')
tax_or_base="tax", move_type="refund"
)
tax.base_balance_refund = tax.compute_balance(
tax_or_base='base', move_type='refund')
tax_or_base="base", move_type="refund"
)
tax.balance = tax.balance_regular + tax.balance_refund
tax.base_balance = (
tax.base_balance_regular + tax.base_balance_refund)
tax.base_balance = tax.base_balance_regular + tax.base_balance_refund
def get_target_type_list(self, move_type=None):
if move_type == 'refund':
return ['receivable_refund', 'payable_refund']
elif move_type == 'regular':
return ['receivable', 'payable', 'liquidity', 'other']
if move_type == "refund":
return ["receivable_refund", "payable_refund"]
elif move_type == "regular":
return ["receivable", "payable", "liquidity", "other"]
return []
def get_target_state_list(self, target_move="posted"):
if target_move == 'posted':
state = ['posted']
elif target_move == 'all':
state = ['posted', 'draft']
if target_move == "posted":
state = ["posted"]
elif target_move == "all":
state = ["posted", "draft"]
else:
state = []
return state
def get_move_line_partial_domain(self, from_date, to_date, company_ids):
return [
('date', '<=', to_date),
('date', '>=', from_date),
('company_id', 'in', company_ids),
("date", "<=", to_date),
("date", ">=", from_date),
("company_id", "in", company_ids),
]
def compute_balance(self, tax_or_base='tax', move_type=None):
def compute_balance(self, tax_or_base="tax", move_type=None):
self.ensure_one()
domain = self.get_move_lines_domain(
tax_or_base=tax_or_base, move_type=move_type)
tax_or_base=tax_or_base, move_type=move_type
)
# balance is debit - credit whereas on tax return you want to see what
# vat has to be paid so:
# VAT on sales (credit) - VAT on purchases (debit).
balance = self.env['account.move.line'].\
read_group(domain, ['balance'], [])[0]['balance']
balance = self.env["account.move.line"].read_group(domain, ["balance"], [])[0][
"balance"
]
return balance and -balance or 0
def get_balance_domain(self, state_list, type_list):
domain = [
('move_id.state', 'in', state_list),
('tax_line_id', '=', self.id),
('tax_exigible', '=', True)
("move_id.state", "in", state_list),
("tax_line_id", "=", self.id),
("tax_exigible", "=", True),
]
if type_list:
domain.append(('move_id.move_type', 'in', type_list))
domain.append(("move_id.move_type", "in", type_list))
return domain
def get_base_balance_domain(self, state_list, type_list):
domain = [
('move_id.state', 'in', state_list),
('tax_ids', 'in', self.id),
('tax_exigible', '=', True)
("move_id.state", "in", state_list),
("tax_ids", "in", self.id),
("tax_exigible", "=", True),
]
if type_list:
domain.append(('move_id.move_type', 'in', type_list))
domain.append(("move_id.move_type", "in", type_list))
return domain
def get_move_lines_domain(self, tax_or_base='tax', move_type=None):
from_date, to_date, company_ids, target_move = \
self.get_context_values()
def get_move_lines_domain(self, tax_or_base="tax", move_type=None):
from_date, to_date, company_ids, target_move = self.get_context_values()
state_list = self.get_target_state_list(target_move)
type_list = self.get_target_type_list(move_type)
domain = self.get_move_line_partial_domain(
from_date, to_date, company_ids)
domain = self.get_move_line_partial_domain(from_date, to_date, company_ids)
balance_domain = []
if tax_or_base == 'tax':
if tax_or_base == "tax":
balance_domain = self.get_balance_domain(state_list, type_list)
elif tax_or_base == 'base':
balance_domain = self.get_base_balance_domain(
state_list, type_list)
elif tax_or_base == "base":
balance_domain = self.get_base_balance_domain(state_list, type_list)
domain.extend(balance_domain)
return domain
def get_lines_action(self, tax_or_base='tax', move_type=None):
def get_lines_action(self, tax_or_base="tax", move_type=None):
domain = self.get_move_lines_domain(
tax_or_base=tax_or_base, move_type=move_type)
action = self.env.ref('account.action_account_moves_all_tree')
tax_or_base=tax_or_base, move_type=move_type
)
action = self.env.ref("account.action_account_moves_all_tree")
vals = action.read()[0]
vals['context'] = {}
vals['domain'] = domain
vals["context"] = {}
vals["domain"] = domain
return vals
def view_tax_lines(self):
self.ensure_one()
return self.get_lines_action(tax_or_base='tax')
return self.get_lines_action(tax_or_base="tax")
def view_base_lines(self):
self.ensure_one()
return self.get_lines_action(tax_or_base='base')
return self.get_lines_action(tax_or_base="base")
def view_tax_regular_lines(self):
self.ensure_one()
return self.get_lines_action(tax_or_base='tax', move_type='regular')
return self.get_lines_action(tax_or_base="tax", move_type="regular")
def view_base_regular_lines(self):
self.ensure_one()
return self.get_lines_action(tax_or_base='base', move_type='regular')
return self.get_lines_action(tax_or_base="base", move_type="regular")
def view_tax_refund_lines(self):
self.ensure_one()
return self.get_lines_action(tax_or_base='tax', move_type='refund')
return self.get_lines_action(tax_or_base="tax", move_type="refund")
def view_base_refund_lines(self):
self.ensure_one()
return self.get_lines_action(tax_or_base='base', move_type='refund')
return self.get_lines_action(tax_or_base="base", move_type="refund")

309
account_tax_balance/tests/test_account_tax_balance.py

@ -12,141 +12,167 @@ from odoo.fields import Date
from odoo.tests.common import HttpCase
@odoo.tests.tagged('post_install', '-at_install')
@odoo.tests.tagged("post_install", "-at_install")
class TestAccountTaxBalance(HttpCase):
def setUp(self):
super().setUp()
self.range_type = self.env['date.range.type'].create(
{'name': 'Fiscal year',
'company_id': False,
'allow_overlap': False})
self.range_generator = self.env['date.range.generator']
self.range_type = self.env["date.range.type"].create(
{"name": "Fiscal year", "company_id": False, "allow_overlap": False}
)
self.range_generator = self.env["date.range.generator"]
self.current_year = datetime.now().year
self.current_month = datetime.now().month
range_generator = self.range_generator.create({
'date_start': '%s-01-01' % self.current_year,
'name_prefix': '%s-' % self.current_year,
'type_id': self.range_type.id,
'duration_count': 1,
'unit_of_time': str(MONTHLY),
'count': 12})
range_generator = self.range_generator.create(
{
"date_start": "%s-01-01" % self.current_year,
"name_prefix": "%s-" % self.current_year,
"type_id": self.range_type.id,
"duration_count": 1,
"unit_of_time": str(MONTHLY),
"count": 12,
}
)
range_generator.action_apply()
self.range = self.env['date.range']
self.range = self.env["date.range"]
def test_tax_balance(self):
tax_account_id = self.env['account.account'].create({
'name': 'Tax Paid',
'code': 'TAXTEST',
'user_type_id': self.env.ref(
'account.data_account_type_current_liabilities'
).id,
}).id
tax = self.env['account.tax'].create({
'name': 'Tax 10.0%',
'amount': 10.0,
'amount_type': 'percent',
})
invoice_line_account_id = self.env['account.account'].create({
'user_type_id': self.env.ref(
'account.data_account_type_expenses'
).id,
'code': 'EXPTEST',
'name': 'Test expense account',
}).id
product = self.env.ref('product.product_product_4')
invoice = self.env['account.move'].create({
'partner_id': self.env.ref('base.res_partner_2').id,
'type': 'out_invoice',
'invoice_line_ids': [
(0, None, {
'product_id': product.id,
'quantity': 1.0,
'price_unit': 100.0,
'name': 'product that cost 100',
'account_id': invoice_line_account_id,
'tax_ids': [(6, 0, [tax.id])],
}),
]
})
tax_account_id = (
self.env["account.account"]
.create(
{
"name": "Tax Paid",
"code": "TAXTEST",
"user_type_id": self.env.ref(
"account.data_account_type_current_liabilities"
).id,
}
)
.id
)
tax = self.env["account.tax"].create(
{"name": "Tax 10.0%", "amount": 10.0, "amount_type": "percent"}
)
invoice_line_account_id = (
self.env["account.account"]
.create(
{
"user_type_id": self.env.ref(
"account.data_account_type_expenses"
).id,
"code": "EXPTEST",
"name": "Test expense account",
}
)
.id
)
product = self.env.ref("product.product_product_4")
invoice = self.env["account.move"].create(
{
"partner_id": self.env.ref("base.res_partner_2").id,
"type": "out_invoice",
"invoice_line_ids": [
(
0,
None,
{
"product_id": product.id,
"quantity": 1.0,
"price_unit": 100.0,
"name": "product that cost 100",
"account_id": invoice_line_account_id,
"tax_ids": [(6, 0, [tax.id])],
},
)
],
}
)
invoice._onchange_invoice_line_ids()
invoice._convert_to_write(invoice._cache)
self.assertEqual(invoice.state, 'draft')
self.assertEqual(invoice.state, "draft")
# change the state of invoice to open by clicking Validate button
invoice.action_post()
self.assertEqual(tax.base_balance, 100.)
self.assertEqual(tax.balance, 10.)
self.assertEqual(tax.base_balance_regular, 100.)
self.assertEqual(tax.balance_regular, 10.)
self.assertEqual(tax.base_balance_refund, 0.)
self.assertEqual(tax.balance_refund, 0.)
self.assertEqual(tax.base_balance, 100.0)
self.assertEqual(tax.balance, 10.0)
self.assertEqual(tax.base_balance_regular, 100.0)
self.assertEqual(tax.balance_regular, 10.0)
self.assertEqual(tax.base_balance_refund, 0.0)
self.assertEqual(tax.balance_refund, 0.0)
# testing wizard
current_range = self.range.search([
('date_start', '=', '%s-%s-01' % (
self.current_year, self.current_month))
])
wizard = self.env['wizard.open.tax.balances'].new({})
current_range = self.range.search(
[
(
"date_start",
"=",
"{}-{}-01".format(self.current_year, self.current_month),
)
]
)
wizard = self.env["wizard.open.tax.balances"].new({})
self.assertFalse(wizard.from_date)
self.assertFalse(wizard.to_date)
wizard = self.env['wizard.open.tax.balances'].new({
'date_range_id': current_range[0].id,
})
wizard = self.env["wizard.open.tax.balances"].new(
{"date_range_id": current_range[0].id}
)
self.assertEqual(wizard.from_date, current_range[0].date_start)
self.assertEqual(wizard.to_date, current_range[0].date_end)
action = wizard.open_taxes()
self.assertEqual(
action['context']['from_date'], current_range[0].date_start)
self.assertEqual(
action['context']['to_date'], current_range[0].date_end)
self.assertEqual(action["context"]["from_date"], current_range[0].date_start)
self.assertEqual(action["context"]["to_date"], current_range[0].date_end)
# exercise search has_moves = True
taxes = self.env['account.tax'].search([('has_moves', '=', True)])
taxes = self.env["account.tax"].search([("has_moves", "=", True)])
self.assertEqual(len(taxes), 1)
self.assertEqual(taxes[0].name, "Tax 10.0%")
# testing buttons
tax_action = tax.view_tax_lines()
base_action = tax.view_base_lines()
tax_action_move_lines = self.env['account.move.line'].\
search(tax_action['domain'])
tax_action_move_lines = self.env["account.move.line"].search(
tax_action["domain"]
)
self.assertTrue(invoice.line_ids & tax_action_move_lines)
self.assertEqual(
tax_action['xml_id'], 'account.action_account_moves_all_tree')
base_action_move_lines = self.env['account.move.line'].\
search(base_action['domain'])
self.assertEqual(tax_action["xml_id"], "account.action_account_moves_all_tree")
base_action_move_lines = self.env["account.move.line"].search(
base_action["domain"]
)
self.assertTrue(invoice.line_ids & base_action_move_lines)
self.assertEqual(
base_action['xml_id'], 'account.action_account_moves_all_tree')
self.assertEqual(base_action["xml_id"], "account.action_account_moves_all_tree")
# test specific method
state_list = tax.get_target_state_list(target_move='all')
self.assertEqual(state_list, ['posted', 'draft'])
state_list = tax.get_target_state_list(target_move='whatever')
state_list = tax.get_target_state_list(target_move="all")
self.assertEqual(state_list, ["posted", "draft"])
state_list = tax.get_target_state_list(target_move="whatever")
self.assertEqual(state_list, [])
product = self.env.ref('product.product_product_2')
refund = self.env['account.move'].create({
'partner_id': self.env.ref('base.res_partner_2').id,
'type': 'out_refund',
'invoice_line_ids': [
(0, None, {
'product_id': product.id,
'quantity': 1.0,
'price_unit': 25.0,
'name': 'returned product that cost 25',
'account_id': invoice_line_account_id,
'tax_ids': [(6, 0, [tax.id])],
}),
]
})
product = self.env.ref("product.product_product_2")
refund = self.env["account.move"].create(
{
"partner_id": self.env.ref("base.res_partner_2").id,
"type": "out_refund",
"invoice_line_ids": [
(
0,
None,
{
"product_id": product.id,
"quantity": 1.0,
"price_unit": 25.0,
"name": "returned product that cost 25",
"account_id": invoice_line_account_id,
"tax_ids": [(6, 0, [tax.id])],
},
)
],
}
)
refund._onchange_invoice_line_ids()
refund._convert_to_write(invoice._cache)
self.assertEqual(refund.state, 'draft')
self.assertEqual(refund.state, "draft")
# change the state of refund to open by clicking Validate button
refund.action_post()
@ -154,44 +180,67 @@ class TestAccountTaxBalance(HttpCase):
# force the _compute_balance() to be triggered
tax._compute_balance()
self.assertEqual(tax.base_balance, 75.)
self.assertEqual(tax.base_balance, 75.0)
self.assertEqual(tax.balance, 7.5)
self.assertEqual(tax.base_balance_regular, 100.)
self.assertEqual(tax.balance_regular, 10.)
self.assertEqual(tax.base_balance_refund, -25.)
self.assertEqual(tax.base_balance_regular, 100.0)
self.assertEqual(tax.balance_regular, 10.0)
self.assertEqual(tax.base_balance_refund, -25.0)
self.assertEqual(tax.balance_refund, -2.5)
# Taxes on liquidity type moves are included
tax_repartition_line = tax.invoice_repartition_line_ids\
.filtered(lambda line: line.repartition_type == 'tax')
liquidity_account_id = self.env['account.account'].search(
[('internal_type', '=', 'liquidity')], limit=1).id
move = self.env['account.move'].create({
'type': 'entry',
'date': Date.context_today(self.env.user),
'journal_id': self.env['account.journal'].search(
[('type', '=', 'bank')], limit=1).id,
'name': 'Test move',
'line_ids': [(0, 0, {
'account_id': liquidity_account_id,
'debit': 110,
'credit': 0,
'name': 'Bank Fees',
}), (0, 0, {
'account_id': invoice_line_account_id,
'debit': 0,
'credit': 100,
'name': 'Bank Fees',
'tax_ids': [(4, tax.id)]
}), (0, 0, {
'account_id': tax_account_id,
'debit': 0,
'credit': 10,
'name': 'Bank Fees',
'tax_repartition_line_id': tax_repartition_line.id,
})],
})
tax_repartition_line = tax.invoice_repartition_line_ids.filtered(
lambda line: line.repartition_type == "tax"
)
liquidity_account_id = (
self.env["account.account"]
.search([("internal_type", "=", "liquidity")], limit=1)
.id
)
move = self.env["account.move"].create(
{
"type": "entry",
"date": Date.context_today(self.env.user),
"journal_id": self.env["account.journal"]
.search([("type", "=", "bank")], limit=1)
.id,
"name": "Test move",
"line_ids": [
(
0,
0,
{
"account_id": liquidity_account_id,
"debit": 110,
"credit": 0,
"name": "Bank Fees",
},
),
(
0,
0,
{
"account_id": invoice_line_account_id,
"debit": 0,
"credit": 100,
"name": "Bank Fees",
"tax_ids": [(4, tax.id)],
},
),
(
0,
0,
{
"account_id": tax_account_id,
"debit": 0,
"credit": 10,
"name": "Bank Fees",
"tax_repartition_line_id": tax_repartition_line.id,
},
),
],
}
)
move.action_post()
tax.refresh()
self.assertEqual(tax.base_balance, 175.)
self.assertEqual(tax.base_balance, 175.0)
self.assertEqual(tax.balance, 17.5)

84
account_tax_balance/wizard/open_tax_balances.py

@ -5,29 +5,27 @@ from odoo import _, api, fields, models
class WizardOpenTaxBalances(models.TransientModel):
_name = 'wizard.open.tax.balances'
_description = 'Wizard Open Tax Balances'
_name = "wizard.open.tax.balances"
_description = "Wizard Open Tax Balances"
company_id = fields.Many2one(
'res.company', required=True,
default=lambda self: self.env.user.company_id)
"res.company", required=True, default=lambda self: self.env.user.company_id
)
from_date = fields.Date(
required=True,
store=True,
readonly=False,
compute='_compute_date_range')
required=True, store=True, readonly=False, compute="_compute_date_range"
)
to_date = fields.Date(
required=True, store=True, readonly=False, compute="_compute_date_range"
)
date_range_id = fields.Many2one("date.range")
target_move = fields.Selection(
[("posted", "All Posted Entries"), ("all", "All Entries")],
"Target Moves",
required=True,
store=True,
readonly=False,
compute='_compute_date_range')
date_range_id = fields.Many2one('date.range')
target_move = fields.Selection([
('posted', 'All Posted Entries'),
('all', 'All Entries'),
], 'Target Moves', required=True, default='posted')
default="posted",
)
@api.depends('date_range_id')
@api.depends("date_range_id")
def _compute_date_range(self):
for wizard in self:
if wizard.date_range_id:
@ -38,30 +36,44 @@ class WizardOpenTaxBalances(models.TransientModel):
def open_taxes(self):
self.ensure_one()
action = self.env.ref('account_tax_balance.action_tax_balances_tree')
action = self.env.ref("account_tax_balance.action_tax_balances_tree")
act_vals = action.read()[0]
# override action name doesn't work in v12 or v10
# we need to build a dynamic action on main keys
vals = {x: act_vals[x] for x in act_vals
if x in ('res_model', 'view_mode', 'domain',
'view_id', 'search_view_id', 'name', 'type')}
lang = self.env['res.lang'].search(
[('code', '=', self.env.user.lang or 'en_US')])
vals = {
x: act_vals[x]
for x in act_vals
if x
in (
"res_model",
"view_mode",
"domain",
"view_id",
"search_view_id",
"name",
"type",
)
}
lang = self.env["res.lang"].search(
[("code", "=", self.env.user.lang or "en_US")]
)
date_format = lang and lang.date_format or "%m/%d/%Y"
infos = {'name': vals['name'], 'target': _(self.target_move),
'from': self.from_date.strftime(date_format),
'to': self.to_date.strftime(date_format),
'company': self.company_id.name}
infos = {
"name": vals["name"],
"target": _(self.target_move),
"from": self.from_date.strftime(date_format),
"to": self.to_date.strftime(date_format),
"company": self.company_id.name,
}
# name of action which is displayed in breacrumb
vals["name"] = _(
"%(name)s: %(target)s from %(from)s to %(to)s") % infos
multi_cpny_grp = self.env.ref('base.group_multi_company')
vals["name"] = _("%(name)s: %(target)s from %(from)s to %(to)s") % infos
multi_cpny_grp = self.env.ref("base.group_multi_company")
if multi_cpny_grp in self.env.user.groups_id:
vals['name'] = '%s (%s)' % (vals['name'], self.company_id.name)
vals['context'] = {
'from_date': self.from_date,
'to_date': self.to_date,
'target_move': self.target_move,
'company_id': self.company_id.id,
vals["name"] = "{} ({})".format(vals["name"], self.company_id.name)
vals["context"] = {
"from_date": self.from_date,
"to_date": self.to_date,
"target_move": self.target_move,
"company_id": self.company_id.id,
}
return vals
Loading…
Cancel
Save