def _get_depreciation_infos(self, cr, uid, ids, name, arg, context=None):
     res = {}
     cr.execute(
         "SELECT asset_id as id, round(sum(debit-credit)) as amount "
         "FROM account_move_line WHERE asset_id IN %s GROUP BY asset_id",
         (tuple(ids),),
     )
     res.update(dict(cr.fetchall()))
     company_obj = self.pool.get("res.company")
     fields_to_read = [
         "purchase_value",
         "salvage_value",
         "depreciation_date_start",
         "sale_value",
         "state",
         "period_length",
         "accounting_prorata",
         "company_id",
     ]
     fields_to_read += ALL_DEPRECIATION_FIELDS
     for asset in self.read(cr, uid, ids, fields_to_read, context, "_classic_write"):
         fiscalyear_start_day = company_obj.get_fiscalyear_start_day(cr, uid, asset["company_id"], context)
         accelerated_depreciation = get_accelerated_depreciation(**asset)
         if asset["state"] == "draft":
             book_value = asset["purchase_value"]
         elif asset["state"] == "open":
             book_value = res.get(asset["id"], 0.0)
         else:
             book_value = asset["salvage_value"]
         res[asset["id"]] = {
             "depreciation_date_stop": get_period_stop_date(
                 asset["depreciation_date_start"], fiscalyear_start_day, asset["period_length"]
             ).strftime("%Y-%m-%d"),
             "benefit_accelerated_depreciation": accelerated_depreciation,
             "amount_to_depreciate": book_value - asset["salvage_value"],
         }
     return res
 def _compute_depreciation_lines(self, cr, uid, asset_id, depreciation_type="accounting", context=None):
     depreciation_line_obj = self.pool.get("account.asset.depreciation.line")
     # Delete old lines
     line_ids_to_delete = depreciation_line_obj.search(
         cr,
         uid,
         [("asset_id", "=", asset_id), ("depreciation_type", "=", depreciation_type), ("move_id", "=", False)],
         context=context,
     )
     depreciation_line_obj.unlink(cr, uid, line_ids_to_delete, context)
     # Create new lines
     asset = self.browse(cr, uid, asset_id, context)
     method = getattr(asset, "%s_method" % depreciation_type)
     periods = getattr(asset, "%s_periods" % depreciation_type)
     degressive_rate = getattr(asset, "%s_degressive_rate" % depreciation_type)
     fiscalyear_start_day = self.pool.get("res.company").get_fiscalyear_start_day(
         cr, uid, asset.company_id.id, context
     )
     starts_on_first_day_of_month = not getattr(asset, "%s_prorata" % depreciation_type)
     readonly_values = {}
     exceptional_values = {}
     for line in asset.depreciation_line_ids:
         period_stop_month = get_period_stop_date(
             line.depreciation_date, fiscalyear_start_day, asset.period_length
         ).strftime("%Y-%m")
         if line.depreciation_type == depreciation_type and line.move_id:
             readonly_values.setdefault(period_stop_month, 0.0)
             readonly_values[period_stop_month] += line.depreciation_value
         elif line.depreciation_type == "exceptional":
             exceptional_values.setdefault(period_stop_month, 0.0)
             exceptional_values[period_stop_month] += line.depreciation_value
     board = DepreciationBoard(
         asset.purchase_value,
         method,
         periods,
         degressive_rate,
         asset.salvage_value,
         asset.depreciation_date_start,
         starts_on_first_day_of_month,
         asset.sale_date or None,
         asset.period_length,
         readonly_values,
         exceptional_values,
         fiscalyear_start_day,
         asset.accounting_periods,
         rounding=len(str(asset.company_id.currency_id.rounding).split(".")[-1]),
     )
     asset = self.browse(cr, uid, asset_id, context)
     board_lines = board.compute()
     for line in board_lines:
         vals = line.__dict__
         vals["depreciation_date"] = vals["depreciation_date"].strftime("%Y-%m-%d")
         readonly = vals["readonly"]
         del vals["readonly"]
         if readonly:
             for dline in asset.depreciation_line_ids:
                 if dline.depreciation_date == vals["depreciation_date"] and dline.move_id:
                     dline.write(vals)
                     break
             continue
         vals["asset_id"] = asset.id
         vals["depreciation_type"] = depreciation_type
         vals["previous_accumulated_value"] = vals["accumulated_value"] - vals["depreciation_value"]
         depreciation_line_obj.create(cr, uid, line.__dict__, context)
     return True