< Summary

Information
Class: Services.BitrixStockServices.BitrixStockExceptionReportAnnotator
Assembly: Services
File(s): /home/runner/work/Studio2Prod/Studio2Prod/AppRepository/BitrixStockServices/BitrixStockExceptionReportAnnotator.cs
Line coverage
100%
Covered lines: 41
Uncovered lines: 0
Coverable lines: 41
Total lines: 120
Line coverage: 100%
Branch coverage
97%
Covered branches: 47
Total branches: 48
Branch coverage: 97.9%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
HasStockSkip(...)100%66100%
FormatFullNote(...)100%22100%
FormatPriceOnlyNote(...)100%22100%
AppendToNote(...)100%44100%
ApplyPriceNotesToLines(...)100%44100%
CollectParts(...)96.66%3030100%

File(s)

/home/runner/work/Studio2Prod/Studio2Prod/AppRepository/BitrixStockServices/BitrixStockExceptionReportAnnotator.cs

#LineLine coverage
 1using OzonDomains.Models;
 2
 3namespace Services.BitrixStockServices;
 4
 5/// <summary>Подписи исключений в строках отчёта BitrixStock.</summary>
 6internal static class BitrixStockExceptionReportAnnotator
 7{
 8    public const string NotePrefix = "Исключения — ";
 9
 10    public static bool HasStockSkip(
 11        string article,
 12        HashSet<string> skipStockArticles,
 13        BitrixStockExceptionStockRule? stockRule)
 14    {
 1015        if (string.IsNullOrWhiteSpace(article)) return false;
 416        return skipStockArticles.Contains(article)
 417               || stockRule?.StockMode == BitrixStockStockMode.Skip;
 18    }
 19
 20    /// <summary>Все исключения артикула для кабинета (остатки + цены).</summary>
 21    public static string FormatFullNote(
 22        string article,
 23        int clientId,
 24        HashSet<string> skipStockArticles,
 25        HashSet<string> skipPriceArticles,
 26        Dictionary<(string article, int clientId), BitrixStockExceptionClientPrice> priceMap,
 27        BitrixStockExceptionStockRule? stockRule)
 28    {
 1329        var parts = CollectParts(article, clientId, skipStockArticles, skipPriceArticles, priceMap, stockRule,
 1330            includeStock: true, includePrice: true);
 1331        return parts.Count == 0 ? string.Empty : NotePrefix + string.Join("; ", parts);
 32    }
 33
 34    /// <summary>Только ценовые исключения (для строк с обычным накатом остатков).</summary>
 35    public static string FormatPriceOnlyNote(
 36        string article,
 37        int clientId,
 38        HashSet<string> skipPriceArticles,
 39        Dictionary<(string article, int clientId), BitrixStockExceptionClientPrice> priceMap)
 40    {
 541        var parts = CollectParts(article, clientId, null, skipPriceArticles, priceMap, null,
 542            includeStock: false, includePrice: true);
 543        return parts.Count == 0 ? string.Empty : NotePrefix + string.Join("; ", parts);
 44    }
 45
 46    public static void AppendToNote(BitrixStockSyncReportWarehouseLineDto line, string exceptionNote)
 47    {
 1448        if (string.IsNullOrWhiteSpace(exceptionNote)) return;
 649        line.Note = string.IsNullOrWhiteSpace(line.Note)
 650            ? exceptionNote
 651            : $"{line.Note} | {exceptionNote}";
 652    }
 53
 54    public static void ApplyPriceNotesToLines(
 55        IEnumerable<BitrixStockSyncReportWarehouseLineDto> lines,
 56        int clientId,
 57        HashSet<string> skipPriceArticles,
 58        Dictionary<(string article, int clientId), BitrixStockExceptionClientPrice> priceMap)
 59    {
 2260        foreach (var line in lines)
 61        {
 662            if (string.IsNullOrWhiteSpace(line.Article)) continue;
 363            var priceNote = FormatPriceOnlyNote(line.Article, clientId, skipPriceArticles, priceMap);
 364            AppendToNote(line, priceNote);
 65        }
 566    }
 67
 68    private static List<string> CollectParts(
 69        string article,
 70        int clientId,
 71        HashSet<string>? skipStockArticles,
 72        HashSet<string> skipPriceArticles,
 73        Dictionary<(string article, int clientId), BitrixStockExceptionClientPrice> priceMap,
 74        BitrixStockExceptionStockRule? stockRule,
 75        bool includeStock,
 76        bool includePrice)
 77    {
 1878        var parts = new List<string>();
 79
 1880        if (includeStock && skipStockArticles != null)
 81        {
 1382            if (skipStockArticles.Contains(article))
 83            {
 384                parts.Add("остатки: глобальный справочник, пропуск (все кабинеты)");
 85            }
 1086            else if (stockRule?.StockMode == BitrixStockStockMode.Skip)
 87            {
 388                var scope = stockRule.OzonClientId == null ? "все кабинеты" : $"кабинет #{clientId}";
 389                var comment = string.IsNullOrWhiteSpace(stockRule.Comment) ? "" : $" — {stockRule.Comment}";
 390                parts.Add($"остатки: правило, пропуск ({scope}){comment}");
 91            }
 92        }
 93
 1894        if (!includePrice) return parts;
 95
 1896        if (skipPriceArticles.Contains(article))
 497            parts.Add("цены: глобальный справочник, пропуск (все кабинеты)");
 98
 1899        if (priceMap.TryGetValue((article.ToLowerInvariant(), clientId), out var priceRule))
 100        {
 7101            var comment = string.IsNullOrWhiteSpace(priceRule.Comment) ? "" : $" — {priceRule.Comment}";
 7102            switch (priceRule.PriceMode)
 103            {
 104                case BitrixStockPriceMode.Skip:
 4105                    parts.Add($"цены: правило кабинета #{clientId}, пропуск{comment}");
 4106                    break;
 3107                case BitrixStockPriceMode.Fixed when priceRule.FixedPrice.HasValue:
 108                {
 2109                    var old = priceRule.FixedOldPrice.HasValue
 2110                        ? $", старая {priceRule.FixedOldPrice.Value:N0} ₽"
 2111                        : "";
 2112                    parts.Add($"цены: правило кабинета #{clientId}, фикс. {priceRule.FixedPrice.Value:N0} ₽{old}{comment
 113                    break;
 114                }
 115            }
 116        }
 117
 18118        return parts;
 119    }
 120}

Methods/Properties

HasStockSkip(System.String,System.Collections.Generic.HashSet`1<System.String>,OzonDomains.Models.BitrixStockExceptionStockRule)
FormatFullNote(System.String,System.Int32,System.Collections.Generic.HashSet`1<System.String>,System.Collections.Generic.HashSet`1<System.String>,System.Collections.Generic.Dictionary`2<System.ValueTuple`2<System.String,System.Int32>,OzonDomains.Models.BitrixStockExceptionClientPrice>,OzonDomains.Models.BitrixStockExceptionStockRule)
FormatPriceOnlyNote(System.String,System.Int32,System.Collections.Generic.HashSet`1<System.String>,System.Collections.Generic.Dictionary`2<System.ValueTuple`2<System.String,System.Int32>,OzonDomains.Models.BitrixStockExceptionClientPrice>)
AppendToNote(Services.BitrixStockServices.BitrixStockSyncReportWarehouseLineDto,System.String)
ApplyPriceNotesToLines(System.Collections.Generic.IEnumerable`1<Services.BitrixStockServices.BitrixStockSyncReportWarehouseLineDto>,System.Int32,System.Collections.Generic.HashSet`1<System.String>,System.Collections.Generic.Dictionary`2<System.ValueTuple`2<System.String,System.Int32>,OzonDomains.Models.BitrixStockExceptionClientPrice>)
CollectParts(System.String,System.Int32,System.Collections.Generic.HashSet`1<System.String>,System.Collections.Generic.HashSet`1<System.String>,System.Collections.Generic.Dictionary`2<System.ValueTuple`2<System.String,System.Int32>,OzonDomains.Models.BitrixStockExceptionClientPrice>,OzonDomains.Models.BitrixStockExceptionStockRule,System.Boolean,System.Boolean)