Пример #1
0
 def compute_depreciation_board(self,
                                cr,
                                uid,
                                code,
                                purchase_value,
                                salvage_value,
                                annuities,
                                rate,
                                purchase_date,
                                in_service_date,
                                sale_date=None,
                                depreciation_period=12,
                                fiscalyear_start_day='01-01',
                                board_stop_date=None,
                                rounding=2,
                                readonly_values=None,
                                exceptional_values=None,
                                context=None):
     if code == 'none':
         return []
     kwargs = locals().copy()
     kwargs['method_info'] = self.get_method_info(cr, uid, code, context)
     kwargs['depreciation_start_date'] = self.get_depreciation_start_date(
         cr, uid, code, purchase_date, in_service_date, context)
     for key in ('self', 'cr', 'uid', 'code', 'purchase_date',
                 'in_service_date', 'context'):
         del kwargs[key]
     board = DepreciationBoard(**kwargs)
     return [line.__dict__ for line in board.compute()]
 def compute_depreciation_board(self, cr, uid, code, purchase_value, salvage_value, annuities, rate, purchase_date, in_service_date,
                                sale_date=None, depreciation_period=12, fiscalyear_start_day='01-01', board_stop_date=None, rounding=2,
                                readonly_values=None, exceptional_values=None, context=None):
     if code == 'none':
         return []
     kwargs = locals().copy()
     kwargs['method_info'] = self.get_method_info(cr, uid, code, context)
     kwargs['depreciation_start_date'] = self.get_depreciation_start_date(cr, uid, code, purchase_date, in_service_date, context)
     for key in ('self', 'cr', 'uid', 'code', 'purchase_date', 'in_service_date', 'context'):
         del kwargs[key]
     board = DepreciationBoard(**kwargs)
     return [line.__dict__ for line in board.compute()]
 def _test_depreciation_board(self, kwargs, result):
     board = DepreciationBoard(**kwargs)
     lines = [line.__dict__ for line in board.compute()]
     self.assertEqual(lines, result)
 def _test_depreciation_board(self, kwargs, result):
     board = DepreciationBoard(**kwargs)
     lines = [line.__dict__ for line in board.compute()]
     self.assertEqual(lines, result)
 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