moysklad 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +1 -0
- data/README.md +14 -3
- data/lib/moysklad.rb +3 -2
- data/lib/moysklad/client.rb +37 -10
- data/lib/moysklad/client/errors.rb +60 -30
- data/lib/moysklad/entities.rb +17 -21
- data/lib/moysklad/entities/assortment.rb +6 -0
- data/lib/moysklad/entities/attachment_document.rb +16 -0
- data/lib/moysklad/entities/attribute.rb +114 -37
- data/lib/moysklad/entities/attribute_metadata.rb +9 -31
- data/lib/moysklad/entities/attribute_value.rb +19 -0
- data/lib/moysklad/entities/barcode.rb +10 -4
- data/lib/moysklad/entities/base.rb +23 -8
- data/lib/moysklad/entities/bundle.rb +39 -0
- data/lib/moysklad/entities/characteristic.rb +6 -0
- data/lib/moysklad/entities/characteristic_metadata.rb +6 -0
- data/lib/moysklad/entities/collection.rb +30 -7
- data/lib/moysklad/entities/collection_meta.rb +11 -0
- data/lib/moysklad/entities/common_object.rb +0 -2
- data/lib/moysklad/entities/company_settings_metadata.rb +28 -0
- data/lib/moysklad/entities/consignment.rb +19 -17
- data/lib/moysklad/entities/context.rb +9 -0
- data/lib/moysklad/entities/counterparty.rb +18 -0
- data/lib/moysklad/entities/currency.rb +29 -0
- data/lib/moysklad/entities/custom_entity.rb +20 -10
- data/lib/moysklad/entities/custom_entity_metadata.rb +7 -32
- data/lib/moysklad/entities/customer_order.rb +116 -23
- data/lib/moysklad/entities/customer_order_position.rb +10 -18
- data/lib/moysklad/entities/employee.rb +7 -0
- data/lib/moysklad/entities/entity.rb +42 -0
- data/lib/moysklad/entities/good_folder.rb +1 -0
- data/lib/moysklad/entities/group.rb +7 -0
- data/lib/moysklad/entities/image.rb +17 -0
- data/lib/moysklad/entities/images.rb +10 -0
- data/lib/moysklad/entities/meta.rb +14 -0
- data/lib/moysklad/entities/organization.rb +19 -0
- data/lib/moysklad/entities/owner.rb +4 -0
- data/lib/moysklad/entities/price.rb +5 -8
- data/lib/moysklad/entities/price_type.rb +2 -8
- data/lib/moysklad/entities/product.rb +54 -0
- data/lib/moysklad/entities/productfolder.rb +13 -0
- data/lib/moysklad/entities/rate.rb +9 -0
- data/lib/moysklad/entities/resource_metadata.rb +13 -0
- data/lib/moysklad/entities/service.rb +28 -0
- data/lib/moysklad/entities/shortcut.rb +11 -0
- data/lib/moysklad/entities/store.rb +10 -0
- data/lib/moysklad/entities/time.rb +13 -0
- data/lib/moysklad/entities/uom.rb +7 -0
- data/lib/moysklad/entities/variant.rb +51 -0
- data/lib/moysklad/entities/workflow.rb +11 -0
- data/lib/moysklad/entities/workflow_state.rb +8 -0
- data/lib/moysklad/error.rb +1 -0
- data/lib/moysklad/resources.rb +9 -7
- data/lib/moysklad/resources/assortments.rb +14 -0
- data/lib/moysklad/resources/base.rb +32 -44
- data/lib/moysklad/resources/custom_entities.rb +27 -0
- data/lib/moysklad/resources/custom_entity_metadata.rb +12 -8
- data/lib/moysklad/resources/embedded_entity_metadata.rb +0 -1
- data/lib/moysklad/resources/indexed.rb +23 -35
- data/lib/moysklad/resources/indexed_cache.rb +36 -0
- data/lib/moysklad/resources/load_all.rb +21 -0
- data/lib/moysklad/resources/products.rb +10 -0
- data/lib/moysklad/resources/where_filter.rb +0 -1
- data/lib/moysklad/universe.rb +16 -2
- data/lib/moysklad/version.rb +1 -1
- data/moysklad.gemspec +3 -1
- data/scripts/rest.sh +5 -2
- data/spec/fixtures/Good_WithManyAttributes.raw +13 -0
- data/spec/fixtures/Workflow_list.raw +15 -0
- data/spec/fixtures/good_with_image.xml +39 -0
- data/spec/lib/moysklad/entities/customer_order_spec.rb +7 -2
- data/spec/lib/moysklad/entities/good_spec.rb +9 -0
- data/spec/lib/moysklad/resources/workflows_spec.rb +21 -0
- data/spec/spec_helper.rb +2 -1
- data/test.rb +177 -0
- metadata +97 -44
- data/lib/moysklad/entities/common.rb +0 -15
- data/lib/moysklad/entities/feature.rb +0 -20
- data/lib/moysklad/entities/good.rb +0 -34
- data/lib/moysklad/entities/stock_to.rb +0 -33
- data/lib/moysklad/entities/warehouse.rb +0 -15
- data/lib/moysklad/entities/xml_fix.rb +0 -15
@@ -1,38 +1,16 @@
|
|
1
|
+
require_relative 'attribute_value'
|
2
|
+
|
1
3
|
module Moysklad::Entities
|
2
|
-
# https://online.moysklad.ru/exchange/rest/ms/xml/Metadata/list
|
3
4
|
class AttributeMetadata < Base
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
# STRING
|
11
|
-
attribute :attrType, String
|
12
|
-
attribute :entityMetadataUuid, String
|
13
|
-
attribute :feature, Boolean
|
14
|
-
attribute :position, Integer
|
15
|
-
attribute :required, Boolean
|
16
|
-
attribute :dictionaryMetadataUuid, String
|
5
|
+
attribute :meta, Meta
|
6
|
+
attribute :id, String
|
7
|
+
attribute :name, String
|
8
|
+
attribute :type, String # string, customentity
|
9
|
+
attribute :required, Boolean
|
10
|
+
attribute :customEntityMeta, Meta
|
17
11
|
|
18
12
|
def is_dictionary?
|
19
|
-
|
20
|
-
end
|
21
|
-
|
22
|
-
# Если это свойство типа ID_CUSTOM, то возвращается пользовательский справочник
|
23
|
-
#
|
24
|
-
# @return Moysklad::Entities::CustomEntityMetadata
|
25
|
-
def dictionatyMetadata universe
|
26
|
-
raise "Это свойства не типа справочник" unless dictionaryMetadataUuid
|
27
|
-
universe.custom_entity_metadata.find dictionaryMetadataUuid
|
28
|
-
end
|
29
|
-
|
30
|
-
# Справочник к которому принадлежит это ссвойство
|
31
|
-
#
|
32
|
-
# @return Moysklad::Entities::EmbeddedEntityMetadata
|
33
|
-
def entityMetadata universe
|
34
|
-
universe.embedded_entity_metadata.find entityMetadataUuid
|
13
|
+
type == 'customentity'
|
35
14
|
end
|
36
|
-
|
37
15
|
end
|
38
16
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require_relative 'custom_entity'
|
2
|
+
|
3
|
+
module Moysklad::Entities
|
4
|
+
class AttributeValue < Virtus::Attribute
|
5
|
+
def coerce(value)
|
6
|
+
if value.is_a? String
|
7
|
+
value
|
8
|
+
elsif value.is_a? ::Hash
|
9
|
+
if value['meta']['type'] == 'customentity'
|
10
|
+
CustomEntity.new value
|
11
|
+
else
|
12
|
+
raise "Unknown meta type: #{value['meta']['type']}"
|
13
|
+
end
|
14
|
+
else
|
15
|
+
raise "Unknown value type (#{value}) #{value.class}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -1,13 +1,19 @@
|
|
1
1
|
module Moysklad::Entities
|
2
2
|
class Barcode < Base
|
3
|
-
include
|
3
|
+
include HappyMapper
|
4
|
+
include Moysklad::Entities::XmlFix
|
4
5
|
|
5
6
|
tag 'barcode'
|
6
7
|
|
7
|
-
attribute :barcode,
|
8
|
-
# EAN13
|
8
|
+
attribute :barcode, String
|
9
9
|
attribute :barcodeType, String
|
10
10
|
|
11
|
+
attribute :accountUuid, String
|
12
|
+
attribute :accountId, String
|
13
|
+
attribute :uuid, String
|
14
|
+
attribute :groupUuid, String
|
15
|
+
attribute :ownerUuid, String
|
16
|
+
|
17
|
+
attribute :shared, Boolean
|
11
18
|
end
|
12
19
|
end
|
13
|
-
|
@@ -1,16 +1,31 @@
|
|
1
1
|
module Moysklad::Entities
|
2
2
|
class Base
|
3
|
-
|
3
|
+
include Virtus.model
|
4
|
+
attr_accessor :universe
|
5
|
+
attr_accessor :dump
|
4
6
|
|
5
|
-
|
7
|
+
def self.build(data, universe)
|
8
|
+
entity = new data
|
9
|
+
entity.universe = universe
|
10
|
+
entity
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize(data = {})
|
14
|
+
data['attrs'] = data.delete 'attributes' if data['attributes']
|
15
|
+
super (data || {}).merge(dump: data)
|
16
|
+
end
|
6
17
|
|
7
|
-
def
|
8
|
-
|
9
|
-
|
10
|
-
|
18
|
+
def to_json(*args)
|
19
|
+
presented = {}
|
20
|
+
to_h.each_pair do |k, v|
|
21
|
+
presented[k] = v unless v.nil?
|
22
|
+
end
|
23
|
+
|
24
|
+
presented.to_json
|
25
|
+
end
|
11
26
|
|
12
|
-
|
13
|
-
|
27
|
+
def to_s
|
28
|
+
attributes.to_s
|
14
29
|
end
|
15
30
|
end
|
16
31
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Moysklad::Entities
|
2
|
+
# Комплект
|
3
|
+
# https://online.moysklad.ru/api/remap/1.1/doc/index.html#комплект
|
4
|
+
class Bundle < Product
|
5
|
+
#meta - Метаданные объекта
|
6
|
+
#id - ID Комплекта в формате UUID Только для чтения
|
7
|
+
#accountId - ID учетной записи Только для чтения
|
8
|
+
#owner - Ссылка на Владельца (Сотрудника) в формате Метаданных
|
9
|
+
#shared - Общий доступ
|
10
|
+
#group - Отдел сотрудника в формате Метаданных
|
11
|
+
#syncId - ID синхронизации Только для чтения
|
12
|
+
#version - Версия сущности Только для чтения
|
13
|
+
#updated - Момент последнего обновления сущности Только для чтения
|
14
|
+
#name - Наименование Комплекта Необходимое
|
15
|
+
#description - Описание Комплекта
|
16
|
+
#code - Код Комплекта
|
17
|
+
#externalCode - Внешний код Комплекта
|
18
|
+
#archived - Отметка о том, добавлен ли Комплект в архив
|
19
|
+
#pathName - Наименование группы, в которую входит Комплект Только для чтения
|
20
|
+
#vat - НДС %
|
21
|
+
#effectiveVat - Реальный НДС % Только для чтения
|
22
|
+
#productFolder - Ссылка на группу Комплекта
|
23
|
+
#uom - Единицы измерения
|
24
|
+
#image - Изображение Комплекта Только для чтения
|
25
|
+
#minPrice - Минимальная цена
|
26
|
+
#salePrices - Цены продажи
|
27
|
+
#attributes - Коллекция доп. полей в формате Метаданных
|
28
|
+
#country - Ссылка на страну в формате Метаданных
|
29
|
+
#article - Артикул
|
30
|
+
#weight - Вес
|
31
|
+
#volume - Объём
|
32
|
+
#barcodes - Массив штрихкодов Комплекта
|
33
|
+
#overhead - Дополнительные расходы
|
34
|
+
#currency - Валюта доп расходов
|
35
|
+
#value - Значение доп расходов
|
36
|
+
#components - Компоненты Комплекта
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
@@ -1,12 +1,35 @@
|
|
1
|
+
require_relative 'context'
|
2
|
+
require_relative 'collection_meta'
|
3
|
+
|
1
4
|
module Moysklad::Entities
|
2
|
-
class
|
3
|
-
|
4
|
-
|
5
|
-
|
5
|
+
class RowItems < Virtus::Attribute
|
6
|
+
include ActiveSupport::Inflector
|
7
|
+
|
8
|
+
def coerce(items)
|
9
|
+
items.map do |item|
|
10
|
+
type = item['meta']['type']
|
11
|
+
entity_class = find_entity_class type
|
12
|
+
entity_class.new item
|
13
|
+
end
|
14
|
+
end
|
6
15
|
|
7
|
-
|
8
|
-
attribute :start, Integer
|
9
|
-
attribute :count, Integer
|
16
|
+
private
|
10
17
|
|
18
|
+
def find_entity_class(type)
|
19
|
+
case type
|
20
|
+
when 'customentity'
|
21
|
+
Moysklad::Entities::CustomEntity
|
22
|
+
else
|
23
|
+
class_name = 'Moysklad::Entities::' + camelize(type)
|
24
|
+
raise Moysklad::Error, "No entity class for #{type} type" unless Object.const_defined? class_name
|
25
|
+
constantize class_name
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
class Collection < Base
|
31
|
+
attribute :context, Context
|
32
|
+
attribute :meta, CollectionMeta
|
33
|
+
attribute :rows, RowItems
|
11
34
|
end
|
12
35
|
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Moysklad::Entities
|
2
|
+
class CollectionMeta < Meta
|
3
|
+
# Следующие атрибуты объекта meta появляются, как правило, в методах выдачи списка сущностей/строк отчёта
|
4
|
+
attribute :size, Integer
|
5
|
+
attribute :limit, Integer
|
6
|
+
attribute :offset, Integer
|
7
|
+
|
8
|
+
attribute :nextHref, String
|
9
|
+
attribute :prevHref, String
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require_relative 'meta'
|
2
|
+
|
3
|
+
module Moysklad::Entities
|
4
|
+
class EntityMeta < Base
|
5
|
+
attribute :href, String
|
6
|
+
attribute :type, String
|
7
|
+
attribute :mediaType, String
|
8
|
+
end
|
9
|
+
|
10
|
+
class CompanySettingsCustomEntity < Base
|
11
|
+
attribute :meta, Meta
|
12
|
+
attribute :entityMeta, EntityMeta
|
13
|
+
attribute :name, String
|
14
|
+
|
15
|
+
def id
|
16
|
+
meta.id
|
17
|
+
end
|
18
|
+
|
19
|
+
def entities(universe)
|
20
|
+
Moysklad::Resources::CustomEntities.indexed(client: universe.client, list_path: entityMeta.href).all
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class CompanySettingsMetadata < Base
|
25
|
+
attribute :meta, Meta
|
26
|
+
attribute :customEntities, Array[CompanySettingsCustomEntity]
|
27
|
+
end
|
28
|
+
end
|
@@ -1,22 +1,24 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
class Consignment < Base
|
4
|
-
include Common
|
5
|
-
|
6
|
-
tag 'consignment'
|
7
|
-
|
8
|
-
attribute :updated, Time
|
9
|
-
attribute :updatedBy, String
|
1
|
+
require_relative 'entity'
|
2
|
+
require_relative 'assortment'
|
10
3
|
|
11
|
-
|
12
|
-
|
13
|
-
attribute :
|
14
|
-
attribute :
|
15
|
-
|
16
|
-
attribute :
|
4
|
+
module Moysklad::Entities
|
5
|
+
class Consignment < Entity
|
6
|
+
attribute :meta, Meta
|
7
|
+
attribute :id, String
|
8
|
+
attribute :version, Integer
|
9
|
+
attribute :updated, String
|
10
|
+
attribute :name, String
|
11
|
+
attribute :label, String
|
12
|
+
attribute :externalCode, String
|
13
|
+
attribute :archived, Boolean
|
17
14
|
|
18
|
-
|
15
|
+
attribute :accountId, String
|
16
|
+
attribute :assortment, Assortment
|
19
17
|
|
20
|
-
|
18
|
+
# Когда загружаем через ассортименты эти поля устанавливаются
|
19
|
+
attribute :stock, Float
|
20
|
+
attribute :reserve, Float
|
21
|
+
attribute :inTransit, Float
|
22
|
+
attribute :quantity, Float
|
21
23
|
end
|
22
24
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require_relative 'entity'
|
2
|
+
|
3
|
+
module Moysklad::Entities
|
4
|
+
class Counterparty < Entity
|
5
|
+
attribute :email, String
|
6
|
+
attribute :phone, String
|
7
|
+
attribute :fax, String
|
8
|
+
attribute :tags, Array[String]
|
9
|
+
|
10
|
+
attribute :actualAddress, String
|
11
|
+
attribute :legalTitle, String
|
12
|
+
attribute :legalAddress, String
|
13
|
+
attribute :inn, String
|
14
|
+
attribute :kpp, String
|
15
|
+
attribute :ogrn, String
|
16
|
+
attribute :okpo, String
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require_relative 'meta'
|
2
|
+
|
3
|
+
module Moysklad::Entities
|
4
|
+
class Currency < Base
|
5
|
+
class Unit < Base
|
6
|
+
attribute :gender, String
|
7
|
+
attribute :s1, String
|
8
|
+
attribute :s2, String
|
9
|
+
attribute :s5, String
|
10
|
+
end
|
11
|
+
attribute :meta, Meta
|
12
|
+
attribute :system, Boolean
|
13
|
+
attribute :name, String
|
14
|
+
attribute :fullName, String
|
15
|
+
attribute :rate, Float
|
16
|
+
attribute :multiplicity, Integer
|
17
|
+
attribute :rateUpdateType, String
|
18
|
+
attribute :code, String
|
19
|
+
attribute :isoCode, String
|
20
|
+
attribute :majorUnit, Unit
|
21
|
+
attribute :minorUnit, Unit
|
22
|
+
attribute :archived, Boolean
|
23
|
+
attribute :default, Boolean
|
24
|
+
|
25
|
+
def id
|
26
|
+
meta.href.split('/').last
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -1,18 +1,28 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
require_relative 'meta'
|
2
|
+
require_relative 'context'
|
3
|
+
|
4
|
+
# Элемент в справочнике (DictionaryEntity)
|
4
5
|
module Moysklad::Entities
|
5
6
|
class CustomEntity < Base
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
attribute :meta, Meta
|
8
|
+
attribute :accountId, String
|
9
|
+
attribute :id, String
|
10
|
+
attribute :name, String
|
11
|
+
attribute :externalCode, String
|
12
|
+
attribute :description, String
|
10
13
|
|
11
|
-
|
14
|
+
# TODO remove
|
15
|
+
def entityMetadataUuid
|
16
|
+
dictionaryId
|
17
|
+
end
|
12
18
|
|
13
|
-
|
14
|
-
|
19
|
+
# ID Словаря
|
20
|
+
def dictionaryId
|
21
|
+
meta.metadataHref.split('/').last
|
15
22
|
end
|
16
23
|
|
24
|
+
def to_s
|
25
|
+
name
|
26
|
+
end
|
17
27
|
end
|
18
28
|
end
|
@@ -1,36 +1,11 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
# Пользовательский справочник
|
4
|
-
#
|
1
|
+
require_relative 'meta'
|
2
|
+
raise 'не используется'
|
5
3
|
module Moysklad::Entities
|
6
4
|
class CustomEntityMetadata < Base
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
attribute :uniqueCode, Boolean
|
13
|
-
attribute :codeValueType, Integer
|
14
|
-
attribute :independentNameGenerator, Boolean
|
15
|
-
|
16
|
-
attribute :partialReserve, Boolean
|
17
|
-
|
18
|
-
attribute :editOnlyByAuthor, Boolean
|
19
|
-
|
20
|
-
attribute :noEditFromOtherPlaceSource, Boolean
|
21
|
-
|
22
|
-
attribute :noApplicableFromOtherPlaceSource, Boolean
|
23
|
-
|
24
|
-
attribute :noEditFromOtherPlaceTarget, Boolean
|
25
|
-
|
26
|
-
attribute :noApplicableFromOtherPlaceTarget, Boolean
|
27
|
-
|
28
|
-
# Список перечисляемых значений данного справочника
|
29
|
-
#
|
30
|
-
# @return [Array[CustomEntity]]
|
31
|
-
def entities universe
|
32
|
-
universe.custom_entities.where entityMetadataUuid: uuid
|
33
|
-
end
|
34
|
-
|
5
|
+
attribute :meta, Meta
|
6
|
+
attribute :id, String
|
7
|
+
attribute :name, String
|
8
|
+
attribute :type, String # string, customentity
|
9
|
+
attribute :required, Boolean
|
35
10
|
end
|
36
11
|
end
|