17 views
Skip to first unread message

Maxwell Morais

unread,
Jul 3, 2013, 10:37:48 AM7/3/13
to erpnext-dev...@googlegroups.com

Hello All, we developing the integration of our CAD Software and the ERPNext Sales Order, and have some questions.

The code below, parse the CAD file, and create each item described on project scope, and append the material list to item (Sales BOM), but:

If we can get one saved item to update your content, we don't can refresh the price data, we obtain the price list, but do not understand what to do after this point to update the price of the item.

If we create a new item based on template using the webnotes.bean(copy=args) method, on call item.doc.fields.update(*args) this update all fields, but does not update the brand, and the brand is defined on args.

For now we are with these difficulties, could anyone shed some light?

@webnotes.whitelist()
def get_project_costs(filenames):
    from ParsePromob import PromobReader  # The file parse
    from webnotes.model.bean import getlist
    # The Item, Sales BOM and Price templates

    enviroment_template = [
        # The Item
        {
            'doctype': 'Item',
            'item_code': '_Item Template_Code',
            'item_name': '_Item Template_Name',
            'description': '__Item Template_Description',
            'brand': 'New',
            'item_group': 'Itens Projetados',
            'stock_uom': 'Un',
            'is_stock_item': 'No',
            'is_purchase_item': 'No',
            'is_sales_item': 'Yes',
            'is_service_item': 'No',
            'is_sample_item': 'No',
            'max_discount': 65,
            'default_income_account': u'Vendas - Grupo Realize Móveis',
            'default_sales_cost_center': u'Auto Inventory Accounting - Grupo Realize Móveis',    
        }, 
        # The Price
        {
            'doctype': 'Item Price',
            'parentfield': 'ref_rate_details',
            'price_list_name': 'Itens Projetados',
            'ref_rate': '_Item Template_Price',
            'ref_currency': 'BRL',
            'buying_or_selling': 'Selling'
        }
    ]

    sales_bom_template = [
        #nothing
    ]

    cost, increase = 0, 0
    items = []

    for project_files in filenames.split(';'):
        reader = PromobReader(project_files)              # Init the parse
        project = reader.getProject()                     # Get the xml root element 
        data = project.toDict()                           # Get the item and subitems to compose the sales bom
        cost += data.get('project_cost', 0)               # Get the raw price of the item
        increase += data.get('project_increase', 0)       # Get the project increase

        for i in data.get('items', []):                                                    # Process each item for CAD File
            price = i.pop('price')                                                        # Pop the price to append this on your doctype
            try:
                item = webnotes.bean('Item', i['item_code'])                            # First can get the doctype from db
                item.doc.fields.update(i)                                                # Update the item data based on CAD data
                pricelist = getlist(item.doclist, 'ref_rate_details')                   # Get the price list
                item.save()                                                             # Save the item
            except:
                item = webnotes.bean(copy=enviroment_template)                          # Make a new item based on template
                item.doc.fields.update(i)                                               # Update the item data based on CAD data
                item.doclist[1].fields.update({'ref_rate': price})                      # Update the price
                item.insert()                                                           # Save the item
            items.append(i['item_code']) # Append item code to response

    return {
        'project_cost': cost,
        'project_increase': increase,
        'project_cost_net': cost-increase,
        'items': items
    }
--

Rushabh Mehta

unread,
Jul 3, 2013, 12:24:47 PM7/3/13
to erpnext-dev...@googlegroups.com
Max,

The price data is in the "doclist" of the Item "bean" object.

# get the item bean object
item = webnotes.bean("Item", item_id)

# get the price list record
item_price = item.doclist.get({"doctype": "Item Price", "price_list_name": "My Price List"})

# set a new price
if item_price:
  item_price[0].ref_rate = product_cost
  item.save()


To get a better idea, just do a print on item.doclist - you will get an idea, its a collection of records (one parent + many children)

best,
Rushabh

T: @rushabh_mehta

--
You received this message because you are subscribed to the Google Groups "ERPNext Developer Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer...@googlegroups.com.
To post to this group, send email to erpnext-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/CABK1YkMVUtSsSwzZLHPt1pC7H-Fie%3DvPKLVuQ7BXSUu%3DnDW1GQ%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Maxwell Morais

unread,
Jul 3, 2013, 4:09:11 PM7/3/13
to erpnext-dev...@googlegroups.com
Rushabh, one more question.

If we have 2 doclist, the stored in database and the updated data.
webnotes lib, provide a good form to evaluate the diference between these doclist?


2013/7/3 Rushabh Mehta <rme...@gmail.com>

For more options, visit https://groups.google.com/groups/opt_out.
 
 

Anand Doshi

unread,
Jul 3, 2013, 11:47:32 PM7/3/13
to erpnext-dev...@googlegroups.com
Hi Max,

As of now, there is no method to find a diff between two doclists.

What kind of diff do you want? Something like "if doc with item_code=something" exists in old and not in new? and/or "what fields have changed in the doc between old and new", etc.

Maybe there could be an easier solution without going into diffs. Can you give an overview of what you are trying to achieve?

-Anand.

Maxwell Morais

unread,
Jul 4, 2013, 9:02:18 AM7/4/13
to erpnext-dev...@googlegroups.com

Hello Anand!

In a basic way, I just want to be able to compare 2 DocList, from left to right, why, I have a method that I just list all the items that will be included in a “good” sales.

ex:

dl1 = [....] # These are the items that are in the database, counting 33
DL2 = [....] # These items are updated, counting 28

dldiff = diff (DL1, DL2)
toinsert = dldiff.new_docs # These docs are in DL2 and not in dl1
toupdate = dldiff.updated_docs = # These docs are in dl1 and are modified in DL2
todelete = dldiff.removed_docs = # These docs are in dl1 not in DL2
unchanged = dldiff.unchanged_docs = # These docs existing in both dl's


2013/7/4 Anand Doshi <an...@iwebnotes.com>

For more options, visit https://groups.google.com/groups/opt_out.
 
 

Anand Doshi

unread,
Jul 5, 2013, 8:23:36 AM7/5/13
to erpnext-dev...@googlegroups.com
Hi Max,

We had experimented with version control for each document a few months back.

You should get an idea about how the diff was done to write your own diff functions.

Thanks,
Anand.

Reply all
Reply to author
Forward
0 new messages