addons14/account_asset_management/wizard/account_asset_remove.py
def _prepare_early_removal(self, asset):
        """
        Generate last depreciation entry on the day before the removal date.
        """
        date_remove = self.date_remove
        asset_line_obj = self.env["account.asset.line"]

        digits = self.env["decimal.precision"].precision_get("Account")

        def _dlines(asset):
            lines = asset.depreciation_line_ids
            dlines = lines.filtered(
                lambda l: l.type == "depreciate"
                and not l.init_entry
                and not l.move_check
            )
            dlines = dlines.sorted(key=lambda l: l.line_date)
            return dlines

        dlines = _dlines(asset)
        if not dlines:
            asset.compute_depreciation_board()
            dlines = _dlines(asset)
        first_to_depreciate_dl = dlines[0]

        first_date = first_to_depreciate_dl.line_date
        if date_remove > first_date:
            raise UserError(
                _(
                    "You can't make an early removal if all the depreciation "
                    "lines for previous periods are not posted."
                )
            )

        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(
                [("asset_id", "=", asset.id), ("type", "=", "create")]
            )
            last_depr_date = create_dl.line_date

        period_number_days = (first_date - last_depr_date).days
        new_line_date = date_remove + relativedelta(days=-1)
        to_depreciate_days = (new_line_date - last_depr_date).days
        to_depreciate_amount = round(
            float(to_depreciate_days)
            / float(period_number_days)
            * first_to_depreciate_dl.amount,
            digits,
        )
        residual_value = asset.value_residual - to_depreciate_amount
        if to_depreciate_amount:
            update_vals = {"amount": to_depreciate_amount, "line_date": new_line_date}
            first_to_depreciate_dl.write(update_vals)
            dlines[0].create_move()
            dlines -= dlines[0]
        dlines.unlink()
        return residual_value

        Generate last depreciation entry on the day before the removal date.
        
Generate last depreciation entry on the day before the removal date.
Generate last depreciation entry on the day before the removal date .
def _prepare_early_removal(self, asset):
        date_remove = self.date_remove
        asset_line_obj = self.env["account.asset.line"]
        digits = self.env["decimal.precision"].precision_get("Account")
        def _dlines(asset):
            lines = asset.depreciation_line_ids
            dlines = lines.filtered(
                lambda l: l.type == "depreciate"
                and not l.init_entry
                and not l.move_check
            )
            dlines = dlines.sorted(key=lambda l: l.line_date)
            return dlines
        dlines = _dlines(asset)
        if not dlines:
            asset.compute_depreciation_board()
            dlines = _dlines(asset)
        first_to_depreciate_dl = dlines[0]
        first_date = first_to_depreciate_dl.line_date
        if date_remove > first_date:
            raise UserError(
                _(
                    "You can't make an early removal if all the depreciation "
                    "lines for previous periods are not posted."
                )
            )
        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(
                [("asset_id", "=", asset.id), ("type", "=", "create")]
            )
            last_depr_date = create_dl.line_date
        period_number_days = (first_date - last_depr_date).days
        new_line_date = date_remove + relativedelta(days=-1)
        to_depreciate_days = (new_line_date - last_depr_date).days
        to_depreciate_amount = round(
            float(to_depreciate_days)
            / float(period_number_days)
            * first_to_depreciate_dl.amount,
            digits,
        )
        residual_value = asset.value_residual - to_depreciate_amount
        if to_depreciate_amount:
            update_vals = {"amount": to_depreciate_amount, "line_date": new_line_date}
            first_to_depreciate_dl.write(update_vals)
            dlines[0].create_move()
            dlines -= dlines[0]
        dlines.unlink()
        return residual_value
def _prepare_early_removal ( self , asset ) : date_remove = self . date_remove asset_line_obj = self . env [ "account.asset.line" ] digits = self . env [ "decimal.precision" ] . precision_get ( "Account" ) def _dlines ( asset ) : lines = asset . depreciation_line_ids dlines = lines . filtered ( lambda l : l . type == "depreciate" and not l . init_entry and not l . move_check ) dlines = dlines . sorted ( key = lambda l : l . line_date ) return dlines dlines = _dlines ( asset ) if not dlines : asset . compute_depreciation_board ( ) dlines = _dlines ( asset ) first_to_depreciate_dl = dlines [ 0 ] first_date = first_to_depreciate_dl . line_date if date_remove > first_date : raise UserError ( _ ( "You can't make an early removal if all the depreciation " "lines for previous periods are not posted." ) ) 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 ( [ ( "asset_id" , "=" , asset . id ) , ( "type" , "=" , "create" ) ] ) last_depr_date = create_dl . line_date period_number_days = ( first_date - last_depr_date ) . days new_line_date = date_remove + relativedelta ( days = - 1 ) to_depreciate_days = ( new_line_date - last_depr_date ) . days to_depreciate_amount = round ( float ( to_depreciate_days ) / float ( period_number_days ) * first_to_depreciate_dl . amount , digits , ) residual_value = asset . value_residual - to_depreciate_amount if to_depreciate_amount : update_vals = { "amount" : to_depreciate_amount , "line_date" : new_line_date } first_to_depreciate_dl . write ( update_vals ) dlines [ 0 ] . create_move ( ) dlines -= dlines [ 0 ] dlines . unlink ( ) return residual_value
Generate last depreciation entry on the day before the removal date.
Generate last depreciation entry on the day before the removal date .
"""
        Generate last depreciation entry on the day before the removal date.
        """
self
asset