Customizing Stock Reconsiliation

Hi

First of all … I wish to you you a very prosperous new year !

My system is running …
ERPNext: v12.26.0 (version-12)
Frappe Framework: v12.23.0 (version-12)

I would like to do my first cusomization and I am getting stuck. If someone could offer
some guidance I would appreciate it …

When doing a stock recon, I would like to use my barcode-scanner. But currently it only
seems to be possible if I “edit” each lilne in the Stock Recon Items-table.

So I thought to add 2 fields …
Default Warehouse ( which must auto-fill the warehouse entry in the items-table
Scan Barcode that can be used similarly to when you can barcodes in purchase-order
doctype. In the purchase-order doctype, when you scan the barcode, it auto-fills the
Items-fields in the Item-table.

So I want it to look like this …

SO I modified the Stock Reconsiliation Form like this …

And I modified the Stock Reconsiliation Item form like this …

Hi all

Isn’t there someone that can help me with this please ?

I really would like to have a stock re-con where I can scan the barcode on on the
main-page of the stock-recon and not on the “item-page” like it is currently.

Thanks

Hi there,

I think I understand what you’re trying to do, and it’s definitely doable. You’ll have to use a custom client script, however. It’s not possible just with “Fetch From” fields.

Here’s the javascript API reference:
https://frappeframework.com/docs/v13/user/en/api/form

THank you @peterg for taking the time

If I can just verify that I understand the process correctly…

Do I first create the required addisional fields using “Customize Form” … like below …

and then I do the data manupulation under “Custom Script” using the API
that you suggested … like below …

That would be a way to get started. The key will be setting up triggers for when the bar code field changes appropriately, generating a new child row, and clearing the field again.

Good day all … an update

Thank you @peterg again for your time

I have done a lot of reading and looking at videos. Also, please be patient as I have not done
any JS and python previously. I have done a lot C-coding ( embedded systems ) … but not this.

I have decided to , instead of tackling my project head-on, to first take little steps.

So for a start, I just wanted to update fields on the same form i.e. the parent form of
Stock Reconciliation. So for now I am not updating fields on the child form yet. I shall get there.

I added my extra fields … warehouse and barcode …


"Warehouse is a “link” field to Warehouse
and
Barcode is a “Data” field

Step 1 I want to use “warehouse” as the trigger and to use that trigger to transfer data from the
“Company” field to the “Barcode” field.

I added this code to the “Stock Reconciliation” form…and it works. When I make a
warehouse selection, I see the Company name in the barcode field.

Blockquote
frappe.ui.form.on(‘Stock Reconciliation’, {
onload: function(frm) {
frm.add_fetch(“warehouse”, “company”, “barcode”);
msgprint(‘Value was set’);
}
});

Step 2…
However, when I want to do this …

And I change the code to …

Blockquote
frappe.ui.form.on(‘Stock Reconciliation’, {
onload: function(frm) {
frm.add_fetch(“warehouse”, “warehouse”, “barcode”);
msgprint(‘Value was set’);
}
});

I get the error …
Wrong fieldname warehouse in add_fetch configuration of custom script

If someone could assist me with this error I would appreciate this.

If I can clear this , then the next step would be to update field-values on the child-form.

Apologies … I see my code did not format properly on the above post …!!!

this is my original PR for barcode scan feature, hopefully it can give you some idea
https://github.com/frappe/erpnext/pull/15731/files

Thank you @szufisher fro taking the time.

Let me go and look

Update

Good day all.

I followed the advise from @szufisher and had a look at existing code. But I also looked at
other forms that has a similar function … i.e. that scans a barcode and populate
a table. And based on that , i added a trigger-response ( is that the correct wording ?? )

Under …
erpnext.stock.StockReconciliation = erpnext.stock.StockController.extend({

I inserted the follwing code…

    scan_barcode: function() {
            let transaction_controller= new erpnext.TransactionController({frm:this.frm});
            transaction_controller.scan_barcode();
    },

I also added to fields under Customise Form → Stock Reconsiliation…

Field name are : scan_barcode and from_warehouse

The barcode-scan part works … when I scan the barcode, it auto-completes the table
in the child-form BUT not the warehouse.

I tried by inserting the following code…

    from_warehouse: function(doc) {
            this.set_warehouse_in_children(doc.items, "warehouse", doc.from_warehouse);
    },

But this does not work.

As an interim solution, I customised the Stock Reconciliation Item form and set the
default for the Item-Warehouse to Stores - TD. Now everything works, but relying on
a default setting to set the Item-Warehouse is not very elegent.

Could someone please help me with this, I am almost there. But looking throught the code
trying to sort it out … I am not making headway. I am once again using the code
for “Stock Entry” as a reference but in stock-entry, there is a “s_warehouse” and
a “t_warehouse” so it makes it dificult to try and “copy” that code and apply it to
Stock Reconciliation.