Setting COM compound 1C 8.3. Three whales of work with COM objects. Work through the COM connection is easier than you think. Receipt and comparison of transfer via COM connection

One way to transfer data from one configuration 1C to another is software connection With COM. Many companies use several different bases, between which certain relations must be and dependencies. If it is necessary not only to transfer data, but also to perform a specific data processing, then the COM connection will be the best mechanism. The ability to analyze data from another database 1c is useful to any developer.

Connect through the COM to the database 1c

To implement the COM connection in 1C, a special mechanism called ComConnector is used. This object is installed along with the platform and is used for communication. information bases. It should be noted that for versions 8.2 and 8.3, different objects are used - "V82.Connector" and "V83.comConnector" respectively.

Remember that on the COM connection to the database to spend a license - it is not necessary to get involved in the simultaneous execution of multiple connections. This is especially important for organizations whose number of licenses is limited. This question can be decided with the help of regulatory tasks running during the absence. active connections Users to the information base.

To be able to connect to another database and request necessary information You need to know the following data:

  1. What kind of type is - file or client-server;
  2. Where it is located;
  3. Under what name and password can go to it;
  4. What data are you interested in.

From the first three items to implement the COM connection, you must form the parameter string. Depending on the type of IB, it will be different external species. Using the resulting string, a connection is connected, which can be collected for analysis and processing data from another database by any methods.

Parameters Conference FileBeib \u003d "FILE \u003d" "path_base" ""; usr \u003d "" username "" "; pwd \u003d" "" password "" "; Parameters ConclusionsClinSerVerVeb \u003d "srvr \u003d" "server_name" ""; ref \u003d "" Base name ""; usr \u003d "" username "" "; pwd \u003d" "Password" "";

The connection feature is simple and should not cause questions if all parameters are correct. To speed up debugging and analyzing possible errors It is better to conclude a connection in the "Attempt" design. Return the function will be the value of the "COM object" type, with which you have to work, getting the necessary data.

& Nasserver Connect function () Export parameters ConclusionsIb \u003d "FILE \u003d" "E: \\ Base 1C \\ ERP" "; usr \u003d" "Administrator" "; pwd \u003d" "1" ""; V83Comcon \u003d new co-object ("v83.comconnector"); Attempt to return V83COMCON.CONNECT (Parameters Power Points); Exception to inform (Description ()); Return is undefined; Celebrations; Endfunction

Through the COM connection you can not only select data, but also add them to the database to which you connect. Remember that we can transmit an object with a COM 4 primitive data types. Other types will have to be specified using the search functions built into the platform. Note that global functions Platforms are also called through the COM connection.

We receive data from the 1C base

After you have received the desired object, you need to read the data from another base. To do this, we apply a request via COM connection to 1C 8.3 using the resulting "COM object" type from the function. It is important to first connect to the database, and then perform a request. Execution occurs through the NewObject method with an indication as an object type parameter in a string form - "Request".

& Nasserver Tests Mechanical Procedure () Connection \u003d Connect (); If typcouch (connection) type ("undefined") then Request \u003d connection.NewObject ("query"); Request. Text \u003d "Select the first 15 | DirectoryProduction. Name as a name | From | Directory. Users as a directory"; Sampling \u003d Request. Fill (). Select (); While the sample. The next () cycle is reported (sampling. EndCycle; Ended; Extra-Procedure\u003e

For example, to obtain information about users of a specific unit, set the condition to the request through the parameters. One parameter will be a simple type - a string, and the unit is referenced by the reference book "Enterprise structure". The result of the query is a table with the listed fields of the type that they exist in the database to which the COM connection occurred. If you need to convert them to other types - use standard functions Platforms:

  • Line();
  • Number();
  • Date().
Request \u003d connection.NewObject ("query"); Requescribe. Text \u003d "Select the first 15 | DirectoryAdenz. Name as name | From | Directory. Users as a Directory of Handbook I WHERE | Directory Administration \u003d & Supplies | And Reference Plug. Naming Like"% "" + ""% " ; Request. Installation parameter ("Desktoming", compound. Runs. StructurePredit. EntryPocode ("00-000023")); Request. Installation parameter ("desired", "Catherine"); Sampling \u003d Request. Fill (). Select (); While the sample. The next () cycle is reported (sampling. Name); EndCycle;

If you want to send an array to the database to select several parameters, for example, units, the NewObject command is also used. Similarly, you can transfer a list or table of values \u200b\u200bby filling them with elements of another database through the connection. All existing methods of objects and platform mechanisms are available to you.

Request \u003d connection.NewObject. ("Query"); Requescribably .text \u003d "Select the first 15 | DirectoryProduction. Name as name | From | Directory. Users as a Directorypolf I, where | Directory Additive in (& Description) | And Rebukefold. Namination Limit ""; Massputs \u003d connection.newObject ("array"); Massput forces. Addly (compound. Pravnochniki. Structural enterprise. Entripotype ("00-000023")); Massputs forces. Addly (compound. Runs. Structural enterprise. EntryPocus ("00-000038")); Massput forces. Addly (compound. Frames. Structural enterprise. Entripotype ("00-000046")); Request. Installation parameter ("desired for division", array); Request. Installation parameter ("desired", "Catherine"); Sampling \u003d Request. Fill (). Select (); While the sample. The next () cycle is reported (sampling. Name); EndCycle;

When transferring documents or reference elements, the question of controlling the transfer of a certain object is always arising. Using COM connections, such problems can be solved through a unique identifier. You need to find an object in the connected database on the identifier from the current IB using the "Dressline" function using the identifier in the form of a string. If this was not found, you can create it with a COM connection.

Strider \u003d Row (directories. Users. LightPocode ("00-0000313"). Unique Selfentifier ()); If it is not denominated (connection. Runs. Users. Pereskliklka (connection .NewObject ("Unique Selfentifier", Streed))) Then a new user \u003d compound. Runs. Users. Create element (); New User.Name \u003d References. Users. Entipocose ("00-0000313"). Name; New User.physicity \u003d References. Users. Entipotype ("00-0000313"). Physical New user. recruit (); Ended;

Also the COM connection has the right to use procedures and functions from General Modules 1C with the "External Union" property included. In addition, the condition called function or procedure must be export and not include interactive actions performed on the server. In the opposite case, you will see a mistake about the inadmissibility of the operation.

Compound..; MachineFunction \u003d connection ..; Calling\u003e Name Upholstery\u003e CallsProcessories\u003e NamesOtherness\u003e

The possibilities of an external connection with another base in 1C are sufficiently extensive and can allow a plurality of tasks. It is important to be able to correctly evaluate the toolkit and choose optimal solution. In most cases, this ability appears only with experience or studying examples of experienced specialists.

Printing (Ctrl + P)

One of the data exchange options between databases 1C is an exchange through the COM connection. With the COM connection, you can connect from one database to another and read or write data. You can use this method both in client-server versions of the databases and file bases. This article discusses this kind of compounds on the platform 8.3

cOM connection

You can create two types of COM objects for application 1C. This is OLE connections V83.application and COM connections V83.comConnector . In case of V83.application The almost complete instance of the 1C application is started. In case of use V83.comConnector Launched small server part. The speed of work in this case is higher, but some functions may not be available. In particular, work with forms and with common modules for which the property is not established with external compounds. Mustly need to use V83.comConnector And only in case of shortage of functionality V83.application. Especially strongly the difference in speed can be noticeable at the bases of the large volume. For platform 8.2 used V82.Application or v82.comConnector

Install OLE Connection

Connection \u003d new COMBACK ("V83.APPlication");

Set COM connection

Connection \u003d new COM object ("v83.comConnector");

Connection string

// For the option client server
String monitoring \u003d "Srvr \u003d" "imparation" "; ref \u003d" "" name ";
// For file mode option:
String monitoring \u003d "File \u003d" "Pullbase" "; Usr \u003d username; Pwd \u003d password ";
Attempt
Connection \u003d Connection . Connect.(String monitoring);
An exception
Message \u003d New user message;
Message . Text = "Failed to connect to the database" + Description (); Message . To report();
Celebrations;

Breaking connection

Compound \u003d undefined;
For object V83.application It is necessary to fulfill the connection to the connection, otherwise the incomplete session will hang, which then will have to be deleted manually. In case of V83.comConnector The connection is torn automatically when the procedure is completed in which the connection was performed. And there is another little moment. For the user under which the connection is performed, the "Request Closing Program" checkbox must be turned off in its settings.

NewObject () method

To create a new object, you can use the newObject () method, for example:

for V83.comConnector

Requercise \u003d Connection. NewObject ( "Inquiry ") ;
TableCom. \u003d Connection. NewObject ( "Tablement") ;
Masscoma \u003d connection. NewObject ("array");

Uidcom \u003d connection .NewObject

for V83.application

Request \u003d Compound. NewObject (" Inquiry ") ;
Tableole \u003d connection. NewObject.("Tablement") ;
Massive \u003d connection.NewObject("Array");
Uidcom \u003d connection.newobject("Unique Selfentifier", Rowing);

Requercise . Text \u003d."CHOOSE
| Postganizations. Code,
| Propulator organizations.Name
| Is | Directory. Validityorganizations
As office ";

Result \u003d Request. Perform ();
Sample \u003d Result. Choose () ;
While sample. Following()Cycle
EndCycle;
You can also use configuration object managers:
ReferenceCom \u003d Connection. Directories. Namemanship;
DocumentCom. \u003d Connection. Documentation. Immediate;
Register \u003d connection. Registribution. Nameregister;

Receipt and comparison of transfer via COM connection

To compare the values \u200b\u200bof the elements of the enumerations defined in the configuration, it is necessary to transform these elements to one of the primitive types, which does not cause difficulties. Such types can be either a numeric or a string type. Convert the value of the enumeration element to the numeric type can be so

Element transactions \u003d. Connection. Runs. Pravoyer1.Nextile (1). Requisite1;

Possible \u003d Element transactions. Molding (). Values;

Elemental procedures \u003d Possible. POSSIBLE. INDEX (POSSIBILITY. INTERITIES (connection.xmlstring (element transactions)));

If the element is the operation \u003d 0 then to report ( "Values1");

Inspecified the elementarization \u003d 1 Then Report ("Values2");

Ended;

Getting an object via COM by identifier

Through configuration object managers, we receive a COM object, for example:
DocumentCom. \u003d Compound. Documentation. Immediate;

Then we get a string of a unique identifier:

Rowing \u003d connection.string ( DocumentCom.UnikovyTentifier())

Identifier \u003d new y naturalFentifier (Rowing);
FROM syclipoider \u003d [IMIDCEMENT] documents. Pour to the identifier (identifier);

If you need to find a COM object according to the identifier document, then you need to write like this:

Uidcom \u003d. Connection.newObject("Unique Selfentifier", Rowing);
Refld identifier \u003d connection. Documents [IMYTROCEMENT]. Troubleshold (UIDCOM);

One of the data exchange options between databases 1C is an exchange through the COM connection.

With the COM connection, you can connect from one database to another and read or write data. You can use this method both in client-server versions of the databases and file bases. In this article, we will analyze examples of this kind of compounds. The examples use the platform 8.2.

You can create two types of COM objects for application 1C. it V82.application and V82.comConnector. In case of V82.application The almost complete instance of the 1C application is started. In case of use V82.comConnector A small server part is launched.
The speed of work in this case is higher, but some functions may not be available. In particular, work with forms and with common modules for which the property is not established with external compounds. Mustly need to use V82.comConnector And only in case of shortage of functionality V82.application. Especially strongly the difference in speed can be noticeable at the bases of the large volume.

So, proceed

  1. Create a COM object
    • for V82.application Connection \u003d new COM object ("v82.application");
    • for V82.comConnector Connection \u003d new COM object ("v82.comConnector");
  2. We form a plural connection
    • for the server variant of the string connection \u003d "srvr \u003d" "imasorver" "; ref \u003d" "" name ";
    • for the file version of the string connection \u003d "File \u003d" "Pullbazbaz" "; Usr \u003d username; PWD \u003d password";
  3. Perform a connection to the database Attempting Connection \u003d Connection. CONNECT (string compound); Exception message \u003d new user message; Message. Text \u003d + Description (); Message. To report() ; Celebrations;
  4. Break the connection with the base Compound \u003d undefined;

    For object V82.application It is necessary to fulfill the connection to the connection, otherwise the incomplete session will hang, which then will have to be deleted manually. In case of V82.comConnector The connection is torn automatically when the procedure is completed in which the connection was performed. And there is another little moment.

    For the user under which the connection is performed, the "Request Closing Program" checkbox must be turned off in its settings.

Now we will collect all the code in a bunch

Connection \u003d new COM object ("v82.application"); // Connection \u003d new COM object ("v82.comConnector"); Rowing index \u003d "srvr \u003d" "server1c" "; ref \u003d" "MyBase" "; usr \u003d Petya; pwd \u003d 123"; // Ritching Indion \u003d "File \u003d" "C: \\ MyBase" "; usr \u003d Peter; pwd \u003d 123"; Attempting Connection \u003d Connection. CONNECT (string compound); Exception message \u003d new user message; Message. Text \u003d. "Failed to connect to the database" + Description (); Message. To report() ; Celebrations; Compound \u003d undefined;

For the type of connection V82.application The method is applied to the COM object, which was originally created, and for V82.comConnector The method applies to connecting. Next, work with the request goes standard means 1C. In the code it looks like this:

Request \u003d Connection. NewObject ("query"); // for V82.comConnector Query \u003d connection. NewObject ("query"); // for V82.application Inquiry. Text \u003d "Select | Postganizations. Code, | Propulator organizations.Name | Is | Directory. Allorganizations as office "; Result \u003d request. Perform (); Selection \u003d result. Choose() ; While sample. The next () cycle of the endackel;

For version 1C: Enterprise 8.3 everything remains unchanged, except that when creating a COMOBECs should be used "V83.comConnector" or "V83.APPlication".

) All right

At the same time, I saw more than once when I just got off the publications that did not even pull on 10 points.
Why did it happen? Apparently because someone they obviously fell like.


I'm talking about it and I would say that it would be nice without reading the article on the rating to understand how much you need it, or evaluate it is not so primitive +/-. As for the soul, I would adjust this: she scored so much due to the fact that the stars have developed and many people gathered on the site and liked many, you understand this case, because as soon as the article leaves with main page It can already be found only on request, and so voting everything passing. And maintain on the main thing as far as I understand, allow permanent comments \u003d promotion of the article.
It is for this that there are shops on the passing streets - after all, it is often important not the quality and relevance of the goods, but the passability of the place, people walking often buy what they will throw out the next day, just for the sake of the process. It has long been a well-known disease - a burst. Or simply increase the stream increases the likelihood of the desired buyer.

And pluses and cons ... is just some kind of "thank you" for the time spent and work


Those. Minus is also considered for "thanks"? I wanted to know your attitude to whether it is necessary to put it in such cases, and how interesting is others? Does it be placed when the article is harmful / bad or when it is just useless to you / empty.
In my opinion the article looks like simply raising the rating, because:
1. The problem with the types with the types are generally ignored by the author, although he was not lazy to write a bunch of comments.
2. In the article, obvious inaccuracy: it is said that you can only

V82 \u003d new COMBACK ("V82.COMCONNECTOR"); Code \u003d counterparty.code;


but I calmly do with the help of processing like this:

Report (base.pravnikhniki.Tragents.Nightyponiament ("LLC"). Code);


and everything is fine! And I choose the connection v82.comConnector
It is strange to somehow that the author absolutely spit on the fact that his article contains such problems on which they indicated, and it does not react in any way.
3. But there is still a problem when an error pops up "Class does not exist"
4. And there is a problem when installed 8.2, and then installed 8.1 - try you to exchange on Ole / COM typical exchange UT-BP!
5. Could you specify the main processing on the site that allow you to universally connect via Ole / Com to begin the newcomers, you write for them! By the way, by the way, for some reason, it is banging with you, why? And as a result, 2 words are essentially 6 for the scenes.

In general, I do not water mud, but point to specific gaps, but zero reactions. If this is the experience that you share it is some kind of erroneous and incomplete.
I mean by the fact that the author would have a desire to collect all the glitches, then he could at least listen to someone else's experience, and not to gripe on comments. There is also a situation when the one who read her know more than the author, they say to him (sometimes incorrectly), and he is also fighting. As a result, all information is not in the article, but in comments! Funny! So it often happens, but you do not need to get away from what you wanted as better - I show how best, and others are shown! Include it in the article and it will be worthwhile, not all the same interesting to read this vessel.

Hi Habravelov!

In this article, I want to tell about how integration with the 1c platform in my organization is established. Prompted me to do almost complete absence technical information about this theme. Reading various articles and reports on the topic of Bundles 1C with any information system, once again make sure that they all are marketing, demonstration, and never - the technical, reflecting the problem and the essence of its decision.

I warn that the method in no case claims universality. Since 1C configurations themselves there is a lot, and information systems, languages \u200b\u200band platforms are even more, the number of possible combinations is huge. My goal is to demonstrate one of the possible solutions.


As a language that will be integrated with 1C, I chose Python. It is very well suited for the automation of processes. This contributes to the minimalistic syntax (the code is recruited very quickly), a rich standard library (less need for third-party modules), cross-platform - with a high probability, the code written in the Linix OS will successfully earn in Windows.

To begin with, outlines with which we will work with. Organization - Energy supply company in the Far Eastern region - serves approximately 400 thousand subscribers, the base 1C on a self-written configuration. For each subscriber, its payments, accruals, services consumed and calculation schemes, accounting devices, readings and many other data are stored.

Once in the organization stood a program written in Delphi and using MSSQL / Firebird as database. In those glorious times, it was possible to connect to the database using any language and make many actions - to select debtor subscribers, disseminate received payment, fix the readings of the instruments. It is not surprising that the collection of scripts that automate the routine constantly grew. Programmers could perform any actions without opening the program itself.

Alas, with the transition to 1C Chairs ended - it was not possible to connect to the base directly. In general, the 1C platform itself is indivisible and poorly integrating with other systems. She, as they say, the thing in itself. By loading data in 1C, it should be remembered that it will not be so easy to remove them. But in view of the fact that the organization needed to implement payment systems and personal AreaIt was necessary to find some solution.

The main tasks that stood in front of me are the ability to quickly receive data on a specific personal account - FULL NAME, address, accounting devices, instrument readings, payments, accruals. Plus, the formation of documents is an act of reconciliation, payment receipt. So, the possibility of direct connection from the database is missing - everyone who looked through the 1C database on the SQL server, saw that in the mass of the table of the AAA1 type, AAA2 is difficult to understand. And build requests with such names of tables and fields is simply unreal. In addition, many tables 1C (especially the most important, like cut slices of the last, residues and revolutions) are virtual and scattered by different physical tables, gathering multiple joines. This method is not suitable.

The 1C platform provides the ability to connect to it through the COM connection. Like many Windows programs, during the installation of 1C, two COM objects are recorded in the system - Automation Server and COM Connector. You can work with both objects using the language in which the COM technology is provided.

The Automation Server object is an application 1C, almost no different from the usual client application. The difference is that the possibility of additionally appears software management An application instance. When working with the COM Connector object, a lightweight version of 1C application is launched, in which the forms are not available, as well as functions and methods related to the interface and visual effects. The application itself starts in the "External Union" mode. The initialization of global variables (for example, the definition of the current user and its settings) must be performed in the 1C external connection module. If in the external connection mode in the code will be called a function that is not available in this mode, the exception will be caused (which will be transferred to our python script). Calling unsafe functions should be framed by the designs of the form

# If not external connection then a warning ("Hi!"); # Endox

Since working with COM objects - technology exclusively Windows-Only, it is not surprising that in the standard supply of python it is missing. You will need to set the extension - a set of modules that provide all the necessary functionality for programming under Windows on python. It can be downloaded as an exe-installer already collected. The extension itself provides access to the registry, services, ODBC, COM objects, etc. Alternatively, you can immediately install the ActiveState Python distribution, in which the Win32 extension comes from the box.

For some time I experimented with a COM connection in developing web applications, in particular, a personal account. The following minuses were revealed:

The COM connection is slow. Low productivity - famous minus COM technology.
- The process of installing a connection with 1C, depending on the configuration, can take from 1 to 8 seconds (in my case - 6 seconds). Is it worth saying that the connection of the connection to each request will lead to that, each page will be loaded for 8 seconds.
- Since web applications on python work as an independent server, the previous item can be compensated for by storing the connection in some global variable and in case of error to restore it. How to maintain a connection to PHP, I, honestly, did not think yet.
The web application cross-platform is lost.

Based on the above items, it was decided to change the principle of interaction, separating it into 2 parts - the first platform-dependent (Windows), unloading data 1c to any convenient format, and the second, non-dependent on the platform, which is capable of working with the data, is unaware About 1C in principle.

The strategy of action is as follows: the python script is connected from 1C, performs requests And unloads the data in the SQLite base. This database can be connected from python, php, java. Most of our projects are working on python, and since I will not get out of writing raw SQL queries with your hands, then all work with the SQLite base is performed via ORM SQLALCHEMY. It was only required to describe the data structure of the database declarative style:

From sqlalchemy.ext.declarative import declarative_base from sqlalchemy import Column, Integer, Numeric, DateTime, Unicode, Boolean, LargeBinary, ForeignKey Base \u003d declarative_base () class Abonent (Base): __tablename__ \u003d "abonents" id \u003d Column (Integer, primary_key \u003d True) Account \u003d Column (Unicode (32), index \u003d True) Code \u003d Column (Unicode (32)) Address \u003d column (Unicode (512)) FIO \u003d Column (Unicode (256)) Source \u003d Column (Unicode (16) ) PSU \u003d Column (Unicode (256)) TSO \u003d column (Unicode (256)) NP \u003d Column (Unicode (256)) Street \u003d Column (Unicode (256)) House \u003d Column (Integer) Flat \u003d Column (Integer) MRO \u003d Column (Unicode (256)) Class Payment: __TABLENAME__ \u003d "payments" # and so on ...

Now it is enough to import this module into any python project, and you can work with the data.

I foresee your question - "why sqlite"? The main reason - the base is needed only for reading, so there should be no problems with writing in SQLite. Secondly, the format of this DBMS is convenient - it is more convenient to view it (we exist a lot free utilities, including a super-expansion for Firefox). Thirdly, in some cases it was necessary to access subscribers from those machines on which there is no connection with the MYSQL server. In this case, it is enough to copy the SQLite-database file, and this machine will access all information.

Unloading occurs once a day at night. Data enclosure in 1C can be automated in the same way. For example, you need to record the testimony left by subscribers on the personal account site. In this case, again connect with 1C and software method Create and carry out the document "Act of Removing Indications". I will give the code just below.

Working with COM objects in Python is a bit unusual. Firstly, the "pitonicity" of the code is lost - the rules of naming variables and functions in 1C, to put it mildly, do not correspond to Zen Python. Secondly, everyone knows that 1C objects are often referred to as Cyrillic symbols, which will cause problems when developing on Python ... But they are solved. I propose to familiarize yourself with the code:

Import pythoncom import win32com.client v82_conn_string \u003d "SRVR \u003d V8_SERVER; REF \u003d V8_DB; usr \u003d username; pwd \u003d megapass;" pythoncom.coinitialize () v82 \u003d win32com.client.dispatch ("v82.comConnector"). Connect (V82_CONN_STRING)

As can be seen from the code, the client is initialized to work with 1C. The definition of the COM object occurs by the name "V82.comConnector". Please note that this name is true for the platform V8.2, if you have version 8.1, then the name will be "v81.comConnector".

At the initialized client, we call the connection () method by passing it a connection string. The string consists of the server name, database, user and password. The resulting object V82 keeps the connection with the 1C application. He has no disconnect () method or something like that. To disconnect the base, it is enough to delete an object from the memory function Del () or assign a None variable.

Having an object, you can refer to any fields and methods of the global context 1C, operate with universal volumes of the type of text document, table and TD. It is important to consider that when working through the COM connection 1C operates in the "External Union" mode. It is unavailable any functions for interactive work, such as pop-up dialogues, notifications, and, most importantly, forms. I am sure that you are changing the configuration developers, which make the most important functionality in the procedure 1 button () in the document form module.

Let's talk about such a vanity as Kirilic attributes. Despite the fact that 1C is a bilingual medium and for each Russian method there is an English-speaking analogue, sooner or later it will be necessary to contact the Kirilic attribute. If on pHP languages or VBScript it will not cause any problems

SET CON \u003d CREATEOBJECT ("V81.COMCONNECTOR") SET V8 \u003d CON.CONNECT ("StringClining") SET accounting manner \u003d V8.Documents. Schedule .... SET accountscape \u003d Battery. .... accountscape. recruit ()

The code on Python simply crashes with a Syntax Error error. What to do? Edit configuration? No, it is enough to use the methods GetAttr and SetAttr. Transmitting the COM object and the Cyrillic name of the attribute to these functions, can be obtained accordingly and set values:

# Coding \u003d CP1251 Catalog \u003d GetAttr (V82.Catalogs, "Facial")

The following is important: the names of the details, as well as the parameters of the functions and methods should be transmitted in the encoding CP1251. Therefore, in order to avoid Putnice with encodings in advance, it makes sense to declare it at the beginning of the file: # Coding \u003d CP1251. After that, you can transfer lines without worrying about their encoding. But! All strings obtained from 1C (the results of the function of the functions, requests) will be in the UTF-8 encoding.

An example of a code that performs in the 1C query, it turns out the result and saves the base in SQLite:

# Coding \u003d CP1251 Q \u003d "" "Choose a fairytte. Code like Code, Facial Facial. Equipment. Naselipart. Name +", "+ Facials. Smartyaddress as ADDRESS, Facial. Bonient.Name as FIO, Facial PSU.Division. Name as PSU, Express (characterically desiccreet-lasting. Relationship as a guide. Surrian substitutional organization). Operation as TSO, facials. Equipment. Naselipart. Name as NP, Facial Facial. Equipment. Launch. Name as Street, Facial. Equipment. Detachast , LitsevyeScheta.Divizion.Roditel.Naimenovanie mro AS OF AS Spravochnik.LitsevyeScheta LitsevyeScheta left join RegistrSvedeniy.HarakteristikiLitsevyeScheta.SrezPoslednih (, VidHarakteristiki \u003d VALUE (Spravochnik.VidyHarakteristik.TerritorialnoSetevayaOrganizatsiya)) HOW TO HarakteristikiLitsevyeSchetaSrezPoslednih LitsevyeScheta.Ssylka HarakteristikiLitsevyeSchetaSrezPoslednih.Obekt \u003d "" "query \u003d V82.newobject ( "Query", q) selection \u003d query.execute (). Choose () Conn \u003d db.connect () Conn.Query (Models.abonent) .Delete () While Selection.next (): abonent \u003d models.abonent () abonent.account \u003d selection.code.strip () abonent.code \u003d selection.code abonent.fio \u003d selection.fio abonent.address \u003d selection.address abonent.psu \u003d selection.psu abonent.tso \u003d selection.tso abonent.source \u003d U "ASRN" abonent.np \u003d selection.np abonent.street \u003d selection.street abonent.house \u003d selection.House abonent.flat \u003d selection.flat.mro \u003d selection.mro conn.add (abonent) Conn.commit ()

Here Conn is a SQLite-Base Connection Session. A query request object is created, its text is filled. As noted above, the query text must be in CP1251, for which the encoding is first declared. After executing the request, all subscribers are deleted in the database so as not to add a ducky, then added in the cycle and follows the final commote.

When working with requests, I revealed the following rules.

Choosing the fields, assign them the names of the Latin, it will be much more convenient to access them through the selector (point), instead of getatr ().
- Choose only the primit types of data: rows, numbers, date and boolean. Never choose links to an object (document, directory)! In this context, the references are absolutely not needed and even harmful to you, because any reference to the details or method of the link will result in request via a COM connection. If you contact the attributes of the link in the cycle, it will be extremely slow.
- If you choose a field type field, then it is returned as an Object Pytime. This is a special data type to transfer date-time in the COM connection. It is not so convenient to work with him, as with the usual datetime. If you send this object to int (), TimeStamp returns, from which you can then get a DateTime method fromTimeStamp ().

Now consider how print documents are formed. The fact is that the consumer needs to provide the ability to download pre-prepared documents, such as payment receipt or reconciliation act. These documents are formed in 1C in accordance with the established requirements, their implementation on Python will take a long time. Therefore, it is better to generate documents in 1C and save them to Excel format.

So, the reconciliation act is generated by a special external processing. For those who are not familiar with 1C terminology: Processing is a standalone program that has a module, forms, templates, designed to start in the 1C medium. It is necessary to initialize the processing, fill its details and call a function that will return to us a tabular document designed to view 1C. This document must be saved to Excel format and copy to the server or write to the database.

Link \u003d getattr (v82.catalogs, "Reportsystems"). FindbyDescription ("Act Records Elean") NAV_URL \u003d V82.GetURL (Link, "Report") name \u003d v82.externalReports.connect (NAV_URL) externalReport \u003d V82.ExternalReports.create (Name) SetAttr (ExternalReport, "Facial", Reference) table_doc \u003d externalRetence.getDoc () Path \u003d V82.getTempFileName ("XLS") Table_Doc.Write (Path, V82 .spreadSheetDocumentFileType.xls) Report \u003d Models.Report () Report .Account \u003d reference.code.strip () report.Type \u003d U "ACT" report.document \u003d Open (Path, "Rb"). Read () Conn.add (Report)

The following fragment is followed. Connects processing forming a document. Processing can be built into the configuration, stored on a disk or in 1C database (in some guide). Since processing is often changed, so that each time you cannot update the configuration, the most frequently changing processing is stored in the Reporting Guide, in a details of the "Value Storage" type named report. The processing can be initialized by unloading it from the database to the disk and loading, or by the GETURL () method, to which the reference to the reference item and the name of the props. We assign the value of the props obtained by the processing object, call the GETDOC () function, we obtain a tabular document that is stored in a temporary Excel file. The contents of this file are recorded in SQLite-database.

The last thing remains to be considered - this is a software enhancing in 1C. Suppose that you want to make testimony from subscribers. To do this, it is enough to create and conduct a document "Act of Removing Indications":

# Coding \u003d CP1251 ACTS \u003d GetAttr (V82.Documents, "Aktsnotchy") Act \u003d Acts.createDocument () SetAttr (Act, "Indication", 1024.23) SetAttr (ACT, "Subscriber", "Ivanov") # Filling other details. .. Act.Write ()
Now data enclosure automated.

So, I outlined the method that is based on software unloading and loading data using the COM connection. This method is successfully operating in my organization for almost a year. The base formed from 1C serves 3 payment systems, Internet acquiring (payment by cards via the Internet), as well as a personal account. In addition, various scripts are connected to the database to automate the routine.

Despite the disadvantages of the method (the slow speed of the COM-compound), in general it functions stable. We have data in a platform-based form (SQLite) with which you can work from any language. And the main part of the code is written in Python, and therefore, many means and techniques are available, which can not even dream of 1c.

This is one of possible methods interaction with 1C. I am sure that he is not new and probably already been tested by someone, optimized. However, I tried to set out the maximum of the details of the process to protect you from the pitfalls to which it was assumed.

I wish everyone good luck, and remember that it is not so terrible for 1c, as his little!