# it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import op_db_library as db kehe = db.get_distributor_byname('Kehe') kehe_items = db.get_distributor_items(show_distributors=[kehe]) for p,item,d,dist_item in kehe_items: # p and d are unused if d.name != 'Kehe': continue note = item.get_notes() d_id = dist_item.get_dist_item_id() note += '\nold kehe id:' + str(d_id) item.set_notes(note) barcodes = item.get_barcodes() if len(barcodes) == 0 : dist_item.set_dist_item_id('') if len(barcodes) == 1: dist_item.set_dist_item_id(barcodes[0]) else: print 'Item %s has more than 1 barcode --> ambiguity, no action taken.' % (item)
def main(): form = cgi.FieldStorage() idf.init(form,discontinued=True,distributors=True,categories=True) print_headers() print ''' <body>''' print ''' <div>Click table headers to sort</div> <div>To change a price, enter the new price in the text field and hit ENTER </div> <div>To change an item's price group, enter the new group and hit ENTER </div> <div>To split an item from the given group click the 'split' button. It will be given a new price_id </div> <div>To log a delivery select the appropriate distributor from the dropdown, type in the number delievered (positive or negative integer) and press ENTER </div> <div style="clear: both; height: 15px;"> </div>''' print '''<form name="options" action="manage_prices.py" method="get">''' options = idf.print_form() print '''<input type="submit" value="Change options" /> </form>''' print '''<br><br>''' print '''<table border=0 id="main" class="sortable" cellspacing=0 cellpadding=0> <thead class="col-header"> <th class="th">Price ID </th> <th class="th">OP Price</th> <th class="th">SaleUnit</th> <th class="th">Name</th> <th class="th">SKU</th> <th class="th">Count</th> <th class="th">Deliv</th> <th class="th">Distributor</th> <th class="th">D ItemID </th> <th class="th">Case Cost</th> <th class="th">Case Size</th> <th class="th">Case Units</th> <th class="th">Each Cost</th> <th class="th">Margin</th> <th class="th">Change P_ID</th> <th class="th">Split</th> <th class="th">Stocked</th> </thead><tbody id="item-stats">\n''' cur_price = -1 cur_item = -1 units = [(u.get_id(), u.get_name()) for u in db.get_units()] for price,item,dist,dist_item in db.get_distributor_items(**options): item_id = item.get_id() price_id = price.get_id() if cur_price != price_id: if cur_price != -1: # end previous row print '</tbody>' print '</table></td></tr>' print '<tr class="color-row" id="%d_price"><td class="td">%d</td><td class="td">$<input type="text" class="price" id="%d_price_input" size="3" value="%.2f"></input></td>' % (price_id, price_id, price_id, price.get_unit_cost()) print '''<td class="td"> <select class="saleunit" id="%d_sale_unit" onChange="setPriceSaleUnit(%d)">''' % (price_id,price_id) for unit in units: print '''<option value="%d"''' % (unit[0],) if unit[0] == price.get_sale_unit_id(): print ''' selected>''' else: print '''>''' print unit[1], ''' </option>''' print '''</select></td>''' print'<td colspan="%d" class="td"><table id="%d_table" cellspacing=0 cellpadding=0>' % (colspan,price_id) print '<tbody class="inner_table">' cur_price = price_id print '<tr class="%d_tr">' % (item_id,) if cur_item != item_id: item_dist_count = item.get_distributor_count() print '''<td rowspan='%s' id='%d_td' width='400' style='padding-left: 1em;'> %s </td>''' % (item_dist_count, item_id, str(item)) print '''<td rowspan='%s' width='80'> <a href='%s' onclick="window.open(this.href,'_blank'); return false;">%d</a> </td>''' % (item_dist_count,db.get_item_info_page_link(item_id),item_id) print '''<td rowspan='%s' width='80' id="%d_amt"> %d </td>''' % (item_dist_count,item_id,item.get_count()) print '''<td rowspan="%d" width='100'><input class="amt" id="%d_in" name="%d_in" size="2"/>''' % (item_dist_count,item_id, item_id) print '''<select id="%d_dist_in" name="%d_dist_in">''' % (item_id, item_id) for d in item.get_distributors(): print '''<option value="%s"> %s </option>''' % (d.get_dist_id(),d.get_distributor()) print '''</select>''' print '''</td>\n''' print '''<td width="100"> %s </td>''' % (dist,) print '''<td width="100"> <input class="ditemid" size="10" value="%s" id="%d_%d_ditemid" /> </td>''' % (dist_item.get_dist_item_id(),item.get_id(), dist.get_id()) each_cost = dist_item.get_each_cost() op_price = item.get_price() tax = item.get_tax_value() if op_price - tax > 0: margin = (1.0 - each_cost/(op_price - tax)) * 100 else: margin = 100 print '''<td width="100">$<input class="casecost" size="6" value="%.2f" id="%d_%d_%d_casecost" /></td>''' % (dist_item.get_wholesale_price(), item.get_id(), dist.get_id(), price_id) print '''<td width="80" ><input class="casesize" size="5" value="%.2f" id="%d_%d_%d_casesize"/> </td>''' % (dist_item.get_case_size(), item.get_id(), dist.get_id(), price_id) print '''<td width="80">%s </td>''' % (dist_item.get_case_unit(),) print '''<td width="80" id="%d_%d_each">$%.2f </td>''' % (item_id,dist.get_id(),each_cost) if margin <= 20: print '''<td width="80" class="bad" id="%d_%d_margin"> %.0f%% </td>''' % (item_id,dist.get_id(), margin) elif margin <= 30: print '''<td width="80" class="mid" id="%d_%d_margin"> %.0f%% </td>''' % (item_id,dist.get_id(), margin) else: print '''<td width="80" class="good" id="%d_%d_margin"> %.0f%% </td>''' % (item_id,dist.get_id(), margin) if cur_item != item_id: print '''<td rowspan='%s' width="100"><input class="group" id="%d_group" type="text" size="3"></input></td>''' % (item_dist_count,item_id) print '''<td rowspan='%s' width="80"><div onClick="split(%d)">split</div></td>''' % (item_dist_count,item_id) if not item.get_is_discontinued(): print '''<td><input type="checkbox" id="%d_isStocked" onClick="discontinueItem(this)" checked /> </td>''' % (item_id,) else: print '''<td><input type="checkbox" id="%d_isStocked" onClick="discontinueItem(this)"/> </td>''' % (item_id,) cur_item = item_id print '''</tr>\n''' print '</table></td></tr>' print '''</tbody></table>\n''' print '''</body></html>'''