Mapping (or Populate) a child table based on DocType

Hey guys,

My scenario:
A have a Custom DocType name GoodsSummary with a Field:Link to Purchase Order. For this I need to map (or pre-populate) a child table named BookItems (items with Purchase Receipt) and another one ‘UnBookItems’ (items without Purchase Receipt) onchange of Purchase Order:Link:Field.

I have seen the same functionality to Purchase Receipt with the button ‘Get Items’ form Purchase Order. In the source code I see a erpnext.utils.map_current_doc that calls erpnext.buying.doctype.purchase_order.purchase_order.make_purchase_receipt and inside there i see from frappe.model.mapper import get_mapped_doc (frappe/mapper.py at develop · frappe/frappe · GitHub)

Basically I need to create something similar I can’t understand from get_mapped_doc function the table_maps argument how it should be structured.
For example I see in apps/erpnext/erpnext/buying/doctype/purchase_order/purchase_order.py
I see some postprocess and condition or even add_if_empty.

May I have some explanation about the get_mapper_doc or a simplified usage example?

I guess trial and error is the best. Just do a code search on get_mapped_doc and see the various use cases

If you have a specific query will be happy to help.

Hey @rmehta, on the other hand I guess it would be great to provide some doc strings for some of functions.

1 Like

@kickapoo yesterday, I got a business enquiry with same topic. Perhaps, when community member try to map various path to get the proprietary project done through this platform or members, It makes me smile :slight_smile:

Some time back @adityaduggal addressed similar stuff rightly.

1 Like

@sunilsrikumar Interesting how my mail … travels :).