Black, isort, etc...
This commit is contained in:
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user