183183from ..api .robo_ledger_fiscal_close .rebuild_schedule import (
184184 sync_detailed as op_rebuild_schedule ,
185185)
186+ from ..api .robo_ledger_fiscal_close .preview_schedule import (
187+ sync_detailed as op_preview_schedule ,
188+ )
186189from ..api .robo_ledger_report_distribution .add_publish_list_members import (
187190 sync_detailed as op_add_publish_list_members ,
188191)
644647from ..models .delete_schedule_arm import DeleteScheduleArm
645648from ..models .delete_schedule_request import DeleteScheduleRequest
646649from ..models .rebuild_schedule_request import RebuildScheduleRequest
650+ from ..models .preview_schedule_request import PreviewScheduleRequest
651+ from ..models .preview_schedule_response import PreviewScheduleResponse
647652from ..models .update_legacy_arm import UpdateLegacyArm
648653from ..models .update_forecast_arm import UpdateForecastArm
649654from ..models .link_entity_taxonomy_request import LinkEntityTaxonomyRequest
@@ -1907,6 +1912,83 @@ def delete_information_block(
19071912
19081913 # ── Schedules ──────────────────────────────────────────────────────
19091914
1915+ @staticmethod
1916+ def _schedule_payload (
1917+ * ,
1918+ name : str ,
1919+ element_ids : list [str ],
1920+ period_start : str ,
1921+ period_end : str ,
1922+ monthly_amount : int | None ,
1923+ debit_element_id : str ,
1924+ credit_element_id : str ,
1925+ entry_type : str ,
1926+ memo_template : str ,
1927+ taxonomy_id : str | None ,
1928+ method : str | None ,
1929+ original_amount : int | None ,
1930+ residual_value : int | None ,
1931+ useful_life_months : int | None ,
1932+ asset_element_id : str | None ,
1933+ auto_reverse : bool ,
1934+ booked_on : str | None ,
1935+ entity_id : str | None ,
1936+ periodic_amounts : list [int ] | None ,
1937+ loan_terms : dict [str , Any ] | None ,
1938+ legs : list [dict [str , Any ]] | None ,
1939+ dimension_ids : list [str ] | None ,
1940+ closed_through : str | None ,
1941+ ) -> dict [str , Any ]:
1942+ """The schedule definition ``create_schedule`` and ``preview_schedule``
1943+ send, as the request's dict. Only what the caller set is sent, so the
1944+ server's defaults apply to the rest."""
1945+ entry_template : dict [str , Any ] = {
1946+ "debit_element_id" : debit_element_id ,
1947+ "credit_element_id" : credit_element_id ,
1948+ "entry_type" : entry_type ,
1949+ "memo_template" : memo_template ,
1950+ "auto_reverse" : auto_reverse ,
1951+ }
1952+ if legs :
1953+ entry_template ["legs" ] = legs
1954+ if dimension_ids :
1955+ entry_template ["dimension_ids" ] = dimension_ids
1956+ payload : dict [str , Any ] = {
1957+ "name" : name ,
1958+ "element_ids" : element_ids ,
1959+ "period_start" : period_start ,
1960+ "period_end" : period_end ,
1961+ "entry_template" : entry_template ,
1962+ }
1963+ if monthly_amount is not None :
1964+ payload ["monthly_amount" ] = monthly_amount
1965+ if taxonomy_id :
1966+ payload ["taxonomy_id" ] = taxonomy_id
1967+ if entity_id :
1968+ payload ["entity_id" ] = entity_id
1969+ if closed_through is not None :
1970+ payload ["closed_through" ] = closed_through
1971+ schedule_metadata : dict [str , Any ] = {}
1972+ if method :
1973+ schedule_metadata ["method" ] = method
1974+ if original_amount is not None :
1975+ schedule_metadata ["original_amount" ] = original_amount
1976+ if residual_value is not None :
1977+ schedule_metadata ["residual_value" ] = residual_value
1978+ if useful_life_months is not None :
1979+ schedule_metadata ["useful_life_months" ] = useful_life_months
1980+ if asset_element_id :
1981+ schedule_metadata ["asset_element_id" ] = asset_element_id
1982+ if booked_on is not None :
1983+ schedule_metadata ["booked_on" ] = booked_on
1984+ if periodic_amounts is not None :
1985+ schedule_metadata ["periodic_amounts" ] = periodic_amounts
1986+ if loan_terms is not None :
1987+ schedule_metadata ["loan_terms" ] = loan_terms
1988+ if schedule_metadata :
1989+ payload ["schedule_metadata" ] = schedule_metadata
1990+ return payload
1991+
19101992 def create_schedule (
19111993 self ,
19121994 graph_id : str ,
@@ -1915,7 +1997,7 @@ def create_schedule(
19151997 element_ids : list [str ],
19161998 period_start : str ,
19171999 period_end : str ,
1918- monthly_amount : int ,
2000+ monthly_amount : int | None = None ,
19192001 debit_element_id : str ,
19202002 credit_element_id : str ,
19212003 entry_type : str = "closing" ,
@@ -1929,50 +2011,59 @@ def create_schedule(
19292011 auto_reverse : bool = False ,
19302012 booked_on : str | None = None ,
19312013 entity_id : str | None = None ,
2014+ periodic_amounts : list [int ] | None = None ,
2015+ loan_terms : dict [str , Any ] | None = None ,
2016+ legs : list [dict [str , Any ]] | None = None ,
2017+ dimension_ids : list [str ] | None = None ,
19322018 ) -> InformationBlockEnvelope :
19332019 """Create a new schedule with pre-generated monthly facts.
19342020
2021+ Three methods. Straight-line (the default) spreads ``monthly_amount``
2022+ over the months, the last absorbing rounding. ``method="custom"`` takes
2023+ ``periodic_amounts`` instead: one cents value per month, non-negative,
2024+ summing to ``original_amount`` less ``residual_value``.
2025+ ``method="effective_interest"`` is a loan: ``loan_terms`` (the fields of
2026+ :class:`~robosystems_client.models.loan_terms_request.LoanTermsRequest`:
2027+ ``principal``, ``annual_rate``, ``start_date``, ``note_element_id``, the
2028+ day count, payment frequency and amount, ``interest_only``,
2029+ ``maturity_date``) computes the amortization table, and ``legs`` (each
2030+ ``{"element_id", "side", "amount_source"}``) say which table column each
2031+ line of the period's entry takes; ``debit_element_id`` names the
2032+ interest debit leg and ``credit_element_id`` one credit leg.
2033+
19352034 ``booked_on`` (``YYYY-MM-DD``) is the day the schedule's cost went on
19362035 the books, when that is before its first period. The schedule
19372036 reconciliation carries the cost from that day.
19382037
19392038 ``entity_id`` is the entity whose books the schedule belongs to;
1940- ``None`` = the group parent.
2039+ ``None`` = the group parent. :meth:`preview_schedule` takes the same
2040+ arguments and shows the roll-forward without creating anything.
19412041 """
1942- payload_dict : dict [str , Any ] = {
1943- "name" : name ,
1944- "element_ids" : element_ids ,
1945- "period_start" : period_start ,
1946- "period_end" : period_end ,
1947- "monthly_amount" : monthly_amount ,
1948- "entry_template" : {
1949- "debit_element_id" : debit_element_id ,
1950- "credit_element_id" : credit_element_id ,
1951- "entry_type" : entry_type ,
1952- "memo_template" : memo_template ,
1953- "auto_reverse" : auto_reverse ,
1954- },
1955- }
1956- if taxonomy_id :
1957- payload_dict ["taxonomy_id" ] = taxonomy_id
1958- if entity_id :
1959- payload_dict ["entity_id" ] = entity_id
1960- schedule_metadata : dict [str , Any ] = {}
1961- if method :
1962- schedule_metadata ["method" ] = method
1963- if original_amount is not None :
1964- schedule_metadata ["original_amount" ] = original_amount
1965- if residual_value is not None :
1966- schedule_metadata ["residual_value" ] = residual_value
1967- if useful_life_months is not None :
1968- schedule_metadata ["useful_life_months" ] = useful_life_months
1969- if asset_element_id :
1970- schedule_metadata ["asset_element_id" ] = asset_element_id
1971- if booked_on is not None :
1972- schedule_metadata ["booked_on" ] = booked_on
1973- if schedule_metadata :
1974- payload_dict ["schedule_metadata" ] = schedule_metadata
1975-
2042+ payload_dict = self ._schedule_payload (
2043+ name = name ,
2044+ element_ids = element_ids ,
2045+ period_start = period_start ,
2046+ period_end = period_end ,
2047+ monthly_amount = monthly_amount ,
2048+ debit_element_id = debit_element_id ,
2049+ credit_element_id = credit_element_id ,
2050+ entry_type = entry_type ,
2051+ memo_template = memo_template ,
2052+ taxonomy_id = taxonomy_id ,
2053+ method = method ,
2054+ original_amount = original_amount ,
2055+ residual_value = residual_value ,
2056+ useful_life_months = useful_life_months ,
2057+ asset_element_id = asset_element_id ,
2058+ auto_reverse = auto_reverse ,
2059+ booked_on = booked_on ,
2060+ entity_id = entity_id ,
2061+ periodic_amounts = periodic_amounts ,
2062+ loan_terms = loan_terms ,
2063+ legs = legs ,
2064+ dimension_ids = dimension_ids ,
2065+ closed_through = None ,
2066+ )
19762067 payload = CreateScheduleRequest .from_dict (payload_dict )
19772068 body = CreateScheduleArm (block_type = "schedule" , payload = payload )
19782069 response = op_create_information_block (
@@ -1981,6 +2072,83 @@ def create_schedule(
19812072 envelope = self ._call_op ("Create schedule" , response )
19822073 return self ._typed_result ("Create schedule" , envelope , InformationBlockEnvelope )
19832074
2075+ def preview_schedule (
2076+ self ,
2077+ graph_id : str ,
2078+ * ,
2079+ name : str ,
2080+ element_ids : list [str ],
2081+ period_start : str ,
2082+ period_end : str ,
2083+ monthly_amount : int | None = None ,
2084+ debit_element_id : str ,
2085+ credit_element_id : str ,
2086+ entry_type : str = "closing" ,
2087+ memo_template : str = "" ,
2088+ taxonomy_id : str | None = None ,
2089+ method : str | None = None ,
2090+ original_amount : int | None = None ,
2091+ residual_value : int | None = None ,
2092+ useful_life_months : int | None = None ,
2093+ asset_element_id : str | None = None ,
2094+ auto_reverse : bool = False ,
2095+ booked_on : str | None = None ,
2096+ entity_id : str | None = None ,
2097+ periodic_amounts : list [int ] | None = None ,
2098+ loan_terms : dict [str , Any ] | None = None ,
2099+ legs : list [dict [str , Any ]] | None = None ,
2100+ dimension_ids : list [str ] | None = None ,
2101+ replaces_structure_id : str | None = None ,
2102+ closed_through : str | None = None ,
2103+ ) -> PreviewScheduleResponse :
2104+ """Generate a schedule from a definition without keeping it.
2105+
2106+ The same generator and guards as :meth:`create_schedule`, run and
2107+ rolled back. The response carries ``envelope`` (what create would leave;
2108+ its ids provisional), ``roll_forward`` (the balance the schedule carries
2109+ period by period, with a loan's interest, payment, principal and current
2110+ portion) and ``warnings`` naming any active schedule already posting the
2111+ same accounts in the same months. A definition create would refuse is
2112+ refused here with the period that breaks. With ``replaces_structure_id``
2113+ (the schedule being edited or recreated), ``replaces`` says what it has
2114+ posted and the path the change takes: ``rebuild`` (save through
2115+ :meth:`rebuild_schedule`) while nothing has posted,
2116+ ``terminate_and_succeed`` after.
2117+ """
2118+ payload_dict = self ._schedule_payload (
2119+ name = name ,
2120+ element_ids = element_ids ,
2121+ period_start = period_start ,
2122+ period_end = period_end ,
2123+ monthly_amount = monthly_amount ,
2124+ debit_element_id = debit_element_id ,
2125+ credit_element_id = credit_element_id ,
2126+ entry_type = entry_type ,
2127+ memo_template = memo_template ,
2128+ taxonomy_id = taxonomy_id ,
2129+ method = method ,
2130+ original_amount = original_amount ,
2131+ residual_value = residual_value ,
2132+ useful_life_months = useful_life_months ,
2133+ asset_element_id = asset_element_id ,
2134+ auto_reverse = auto_reverse ,
2135+ booked_on = booked_on ,
2136+ entity_id = entity_id ,
2137+ periodic_amounts = periodic_amounts ,
2138+ loan_terms = loan_terms ,
2139+ legs = legs ,
2140+ dimension_ids = dimension_ids ,
2141+ closed_through = closed_through ,
2142+ )
2143+ if replaces_structure_id :
2144+ payload_dict ["replaces_structure_id" ] = replaces_structure_id
2145+ body = PreviewScheduleRequest .from_dict (payload_dict )
2146+ response = op_preview_schedule (
2147+ graph_id = graph_id , body = body , client = self ._get_client ()
2148+ )
2149+ envelope = self ._call_op ("Preview schedule" , response )
2150+ return self ._typed_result ("Preview schedule" , envelope , PreviewScheduleResponse )
2151+
19842152 def dispose_schedule (
19852153 self ,
19862154 graph_id : str ,
@@ -2118,6 +2286,11 @@ def rebuild_schedule(
21182286 structure_id : str ,
21192287 * ,
21202288 idempotency_key : str | None = None ,
2289+ period_start : str | None = None ,
2290+ period_end : str | None = None ,
2291+ monthly_amount : int | None = None ,
2292+ entry_template : dict [str , Any ] | None = None ,
2293+ schedule_metadata : dict [str , Any ] | None = None ,
21212294 ) -> ScheduleCreatedResponse :
21222295 """Rebuild a schedule in place — re-run the generator on an existing schedule.
21232296
@@ -2132,11 +2305,31 @@ def rebuild_schedule(
21322305 the schedule to today's close state. Use this to pick up a fixed
21332306 generator without orphaning obligations.
21342307
2308+ It is also how an edit is saved while nothing has posted:
2309+ ``period_start``, ``period_end``, ``monthly_amount``, ``entry_template``
2310+ (replacing the stored one whole) and ``schedule_metadata`` (only the
2311+ fields named) replace the stored definition before it regenerates, as
2312+ the schedule's envelope reads them back (``artifact.mechanics``).
2313+ Omitted fields keep their stored values. Refused once an entry has
2314+ posted; :meth:`preview_schedule` with ``replaces_structure_id`` says
2315+ which path an edit takes.
2316+
21352317 Supply ``idempotency_key`` to make the call safe to retry — replays
21362318 within 24 hours return the same envelope. Reusing the key with a
21372319 different body returns HTTP 409.
21382320 """
2139- body = RebuildScheduleRequest (structure_id = structure_id )
2321+ body_dict : dict [str , Any ] = {"structure_id" : structure_id }
2322+ if period_start is not None :
2323+ body_dict ["period_start" ] = period_start
2324+ if period_end is not None :
2325+ body_dict ["period_end" ] = period_end
2326+ if monthly_amount is not None :
2327+ body_dict ["monthly_amount" ] = monthly_amount
2328+ if entry_template is not None :
2329+ body_dict ["entry_template" ] = entry_template
2330+ if schedule_metadata is not None :
2331+ body_dict ["schedule_metadata" ] = schedule_metadata
2332+ body = RebuildScheduleRequest .from_dict (body_dict )
21402333 response = op_rebuild_schedule (
21412334 graph_id = graph_id ,
21422335 body = body ,
0 commit comments