def update_order(board_name, order): '''Save the order of cards in columns''' board = dataent.get_doc('Kanban Board', board_name) doctype = board.reference_doctype fieldname = board.field_name order_dict = json.loads(order) updated_cards = [] for col_name, cards in iteritems(order_dict): order_list = [] for card in cards: column = dataent.get_value( doctype, {'name': card}, fieldname ) if column != col_name: dataent.set_value(doctype, card, fieldname, col_name) updated_cards.append(dict( name=card, column=col_name )) for column in board.columns: if column.column_name == col_name: column.order = json.dumps(cards) board.save() return board, updated_cards
def test_set_value(self): todo = dataent.get_doc(dict(doctype='ToDo', description='test')).insert() dataent.set_value('ToDo', todo.name, 'description', 'test 1') self.assertEqual(dataent.get_value('ToDo', todo.name, 'description'), 'test 1') dataent.set_value('ToDo', todo.name, {'description': 'test 2'}) self.assertEqual(dataent.get_value('ToDo', todo.name, 'description'), 'test 2')
def set_default_if_missing(self): if cint(self.selling): if not dataent.db.get_value("Selling Settings", None, "selling_price_list"): dataent.set_value("Selling Settings", "Selling Settings", "selling_price_list", self.name) elif cint(self.buying): if not dataent.db.get_value("Buying Settings", None, "buying_price_list"): dataent.set_value("Buying Settings", "Buying Settings", "buying_price_list", self.name)
def sync_all(in_background=False): if not in_background: dataent.msgprint('Sync has started and will run in the background...') verify_whitelisted_call() dataent.enqueue( 'bench_manager.bench_manager.doctype.bench_settings.bench_settings.sync_sites' ) dataent.enqueue( 'bench_manager.bench_manager.doctype.bench_settings.bench_settings.sync_apps' ) dataent.enqueue( 'bench_manager.bench_manager.doctype.bench_settings.bench_settings.sync_backups' ) dataent.set_value('Bench Settings', None, 'last_sync_timestamp', dataent.utils.time.time())
def setup_holiday_list(): """Setup Holiday List for the current year""" year = now_datetime().year holiday_list = dataent.get_doc({ "doctype": "Holiday List", "holiday_list_name": str(year), "from_date": "{0}-01-01".format(year), "to_date": "{0}-12-31".format(year), }) holiday_list.insert() holiday_list.weekly_off = "Saturday" holiday_list.get_weekly_off_dates() holiday_list.weekly_off = "Sunday" holiday_list.get_weekly_off_dates() holiday_list.save() dataent.set_value("Company", epaas.get_default_company(), "default_holiday_list", holiday_list.name)
def execute(): for doctype in ['Expense Claim', 'Leave Application']: active_workflow = get_workflow_name(doctype) if not active_workflow: continue workflow_states = dataent.get_all( 'Workflow Document State', filters=[['parent', '=', active_workflow]], fields=['*']) for state in workflow_states: if state.update_field: continue status_field = 'approval_status' if doctype == "Expense Claim" else 'status' dataent.set_value('Workflow Document State', state.name, 'update_field', status_field) dataent.set_value('Workflow Document State', state.name, 'update_value', state.state)
def save_new_records(test_records): for record in test_records: kwargs = dict( doctype=record.get("doctype"), docname=record.get("date") + '-' + record.get("from_currency") + '-' + record.get("to_currency"), fieldname="exchange_rate", value=record.get("exchange_rate"), ) try: dataent.set_value(**kwargs) except dataent.DoesNotExistError: curr_exchange = dataent.new_doc(record.get("doctype")) curr_exchange.date = record["date"] curr_exchange.from_currency = record["from_currency"] curr_exchange.to_currency = record["to_currency"] curr_exchange.exchange_rate = record["exchange_rate"] curr_exchange.insert()
def test_batch_name_with_naming_series(self): stock_settings = dataent.get_single('Stock Settings') use_naming_series = cint(stock_settings.use_naming_series) if not use_naming_series: dataent.set_value('Stock Settings', 'Stock Settings', 'use_naming_series', 1) batch = self.make_new_batch('_Test Stock Item For Batch Test1') batch_name = batch.name self.assertTrue(batch_name.startswith('BATCH-')) batch.delete() batch = self.make_new_batch('_Test Stock Item For Batch Test2') self.assertEqual(batch_name, batch.name) # reset Stock Settings if not use_naming_series: dataent.set_value('Stock Settings', 'Stock Settings', 'use_naming_series', 0)
def _close_the_doc(start_time, key, console_dump, status, user): time_taken = dataent.utils.time.time() - start_time final_console_dump = '' console_dump = console_dump.split('\n\r') for i in console_dump: i = i.split('\r') final_console_dump += '\n' + i[-1] dataent.set_value('Bench Manager Command', key, 'console', final_console_dump) dataent.set_value('Bench Manager Command', key, 'status', status) dataent.set_value('Bench Manager Command', key, 'time_taken', time_taken) dataent.publish_realtime(key, '\n\n' + status + '!\nThe operation took ' + str(time_taken) + ' seconds', user=user)
def test_serial_no_based_delivery(self): dataent.set_value("Stock Settings", None, "automatically_set_serial_nos_based_on_fifo", 1) from epaas.stock.doctype.item.test_item import make_item item = make_item( "_Reserved_Serialized_Item", { "is_stock_item": 1, "maintain_stock": 1, "has_serial_no": 1, "serial_no_series": "SI.####", "valuation_rate": 500, "item_defaults": [{ "default_warehouse": "_Test Warehouse - _TC", "company": "_Test Company" }] }) dataent.db.sql("""delete from `tabSerial No` where item_code=%s""", (item.item_code)) make_item( "_Test Item A", { "maintain_stock": 1, "valuation_rate": 100, "item_defaults": [{ "default_warehouse": "_Test Warehouse - _TC", "company": "_Test Company" }] }) make_item( "_Test Item B", { "maintain_stock": 1, "valuation_rate": 200, "item_defaults": [{ "default_warehouse": "_Test Warehouse - _TC", "company": "_Test Company" }] }) from epaas.manufacturing.doctype.production_plan.test_production_plan import make_bom make_bom(item=item.item_code, rate=1000, raw_materials=['_Test Item A', '_Test Item B']) so = make_sales_order( **{ "item_list": [{ "item_code": item.item_code, "ensure_delivery_based_on_produced_serial_no": 1, "qty": 1, "rate": 1000 }] }) so.submit() from epaas.manufacturing.doctype.work_order.test_work_order import \ make_wo_order_test_record work_order = make_wo_order_test_record(item=item.item_code, qty=1, do_not_save=True) work_order.fg_warehouse = "_Test Warehouse - _TC" work_order.sales_order = so.name work_order.submit() make_stock_entry(item_code=item.item_code, target="_Test Warehouse - _TC", qty=1) item_serial_no = dataent.get_doc("Serial No", {"item_code": item.item_code}) from epaas.manufacturing.doctype.work_order.work_order import \ make_stock_entry as make_production_stock_entry se = dataent.get_doc( make_production_stock_entry(work_order.name, "Manufacture", 1)) se.submit() reserved_serial_no = se.get("items")[2].serial_no serial_no_so = dataent.get_value("Serial No", reserved_serial_no, "sales_order") self.assertEqual(serial_no_so, so.name) dn = make_delivery_note(so.name) dn.save() self.assertEqual(reserved_serial_no, dn.get("items")[0].serial_no) item_line = dn.get("items")[0] item_line.serial_no = item_serial_no.name self.assertRaises(dataent.ValidationError, dn.submit) item_line = dn.get("items")[0] item_line.serial_no = reserved_serial_no self.assertTrue(dn.submit) dn.load_from_db() dn.cancel() si = make_sales_invoice(so.name) si.update_stock = 1 si.save() self.assertEqual(si.get("items")[0].serial_no, reserved_serial_no) item_line = si.get("items")[0] item_line.serial_no = item_serial_no.name self.assertRaises(dataent.ValidationError, dn.submit) item_line = si.get("items")[0] item_line.serial_no = reserved_serial_no self.assertTrue(si.submit) si.submit() si.load_from_db() si.cancel() si = make_sales_invoice(so.name) si.update_stock = 0 si.submit() from epaas.accounts.doctype.sales_invoice.sales_invoice import \ make_delivery_note as make_delivery_note_from_invoice dn = make_delivery_note_from_invoice(si.name) dn.save() dn.submit() self.assertEqual(dn.get("items")[0].serial_no, reserved_serial_no) dn.load_from_db() dn.cancel() si.load_from_db() si.cancel() se.load_from_db() se.cancel() self.assertFalse( dataent.db.exists("Serial No", {"sales_order": so.name}))
def remove_role(role): dataent.db.sql('delete from `tabHas Role` where role=%s', role) dataent.set_value('Role', role, 'disabled', 1)
def execute(): dataent.reload_doc("setup", "doctype", "country") import_country_and_currency() for name, country in iteritems(get_all()): dataent.set_value("Country", name, "code", country.get("code"))