Black, isort, etc...

pull/837/head
Andrea 2019-10-28 12:39:18 +01:00 committed by Valentin Vinagre Urteaga
parent 4e72c95110
commit c216a5a8fd
6 changed files with 335 additions and 277 deletions

View File

@ -13,16 +13,11 @@
"Odoo Community Association (OCA)", "Odoo Community Association (OCA)",
"license": "AGPL-3", "license": "AGPL-3",
"installable": True, "installable": True,
"depends": [ "depends": ["account", "date_range"],
"account",
"date_range",
],
"data": [ "data": [
"wizard/open_tax_balances_view.xml", "wizard/open_tax_balances_view.xml",
"views/account_move_view.xml", "views/account_move_view.xml",
"views/account_tax_view.xml", "views/account_tax_view.xml",
], ],
"images": [ "images": ["images/tax_balance.png"],
"images/tax_balance.png",
]
} }

View File

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

View File

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

View File

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

View File

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

View File

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