def focus(self): while True: c = self.win.getch() try: if c == 27: return elif c == ord("1"): self.subviews["purchase_id"].focus() self.render() elif c == ord("2"): self.subviews["invoice_id"].focus() inv_id = self.data.get("invoice_id") if inv_id: with Transaction(): inv = get_model("account.invoice").browse(inv_id) rel = inv.related_id if rel and rel._model == "purchase.order": self.data["purchase_id"] = rel.id self.render() elif c == ord("3"): self.subviews["location_id"].focus() self.render() elif c == ord("4"): opts = { "window": self.win, "prev_product_id": self.prev_product_id, } v = make_view("add_product", opts) v.render() res = v.focus() if res: self.data["lines"].append(res) self.prev_product_id = res["product_id"] self.render() elif c == ord("5"): self.validate() return elif c == curses.KEY_DOWN: if self.pos < len(self.data["lines"]) - 1: self.pos += 1 self.render_items() elif c == curses.KEY_UP: if self.pos > 0: self.pos -= 1 self.render_items() elif c == curses.KEY_BACKSPACE or c == curses.KEY_DC: if self.data["lines"]: del self.data["lines"][self.pos] self.render_items() except Exception as e: make_view("error", {"message": str(e)}).focus() self.render()
def validate(self): with Transaction(): vals = { "lines": [], } if self.data["purchase_id"]: vals["related_id"] = "purchase.order,%d" % self.data[ "purchase_id"][0] res = get_model("stock.location").search( [["type", "=", "supplier"]], order="id") if not res: raise Exception("Supplier location not found") supp_loc_id = res[0] if not self.data["location_id"]: raise Exception("Missing location") to_loc_id = self.data["location_id"][0] for line in self.data["lines"]: lot_no = line["lot_no"] if lot_no: res = get_model("stock.lot").search( [["number", "=", lot_no]]) if res: lot_id = res[0] else: lot_id = get_model("stock.lot").create( {"number": lot_no}) else: lot_id = None prod_id = line["product_id"][0] prod = get_model("product").browse(prod_id) line_vals = { "product_id": prod.id, "lot_id": lot_id, "qty": line["qty"], "uom_id": prod.uom_id.id, "location_from_id": supp_loc_id, "location_to_id": to_loc_id, } vals["lines"].append(("create", line_vals)) if not vals["lines"]: raise Exception("Empty goods receipt") pick_id = get_model("stock.picking").create( vals, context={"pick_type": "in"}) get_model("stock.picking").set_done([pick_id]) pick = get_model("stock.picking").browse(pick_id) msg = "Goods receipt %s created successfully" % pick.number make_view("message", {"message": msg}).focus() self.render()
def render(self): with Transaction(): self.win.clear() curses.curs_set(0) self.win.addstr(0, 0, "Netforce Terminal", curses.A_BOLD | curses.color_pair(1)) self.win.addstr(1, 0, "Add Product", curses.A_BOLD) opts = { "win": self.win.subwin(1, 80, 3, 0), "key": 1, "string": "Product", "name": "product_id", "relation": "product", "data": self.data, "name_field": "code", } self.subviews["product_id"] = make_view("field_m2o", opts) opts = { "win": self.win.subwin(1, 80, 4, 0), "key": "2", "string": "Lot Number", "name": "lot_no", "data": self.data, } self.subviews["lot_no"] = make_view("field_char", opts) opts = { "win": self.win.subwin(1, 80, 5, 0), "key": "3", "string": "Qty", "name": "qty", "data": self.data, } if self.data["product_id"]: prod_id = self.data["product_id"][0] prod = get_model("product").browse(prod_id) opts["string"] = "Qty (%s)" % prod.uom_id.name self.subviews["qty"] = make_view("field_decimal", opts) self.win.addstr(6, 0, "4.", curses.A_BOLD | curses.color_pair(2)) self.win.addstr(6, 3, "Add Product") if self.data.get("prev_product_id"): self.win.addstr(7, 0, "5.", curses.A_BOLD | curses.color_pair(2)) self.win.addstr(7, 3, "Select Previous Product") for n, view in self.subviews.items(): view.render()
def render(self): with Transaction(): self.win.clear() curses.curs_set(1) self.win.addstr(0, 0, "Netforce Terminal", curses.A_BOLD | curses.color_pair(1)) s = get_model(self.model)._string self.win.addstr(1, 0, "Select %s" % s, curses.A_BOLD) self.win.addstr(3, 0, "Search:") opts = { "win": self.win.subwin(1, 21, 3, 8), "cols": 20, } self.tb = make_view("textbox", opts) h, w = self.win.getmaxyx() self.list_win = self.win.subwin(h - 5, w, 5, 0) self.load_items() self.render_items()
def check_stock(self): with Transaction(): if not self.data["product_id"]: raise Exception("Missing product") cond = [["product_id", "=", self.data["product_id"][0]]] if self.data["location_id"]: cond.append(["location_id", "=", self.data["location_id"][0]]) self.data["lines"] = [] for bal in get_model("stock.balance").search_browse(cond): self.data["lines"].append({ "location_id": [bal.location_id.id, bal.location_id.name], "lot_id": [bal.lot_id.id, bal.lot_id.number] if bal.lot_id else None, "qty_phys": bal.qty_phys, "qty_virt": bal.qty_virt, }) self.render()
def validate(self): with Transaction(): production_id = self.data["production_id"][0] production = get_model("production.order").browse(production_id) vals = { "related_id": "production.order,%d" % production_id, "lines": [], } if not self.data["location_id"]: raise Exception("Missing location") from_loc_id = self.data["location_id"][0] for line in self.data["lines"]: lot_no = line["lot_no"] if lot_no: res = get_model("stock.lot").search( [["number", "=", lot_no]]) if res: lot_id = res[0] else: lot_id = get_model("stock.lot").create( {"number": lot_no}) else: lot_id = None prod_id = line["product_id"][0] prod = get_model("product").browse(prod_id) line_vals = { "product_id": prod.id, "lot_id": lot_id, "qty": line["qty"], "uom_id": prod.uom_id.id, "location_from_id": from_loc_id, "location_to_id": production.production_location_id.id, } vals["lines"].append(("create", line_vals)) if not vals["lines"]: raise Exception("Empty goods transfer") pick_id = get_model("stock.picking").create( vals, context={"pick_type": "internal"}) get_model("stock.picking").set_done([pick_id]) pick = get_model("stock.picking").browse(pick_id) msg = "Goods transfer %s created successfully" % pick.number make_view("message", {"message": msg}).focus() self.render()
def focus(self): opts = { "model": self.relation, "condition": self.condition, } v = make_view("select_item", opts) v.render() res = v.focus() with Transaction(): if res: obj_id = res["select_id"] if obj_id: if self.name_field: n = get_model(self.relation).read( [obj_id], [self.name_field])[0][self.name_field] else: n = get_model(self.relation).name_get([obj_id])[0][1] val = (obj_id, n) else: val = None self.data[self.name] = val
def load_items(self): with Transaction(): q = self.tb.get_value() self.items = get_model(self.model).name_search( q, condition=self.condition) self.pos = 0