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 = [
<span style="color:rgb(153,153,136);font-style:italic" class="comment"># The Item</span>
{
<span style="color:rgb(221,17,68)" class="string">'doctype'</span>: <span style="color:rgb(221,17,68)" class="string">'Item'</span>,
<span style="color:rgb(221,17,68)" class="string">'item_code'</span>: <span style="color:rgb(221,17,68)" class="string">'_Item Template_Code'</span>,
<span style="color:rgb(221,17,68)" class="string">'item_name'</span>: <span style="color:rgb(221,17,68)" class="string">'_Item Template_Name'</span>,
<span style="color:rgb(221,17,68)" class="string">'description'</span>: <span style="color:rgb(221,17,68)" class="string">'__Item Template_Description'</span>,
<span style="color:rgb(221,17,68)" class="string">'brand'</span>: <span style="color:rgb(221,17,68)" class="string">'New'</span>,
<span style="color:rgb(221,17,68)" class="string">'item_group'</span>: <span style="color:rgb(221,17,68)" class="string">'Itens Projetados'</span>,
<span style="color:rgb(221,17,68)" class="string">'stock_uom'</span>: <span style="color:rgb(221,17,68)" class="string">'Un'</span>,
<span style="color:rgb(221,17,68)" class="string">'is_stock_item'</span>: <span style="color:rgb(221,17,68)" class="string">'No'</span>,
<span style="color:rgb(221,17,68)" class="string">'is_purchase_item'</span>: <span style="color:rgb(221,17,68)" class="string">'No'</span>,
<span style="color:rgb(221,17,68)" class="string">'is_sales_item'</span>: <span style="color:rgb(221,17,68)" class="string">'Yes'</span>,
<span style="color:rgb(221,17,68)" class="string">'is_service_item'</span>: <span style="color:rgb(221,17,68)" class="string">'No'</span>,
<span style="color:rgb(221,17,68)" class="string">'is_sample_item'</span>: <span style="color:rgb(221,17,68)" class="string">'No'</span>,
<span style="color:rgb(221,17,68)" class="string">'max_discount'</span>: <span style="color:rgb(0,153,153)" class="number">65</span>,
<span style="color:rgb(221,17,68)" class="string">'default_income_account'</span>: <span style="color:rgb(221,17,68)" class="string">u'Vendas - Grupo Realize Móveis'</span>,
<span style="color:rgb(221,17,68)" class="string">'default_sales_cost_center'</span>: <span style="color:rgb(221,17,68)" class="string">u'Auto Inventory Accounting - Grupo Realize Móveis'</span>,
},
<span style="color:rgb(153,153,136);font-style:italic" class="comment"># The Price</span>
{
<span style="color:rgb(221,17,68)" class="string">'doctype'</span>: <span style="color:rgb(221,17,68)" class="string">'Item Price'</span>,
<span style="color:rgb(221,17,68)" class="string">'parentfield'</span>: <span style="color:rgb(221,17,68)" class="string">'ref_rate_details'</span>,
<span style="color:rgb(221,17,68)" class="string">'price_list_name'</span>: <span style="color:rgb(221,17,68)" class="string">'Itens Projetados'</span>,
<span style="color:rgb(221,17,68)" class="string">'ref_rate'</span>: <span style="color:rgb(221,17,68)" class="string">'_Item Template_Price'</span>,
<span style="color:rgb(221,17,68)" class="string">'ref_currency'</span>: <span style="color:rgb(221,17,68)" class="string">'BRL'</span>,
<span style="color:rgb(221,17,68)" class="string">'buying_or_selling'</span>: <span style="color:rgb(221,17,68)" class="string">'Selling'</span>
}
]
sales_bom_template = [
<span style="color:rgb(153,153,136);font-style:italic" class="comment">#nothing</span>
]
cost, increase = <span style="color:rgb(0,153,153)" class="number">0</span>, <span style="color:rgb(0,153,153)" class="number">0</span>
items = []
<span style="color:rgb(51,51,51);font-weight:bold" class="keyword">for</span> project_files <span style="color:rgb(51,51,51);font-weight:bold" class="keyword">in</span> filenames.split(<span style="color:rgb(221,17,68)" class="string">';'</span>):
reader = PromobReader(project_files) <span style="color:rgb(153,153,136);font-style:italic" class="comment"># Init the parse</span>
project = reader.getProject() <span style="color:rgb(153,153,136);font-style:italic" class="comment"># Get the xml root element </span>
data = project.toDict() <span style="color:rgb(153,153,136);font-style:italic" class="comment"># Get the item and subitems to compose the sales bom</span>
cost += data.get(<span style="color:rgb(221,17,68)" class="string">'project_cost'</span>, <span style="color:rgb(0,153,153)" class="number">0</span>) <span style="color:rgb(153,153,136);font-style:italic" class="comment"># Get the raw price of the item</span>
increase += data.get(<span style="color:rgb(221,17,68)" class="string">'project_increase'</span>, <span style="color:rgb(0,153,153)" class="number">0</span>) <span style="color:rgb(153,153,136);font-style:italic" class="comment"># Get the project increase</span>
<span style="color:rgb(51,51,51);font-weight:bold" class="keyword">for</span> i <span style="color:rgb(51,51,51);font-weight:bold" class="keyword">in</span> data.get(<span style="color:rgb(221,17,68)" class="string">'items'</span>, []): <span style="color:rgb(153,153,136);font-style:italic" class="comment"># Process each item for CAD File</span>
price = i.pop(<span style="color:rgb(221,17,68)" class="string">'price'</span>) <span style="color:rgb(153,153,136);font-style:italic" class="comment"># Pop the price to append this on your doctype</span>
<span style="color:rgb(51,51,51);font-weight:bold" class="keyword">try</span>:
item = webnotes.bean(<span style="color:rgb(221,17,68)" class="string">'Item'</span>, i[<span style="color:rgb(221,17,68)" class="string">'item_code'</span>]) <span style="color:rgb(153,153,136);font-style:italic" class="comment"># First can get the doctype from db</span>
item.doc.fields.update(i) <span style="color:rgb(153,153,136);font-style:italic" class="comment"># Update the item data based on CAD data</span>
pricelist = getlist(item.doclist, <span style="color:rgb(221,17,68)" class="string">'ref_rate_details'</span>) <span style="color:rgb(153,153,136);font-style:italic" class="comment"># Get the price list</span>
item.save() <span style="color:rgb(153,153,136);font-style:italic" class="comment"># Save the item</span>
<span style="color:rgb(51,51,51);font-weight:bold" class="keyword">except</span>:
item = webnotes.bean(copy=enviroment_template) <span style="color:rgb(153,153,136);font-style:italic" class="comment"># Make a new item based on template</span>
item.doc.fields.update(i) <span style="color:rgb(153,153,136);font-style:italic" class="comment"># Update the item data based on CAD data</span>
item.doclist[<span style="color:rgb(0,153,153)" class="number">1</span>].fields.update({<span style="color:rgb(221,17,68)" class="string">'ref_rate'</span>: price}) <span style="color:rgb(153,153,136);font-style:italic" class="comment"># Update the price</span>
item.insert() <span style="color:rgb(153,153,136);font-style:italic" class="comment"># Save the item</span>
items.append(i[<span style="color:rgb(221,17,68)" class="string">'item_code'</span>]) <span style="color:rgb(153,153,136);font-style:italic" class="comment"># Append item code to response</span>
<span style="color:rgb(51,51,51);font-weight:bold" class="keyword">return</span> {
<span style="color:rgb(221,17,68)" class="string">'project_cost'</span>: cost,
<span style="color:rgb(221,17,68)" class="string">'project_increase'</span>: increase,
<span style="color:rgb(221,17,68)" class="string">'project_cost_net'</span>: cost-increase,
<span style="color:rgb(221,17,68)" class="string">'items'</span>: items
}</code></pre>
--
–
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-forum+un...@googlegroups.com.
To post to this group, send email to er...@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.