2018-08-05 20:33:56 +02:00
|
|
|
# Copyright 2009-2018 Noviat
|
2021-01-14 08:53:25 +01:00
|
|
|
# Copyright 2021 Tecnativa - João Marques
|
2018-08-05 20:33:56 +02:00
|
|
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
|
|
|
|
2015-02-12 11:51:18 +01:00
|
|
|
import logging
|
2018-08-05 20:33:56 +02:00
|
|
|
|
2020-01-29 18:34:31 +01:00
|
|
|
from dateutil.relativedelta import relativedelta
|
|
|
|
|
|
|
|
from odoo import _, api, fields, models
|
2018-10-01 11:57:07 +02:00
|
|
|
from odoo.exceptions import UserError, ValidationError
|
2018-08-05 20:33:56 +02:00
|
|
|
|
2015-02-12 11:51:18 +01:00
|
|
|
_logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
2018-08-05 20:33:56 +02:00
|
|
|
class AccountAssetRemove(models.TransientModel):
|
2020-01-29 18:34:31 +01:00
|
|
|
_name = "account.asset.remove"
|
|
|
|
_description = "Remove Asset"
|
2021-02-11 11:48:48 +01:00
|
|
|
_check_company_auto = True
|
2015-02-12 11:51:18 +01:00
|
|
|
|
2021-02-11 11:48:48 +01:00
|
|
|
company_id = fields.Many2one(
|
|
|
|
comodel_name="res.company",
|
|
|
|
string="Company",
|
|
|
|
readonly=True,
|
|
|
|
required=True,
|
|
|
|
default=lambda self: self._default_company_id(),
|
|
|
|
)
|
2018-08-05 20:33:56 +02:00
|
|
|
date_remove = fields.Date(
|
2020-01-29 18:34:31 +01:00
|
|
|
string="Asset Removal Date",
|
|
|
|
required=True,
|
2018-08-05 20:33:56 +02:00
|
|
|
default=fields.Date.today,
|
|
|
|
help="Removal date must be after the last posted entry "
|
2020-01-29 18:34:31 +01:00
|
|
|
"in case of early removal",
|
|
|
|
)
|
|
|
|
force_date = fields.Date(string="Force accounting date")
|
2018-08-05 20:33:56 +02:00
|
|
|
sale_value = fields.Float(
|
2020-01-29 18:34:31 +01:00
|
|
|
string="Sale Value", default=lambda self: self._default_sale_value()
|
|
|
|
)
|
2018-08-05 20:33:56 +02:00
|
|
|
account_sale_id = fields.Many2one(
|
2020-01-29 18:34:31 +01:00
|
|
|
comodel_name="account.account",
|
|
|
|
string="Asset Sale Account",
|
2021-02-11 11:48:48 +01:00
|
|
|
domain="[('deprecated', '=', False), ('company_id', '=', company_id)]",
|
2020-01-29 18:34:31 +01:00
|
|
|
default=lambda self: self._default_account_sale_id(),
|
|
|
|
)
|
2018-08-05 20:33:56 +02:00
|
|
|
account_plus_value_id = fields.Many2one(
|
2020-01-29 18:34:31 +01:00
|
|
|
comodel_name="account.account",
|
|
|
|
string="Plus-Value Account",
|
2021-02-11 11:48:48 +01:00
|
|
|
domain="[('deprecated', '=', False), ('company_id', '=', company_id)]",
|
2020-01-29 18:34:31 +01:00
|
|
|
default=lambda self: self._default_account_plus_value_id(),
|
|
|
|
)
|
2018-08-05 20:33:56 +02:00
|
|
|
account_min_value_id = fields.Many2one(
|
2020-01-29 18:34:31 +01:00
|
|
|
comodel_name="account.account",
|
|
|
|
string="Min-Value Account",
|
2021-02-11 11:48:48 +01:00
|
|
|
domain="[('deprecated', '=', False), ('company_id', '=', company_id)]",
|
2020-01-29 18:34:31 +01:00
|
|
|
default=lambda self: self._default_account_min_value_id(),
|
|
|
|
)
|
2018-08-05 20:33:56 +02:00
|
|
|
account_residual_value_id = fields.Many2one(
|
2020-01-29 18:34:31 +01:00
|
|
|
comodel_name="account.account",
|
|
|
|
string="Residual Value Account",
|
2021-02-11 11:48:48 +01:00
|
|
|
domain="[('deprecated', '=', False), ('company_id', '=', company_id)]",
|
2020-01-29 18:34:31 +01:00
|
|
|
default=lambda self: self._default_account_residual_value_id(),
|
|
|
|
)
|
2018-08-05 20:33:56 +02:00
|
|
|
posting_regime = fields.Selection(
|
|
|
|
selection=lambda self: self._selection_posting_regime(),
|
2020-01-29 18:34:31 +01:00
|
|
|
string="Removal Entry Policy",
|
2018-08-05 20:33:56 +02:00
|
|
|
required=True,
|
|
|
|
default=lambda self: self._get_posting_regime(),
|
|
|
|
help="Removal Entry Policy \n"
|
2020-01-29 18:34:31 +01:00
|
|
|
" * Residual Value: The non-depreciated value will be "
|
|
|
|
"posted on the 'Residual Value Account' \n"
|
|
|
|
" * Gain/Loss on Sale: The Gain or Loss will be posted on "
|
|
|
|
"the 'Plus-Value Account' or 'Min-Value Account' ",
|
|
|
|
)
|
|
|
|
note = fields.Text("Notes")
|
|
|
|
|
|
|
|
@api.constrains("sale_value")
|
2018-10-01 11:57:07 +02:00
|
|
|
def _check_sale_value(self):
|
|
|
|
if self.sale_value < 0:
|
2020-01-29 18:34:31 +01:00
|
|
|
raise ValidationError(_("The Sale Value must be positive!"))
|
2018-10-01 11:57:07 +02:00
|
|
|
|
2021-02-11 11:48:48 +01:00
|
|
|
@api.model
|
|
|
|
def _default_company_id(self):
|
|
|
|
asset_id = self.env.context.get("active_id")
|
2021-02-23 13:59:08 +01:00
|
|
|
asset = self.env["account.asset"].browse(asset_id)
|
2021-02-11 11:48:48 +01:00
|
|
|
return asset.company_id
|
|
|
|
|
2018-08-05 20:33:56 +02:00
|
|
|
@api.model
|
|
|
|
def _default_sale_value(self):
|
2020-01-29 18:34:31 +01:00
|
|
|
return self._get_sale()["sale_value"]
|
2018-08-05 20:33:56 +02:00
|
|
|
|
|
|
|
@api.model
|
|
|
|
def _default_account_sale_id(self):
|
2020-01-29 18:34:31 +01:00
|
|
|
return self._get_sale()["account_sale_id"]
|
2018-08-05 20:33:56 +02:00
|
|
|
|
|
|
|
def _get_sale(self):
|
2020-01-29 18:34:31 +01:00
|
|
|
asset_id = self.env.context.get("active_id")
|
2015-02-12 11:51:18 +01:00
|
|
|
sale_value = 0.0
|
|
|
|
account_sale_id = False
|
2020-01-29 18:37:08 +01:00
|
|
|
inv_lines = self.env["account.move.line"].search(
|
|
|
|
[
|
|
|
|
("asset_id", "=", asset_id),
|
2021-01-14 08:53:25 +01:00
|
|
|
("move_id.move_type", "in", ("out_invoice", "out_refund")),
|
2020-01-29 18:37:08 +01:00
|
|
|
]
|
2020-01-29 18:34:31 +01:00
|
|
|
)
|
2018-08-05 20:33:56 +02:00
|
|
|
for line in inv_lines:
|
2020-01-29 18:37:08 +01:00
|
|
|
inv = line.move_id
|
|
|
|
comp_curr = inv.company_currency_id
|
2015-02-12 11:51:18 +01:00
|
|
|
inv_curr = inv.currency_id
|
2021-03-29 17:12:05 +02:00
|
|
|
if line.move_id.payment_state == "paid" or line.parent_state == "draft":
|
2015-02-12 11:51:18 +01:00
|
|
|
account_sale_id = line.account_id.id
|
|
|
|
amount = line.price_subtotal
|
|
|
|
if inv_curr != comp_curr:
|
2018-08-05 20:33:56 +02:00
|
|
|
amount = comp_curr.compute(amount)
|
2015-02-12 11:51:18 +01:00
|
|
|
sale_value += amount
|
2020-01-29 18:34:31 +01:00
|
|
|
return {"sale_value": sale_value, "account_sale_id": account_sale_id}
|
2015-02-12 11:51:18 +01:00
|
|
|
|
2018-08-05 20:33:56 +02:00
|
|
|
@api.model
|
|
|
|
def _default_account_plus_value_id(self):
|
2020-01-29 18:34:31 +01:00
|
|
|
asset_id = self.env.context.get("active_id")
|
|
|
|
asset = self.env["account.asset"].browse(asset_id)
|
2018-08-05 20:33:56 +02:00
|
|
|
return asset.profile_id.account_plus_value_id
|
|
|
|
|
|
|
|
@api.model
|
|
|
|
def _default_account_min_value_id(self):
|
2020-01-29 18:34:31 +01:00
|
|
|
asset_id = self.env.context.get("active_id")
|
|
|
|
asset = self.env["account.asset"].browse(asset_id)
|
2018-08-05 20:33:56 +02:00
|
|
|
return asset.profile_id.account_min_value_id
|
|
|
|
|
|
|
|
@api.model
|
|
|
|
def _default_account_residual_value_id(self):
|
2020-01-29 18:34:31 +01:00
|
|
|
asset_id = self.env.context.get("active_id")
|
|
|
|
asset = self.env["account.asset"].browse(asset_id)
|
2018-08-05 20:33:56 +02:00
|
|
|
return asset.profile_id.account_residual_value_id
|
|
|
|
|
|
|
|
@api.model
|
|
|
|
def _selection_posting_regime(self):
|
2020-01-29 18:34:31 +01:00
|
|
|
return [
|
|
|
|
("residual_value", _("Residual Value")),
|
|
|
|
("gain_loss_on_sale", _("Gain/Loss on Sale")),
|
2018-08-05 20:33:56 +02:00
|
|
|
]
|
2015-02-12 11:51:18 +01:00
|
|
|
|
2018-08-05 20:33:56 +02:00
|
|
|
@api.model
|
|
|
|
def _get_posting_regime(self):
|
2020-01-29 18:34:31 +01:00
|
|
|
asset_obj = self.env["account.asset"]
|
|
|
|
asset = asset_obj.browse(self.env.context.get("active_id"))
|
2018-08-05 20:33:56 +02:00
|
|
|
country = asset and asset.company_id.country_id.code or False
|
|
|
|
if country in self._residual_value_regime_countries():
|
2020-01-29 18:34:31 +01:00
|
|
|
return "residual_value"
|
2018-08-05 20:33:56 +02:00
|
|
|
else:
|
2020-01-29 18:34:31 +01:00
|
|
|
return "gain_loss_on_sale"
|
2018-08-05 20:33:56 +02:00
|
|
|
|
|
|
|
def _residual_value_regime_countries(self):
|
2020-01-29 18:34:31 +01:00
|
|
|
return ["FR"]
|
2018-08-05 20:33:56 +02:00
|
|
|
|
|
|
|
def remove(self):
|
|
|
|
self.ensure_one()
|
2020-01-29 18:34:31 +01:00
|
|
|
asset_line_obj = self.env["account.asset.line"]
|
2018-08-05 20:33:56 +02:00
|
|
|
|
2020-01-29 18:34:31 +01:00
|
|
|
asset_id = self.env.context.get("active_id")
|
|
|
|
asset = self.env["account.asset"].browse(asset_id)
|
|
|
|
asset_ref = (
|
|
|
|
asset.code and "{} (ref: {})".format(asset.name, asset.code) or asset.name
|
|
|
|
)
|
2018-08-05 20:33:56 +02:00
|
|
|
|
2020-01-29 18:34:31 +01:00
|
|
|
if self.env.context.get("early_removal"):
|
2018-08-05 20:33:56 +02:00
|
|
|
residual_value = self._prepare_early_removal(asset)
|
|
|
|
else:
|
|
|
|
residual_value = asset.value_residual
|
|
|
|
|
|
|
|
dlines = asset_line_obj.search(
|
2020-08-19 12:08:42 +02:00
|
|
|
[
|
|
|
|
("asset_id", "=", asset.id),
|
|
|
|
("type", "=", "depreciate"),
|
|
|
|
("move_check", "!=", False),
|
|
|
|
],
|
2020-01-29 18:34:31 +01:00
|
|
|
order="line_date desc",
|
|
|
|
)
|
2018-08-05 20:33:56 +02:00
|
|
|
if dlines:
|
|
|
|
last_date = dlines[0].line_date
|
|
|
|
else:
|
|
|
|
create_dl = asset_line_obj.search(
|
2020-01-29 18:34:31 +01:00
|
|
|
[("asset_id", "=", asset.id), ("type", "=", "create")]
|
|
|
|
)[0]
|
2018-08-05 20:33:56 +02:00
|
|
|
last_date = create_dl.line_date
|
2015-02-12 11:51:18 +01:00
|
|
|
|
2018-08-05 20:33:56 +02:00
|
|
|
if self.date_remove < last_date:
|
|
|
|
raise UserError(
|
2020-01-29 18:34:31 +01:00
|
|
|
_("The removal date must be after " "the last depreciation date.")
|
|
|
|
)
|
2018-08-05 20:33:56 +02:00
|
|
|
|
|
|
|
line_name = asset._get_depreciation_entry_name(len(dlines) + 1)
|
|
|
|
journal_id = asset.profile_id.journal_id.id
|
|
|
|
if not self.force_date:
|
|
|
|
date_remove = self.date_remove
|
|
|
|
else:
|
|
|
|
date_remove = self.force_date
|
|
|
|
|
|
|
|
# create move
|
|
|
|
move_vals = {
|
2020-01-29 18:34:31 +01:00
|
|
|
"date": date_remove,
|
|
|
|
"ref": line_name,
|
|
|
|
"journal_id": journal_id,
|
|
|
|
"narration": self.note,
|
2018-08-05 20:33:56 +02:00
|
|
|
}
|
2020-01-29 18:34:31 +01:00
|
|
|
move = self.env["account.move"].create(move_vals)
|
2018-08-05 20:33:56 +02:00
|
|
|
|
|
|
|
# create asset line
|
|
|
|
asset_line_vals = {
|
2020-01-29 18:34:31 +01:00
|
|
|
"amount": residual_value,
|
|
|
|
"asset_id": asset_id,
|
|
|
|
"name": line_name,
|
|
|
|
"line_date": self.date_remove,
|
|
|
|
"move_id": move.id,
|
|
|
|
"type": "remove",
|
2018-08-05 20:33:56 +02:00
|
|
|
}
|
|
|
|
asset_line_obj.create(asset_line_vals)
|
2020-01-29 18:34:31 +01:00
|
|
|
asset.write({"state": "removed", "date_remove": self.date_remove})
|
2018-08-05 20:33:56 +02:00
|
|
|
|
|
|
|
# create move lines
|
|
|
|
move_lines = self._get_removal_data(asset, residual_value)
|
2020-01-29 18:34:31 +01:00
|
|
|
move.with_context(allow_asset=True).write({"line_ids": move_lines})
|
2018-08-05 20:33:56 +02:00
|
|
|
|
|
|
|
return {
|
2020-01-29 18:34:31 +01:00
|
|
|
"name": _("Asset '%s' Removal Journal Entry") % asset_ref,
|
|
|
|
"view_mode": "tree,form",
|
|
|
|
"res_model": "account.move",
|
|
|
|
"view_id": False,
|
|
|
|
"type": "ir.actions.act_window",
|
|
|
|
"context": self.env.context,
|
|
|
|
"domain": [("id", "=", move.id)],
|
2018-08-05 20:33:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
def _prepare_early_removal(self, asset):
|
2015-02-12 11:51:18 +01:00
|
|
|
"""
|
|
|
|
Generate last depreciation entry on the day before the removal date.
|
|
|
|
"""
|
2018-08-05 20:33:56 +02:00
|
|
|
date_remove = self.date_remove
|
2020-01-29 18:34:31 +01:00
|
|
|
asset_line_obj = self.env["account.asset.line"]
|
2018-08-05 20:33:56 +02:00
|
|
|
|
2020-01-29 18:34:31 +01:00
|
|
|
digits = self.env["decimal.precision"].precision_get("Account")
|
2015-02-12 11:51:18 +01:00
|
|
|
|
2018-08-05 20:33:56 +02:00
|
|
|
def _dlines(asset):
|
|
|
|
lines = asset.depreciation_line_ids
|
|
|
|
dlines = lines.filtered(
|
2020-01-29 18:34:31 +01:00
|
|
|
lambda l: l.type == "depreciate"
|
|
|
|
and not l.init_entry
|
|
|
|
and not l.move_check
|
|
|
|
)
|
2018-08-05 20:33:56 +02:00
|
|
|
dlines = dlines.sorted(key=lambda l: l.line_date)
|
|
|
|
return dlines
|
2015-02-12 11:51:18 +01:00
|
|
|
|
2018-08-05 20:33:56 +02:00
|
|
|
dlines = _dlines(asset)
|
|
|
|
if not dlines:
|
|
|
|
asset.compute_depreciation_board()
|
|
|
|
dlines = _dlines(asset)
|
2021-09-07 11:47:37 +02:00
|
|
|
if not dlines:
|
|
|
|
return asset.value_residual
|
2018-08-05 20:33:56 +02:00
|
|
|
first_to_depreciate_dl = dlines[0]
|
2015-02-12 11:51:18 +01:00
|
|
|
|
|
|
|
first_date = first_to_depreciate_dl.line_date
|
|
|
|
if date_remove > first_date:
|
2018-08-05 20:33:56 +02:00
|
|
|
raise UserError(
|
2020-01-29 18:34:31 +01:00
|
|
|
_(
|
|
|
|
"You can't make an early removal if all the depreciation "
|
|
|
|
"lines for previous periods are not posted."
|
|
|
|
)
|
|
|
|
)
|
2015-02-12 11:51:18 +01:00
|
|
|
|
2018-08-05 20:33:56 +02:00
|
|
|
if first_to_depreciate_dl.previous_id:
|
|
|
|
last_depr_date = first_to_depreciate_dl.previous_id.line_date
|
|
|
|
else:
|
|
|
|
create_dl = asset_line_obj.search(
|
2020-01-29 18:34:31 +01:00
|
|
|
[("asset_id", "=", asset.id), ("type", "=", "create")]
|
|
|
|
)
|
2018-08-05 20:33:56 +02:00
|
|
|
last_depr_date = create_dl.line_date
|
|
|
|
|
2022-01-20 10:26:01 +01:00
|
|
|
# Never create move.
|
|
|
|
same_month = (
|
|
|
|
last_depr_date.month == first_to_depreciate_dl.line_date.month and 1 or 0
|
|
|
|
)
|
|
|
|
|
|
|
|
period_number_days = (first_date - last_depr_date).days + same_month
|
2015-02-12 11:51:18 +01:00
|
|
|
new_line_date = date_remove + relativedelta(days=-1)
|
2022-01-20 10:26:01 +01:00
|
|
|
to_depreciate_days = (new_line_date - last_depr_date).days + same_month
|
2015-02-12 11:51:18 +01:00
|
|
|
to_depreciate_amount = round(
|
2020-01-29 18:34:31 +01:00
|
|
|
float(to_depreciate_days)
|
|
|
|
/ float(period_number_days)
|
|
|
|
* first_to_depreciate_dl.amount,
|
|
|
|
digits,
|
|
|
|
)
|
2015-02-12 11:51:18 +01:00
|
|
|
residual_value = asset.value_residual - to_depreciate_amount
|
|
|
|
if to_depreciate_amount:
|
2020-08-19 12:08:42 +02:00
|
|
|
update_vals = {
|
|
|
|
"amount": to_depreciate_amount,
|
|
|
|
"line_date": new_line_date,
|
|
|
|
"line_days": to_depreciate_days,
|
|
|
|
}
|
2015-02-12 11:51:18 +01:00
|
|
|
first_to_depreciate_dl.write(update_vals)
|
2018-08-05 20:33:56 +02:00
|
|
|
dlines[0].create_move()
|
|
|
|
dlines -= dlines[0]
|
|
|
|
dlines.unlink()
|
2015-02-12 11:51:18 +01:00
|
|
|
return residual_value
|
|
|
|
|
2018-08-05 20:33:56 +02:00
|
|
|
def _get_removal_data(self, asset, residual_value):
|
2015-02-12 11:51:18 +01:00
|
|
|
move_lines = []
|
|
|
|
partner_id = asset.partner_id and asset.partner_id.id or False
|
2018-08-05 20:33:56 +02:00
|
|
|
profile = asset.profile_id
|
2015-02-12 11:51:18 +01:00
|
|
|
|
|
|
|
# asset and asset depreciation account reversal
|
2018-08-05 20:33:56 +02:00
|
|
|
depr_amount = asset.depreciation_base - residual_value
|
|
|
|
if depr_amount:
|
|
|
|
move_line_vals = {
|
2020-01-29 18:34:31 +01:00
|
|
|
"name": asset.name,
|
|
|
|
"account_id": profile.account_depreciation_id.id,
|
|
|
|
"debit": depr_amount > 0 and depr_amount or 0.0,
|
|
|
|
"credit": depr_amount < 0 and -depr_amount or 0.0,
|
|
|
|
"partner_id": partner_id,
|
|
|
|
"asset_id": asset.id,
|
2018-08-05 20:33:56 +02:00
|
|
|
}
|
|
|
|
move_lines.append((0, 0, move_line_vals))
|
|
|
|
|
2015-02-12 11:51:18 +01:00
|
|
|
move_line_vals = {
|
2020-01-29 18:34:31 +01:00
|
|
|
"name": asset.name,
|
|
|
|
"account_id": profile.account_asset_id.id,
|
|
|
|
"debit": (asset.depreciation_base < 0 and -asset.depreciation_base or 0.0),
|
|
|
|
"credit": (asset.depreciation_base > 0 and asset.depreciation_base or 0.0),
|
|
|
|
"partner_id": partner_id,
|
|
|
|
"asset_id": asset.id,
|
2015-02-12 11:51:18 +01:00
|
|
|
}
|
|
|
|
move_lines.append((0, 0, move_line_vals))
|
|
|
|
|
|
|
|
if residual_value:
|
2020-01-29 18:34:31 +01:00
|
|
|
if self.posting_regime == "residual_value":
|
2015-02-12 11:51:18 +01:00
|
|
|
move_line_vals = {
|
2020-01-29 18:34:31 +01:00
|
|
|
"name": asset.name,
|
|
|
|
"account_id": self.account_residual_value_id.id,
|
|
|
|
"analytic_account_id": asset.account_analytic_id.id,
|
2021-04-06 15:24:08 +02:00
|
|
|
"analytic_tag_ids": [(4, tag.id) for tag in asset.analytic_tag_ids],
|
2020-01-29 18:34:31 +01:00
|
|
|
"debit": residual_value,
|
|
|
|
"credit": 0.0,
|
|
|
|
"partner_id": partner_id,
|
|
|
|
"asset_id": asset.id,
|
2015-02-12 11:51:18 +01:00
|
|
|
}
|
|
|
|
move_lines.append((0, 0, move_line_vals))
|
2020-01-29 18:34:31 +01:00
|
|
|
elif self.posting_regime == "gain_loss_on_sale":
|
2018-08-05 20:33:56 +02:00
|
|
|
if self.sale_value:
|
|
|
|
sale_value = self.sale_value
|
2015-02-12 11:51:18 +01:00
|
|
|
move_line_vals = {
|
2020-01-29 18:34:31 +01:00
|
|
|
"name": asset.name,
|
|
|
|
"account_id": self.account_sale_id.id,
|
|
|
|
"analytic_account_id": asset.account_analytic_id.id,
|
2021-04-06 15:24:08 +02:00
|
|
|
"analytic_tag_ids": [
|
|
|
|
(4, tag.id) for tag in asset.analytic_tag_ids
|
|
|
|
],
|
2020-01-29 18:34:31 +01:00
|
|
|
"debit": sale_value,
|
|
|
|
"credit": 0.0,
|
|
|
|
"partner_id": partner_id,
|
|
|
|
"asset_id": asset.id,
|
2015-02-12 11:51:18 +01:00
|
|
|
}
|
|
|
|
move_lines.append((0, 0, move_line_vals))
|
2018-08-05 20:33:56 +02:00
|
|
|
balance = self.sale_value - residual_value
|
2020-01-29 18:34:31 +01:00
|
|
|
account_id = (
|
|
|
|
self.account_plus_value_id.id
|
|
|
|
if balance > 0
|
|
|
|
else self.account_min_value_id.id
|
|
|
|
)
|
2015-02-12 11:51:18 +01:00
|
|
|
move_line_vals = {
|
2020-01-29 18:34:31 +01:00
|
|
|
"name": asset.name,
|
|
|
|
"account_id": account_id,
|
|
|
|
"analytic_account_id": asset.account_analytic_id.id,
|
2021-04-06 15:24:08 +02:00
|
|
|
"analytic_tag_ids": [(4, tag.id) for tag in asset.analytic_tag_ids],
|
2020-01-29 18:34:31 +01:00
|
|
|
"debit": balance < 0 and -balance or 0.0,
|
|
|
|
"credit": balance > 0 and balance or 0.0,
|
|
|
|
"partner_id": partner_id,
|
|
|
|
"asset_id": asset.id,
|
2015-02-12 11:51:18 +01:00
|
|
|
}
|
|
|
|
move_lines.append((0, 0, move_line_vals))
|
|
|
|
return move_lines
|