Posting goods receipts across two registers
In Designer mode
In 1C:Enterprise mode
In 1C:Enterprise mode you have to repost all goods receipts. This is required for the documents to create new register records according to the posting algorithm you have just modified.
- Start 1C:Enterprise in the debug mode.
- In the Inventory section, run the Goods receipts command.
This opens the list of goods receipts. - Click each goods receipt while holding down Ctrl to select all of them, and then, on the More menu, click Post.
- Open the first document (fig. 11.7) and run the Balance of materials and Cost of materials commands.
You can see that the document created records in both accumulation registers (fig. 11.8 and fig. 11.9).
Fig. 11.7. Goods receipt #1
Fig. 11.8. Balance of materials register records
Fig. 11.9. Cost of materials register records
Modifying the posting procedure
Let us modify the document posting procedure.
- In Designer, open the GoodsReceipt document editor window and click the Posting tab.
- Add the CostOfMaterials register to the list of registers affected by the document (fig. 11.3).
Fig. 11.3. Creating records of the GoodsReceipt document in the CostOfMaterials register - Click Register records wizard.
- Confirm that you want to replace the previously generated posting procedure.
By doing this you do not lose any data because you have not changed the previously generated procedure and the new one will add records to both registers.
In the Register Records Wizard window you can see that all of the fields related to the BalanceOfMaterials register contain data that you specified earlier, when you set up record generation for this register in section Creating register records of a document. - Click the Add button above the Registers list and add the CostOfMaterials register (fig. 11.4).
Fig. 11.4. Register records wizard
The default register record type is Receipt (the icon is displayed next to the register name). - In the Tabular Section list, select Materials.
It is the tabular section of the GoodsReceipt document.
Once you select the tabular section, its attributes are added to the Document attributes list, which already contains the document header attributes. - Click Fill expressions.
In the bottom pane the mapping between the register fields (dimensions and resources) and the expressions for calculating their values is generated.
Let us specify the mapping for the Cost register field. - In the Field column, click the Cost field, and then, in the Document attributes list, double-click the CurRowMaterials.Total attribute (fig. 11.5).
Fig. 11.5. Register records wizard - Click OK.
The wizard generates a procedure in the GoodsReceipt document module and opens the module. You can see that the new handler procedure includes the generation of records in two registers (listing 11.1).
Listing 11.1. Records of the GoodsReceipt documentProcedure Posting(Cancel, Mode) //{{__REGISTER_REGISTERRECORDS_WIZARD // This fragment was built by the wizard. // Warning! All manually made changes will be lost next time you use the wizard. // register BalanceOfMaterials Receipt RegisterRecords.BalanceOfMaterials.Write = True; For Each CurRowMaterials In Materials Do Record = RegisterRecords.BalanceOfMaterials.Add(); Record.RecordType = AccumulationRecordType.Receipt; Record.Period = Date; Record.Material = CurRowMaterials.Material; Record.Warehouse = Warehouse; Record.Quantity = CurRowMaterials.Quantity; EndDo; // register CostOfMaterials Receipt RegisterRecords.CostOfMaterials.Write = True; For Each CurRowMaterials In Materials Do Record = RegisterRecords.CostOfMaterials.Add(); Record.RecordType = AccumulationRecordType.Receipt; Record.Period = Date; Record.Material = CurRowMaterials.Material; Record.Cost = CurRowMaterials.Total; EndDo; //}}__REGISTER_REGISTERRECORDS_WIZARD EndProcedure
You can see that the script fragment that describes the record generation for the CostOfMaterials register is similar to the script fragment that describes the record generation for the BalanceOfMaterials register.
But having two loops that iterate through the Materials tabular section is not optimal, you can use a single loop for this. - Combine the two loops into one and delete the comments generated by the wizard.
Then your procedure should look as shown in listing 11.2.
Listing 11.2. Records of the GoodsReceipt documentProcedure Posting(Cancel, Mode) RegisterRecords.BalanceOfMaterials.Write = True; RegisterRecords.CostOfMaterials.Write = True; For Each CurRowMaterials In Materials Do // register BalanceOfMaterials Receipt Record = RegisterRecords.BalanceOfMaterials.Add(); Record.RecordType = AccumulationRecordType.Receipt; Record.Period = Date; Record.Material = CurRowMaterials.Material; Record.Warehouse = Warehouse; Record.Quantity = CurRowMaterials.Quantity; // register CostOfMaterials Receipt Record = RegisterRecords.CostOfMaterials.Add(); Record.RecordType = AccumulationRecordType.Receipt; Record.Period = Date; Record.Material = CurRowMaterials.Material; Record.Cost = CurRowMaterials.Total; EndDo; EndProcedure
Adding the command that opens register records
Finally, let us edit the document form command interface to add the link for viewing the CostOfMaterials register records related to the document to the form navigation panel.
- Open the GoodsReceipt document form.
- In the upper left pane, click the Command interface tab.
- In the Navigation panel branch, expand the Go to node.
It contains the command that opens the list of the Cost of materials accumulation register. - Select the Visible check box for this command (fig. 11.6).
Fig. 11.6. GoodsReceipt document form command interface setup