Skip to Content
Odoo เมนู
  • ลงชื่อเข้าใช้
  • ทดลองใช้ฟรี
  • แอป
    การเงิน
    • ระบบบัญชี
    • ระบบการออกใบแจ้งหนี้
    • ระบบบัญชีรายจ่าย
    • ระบบการจัดการข้อมูลผ่านสเปรดชีต (BI)
    • เอกสาร
    • ระบบลงลายเซ็น
    การขาย
    • ลูกค้าสัมพันธ์
    • การขาย
    • POS ร้านค้า
    • POS ร้านอาหาร
    • ระบบสมัครสมาชิก
    • การเช่า
    การจัดการเว็บไซต์
    • เครื่องมือสร้างเว็บไซต์
    • ระบบการขายออนไลน์
    • บล็อก
    • ฟอรั่ม
    • ไลฟ์แชท
    • ระบบการอบรมออนไลน์
    ซัพพลายเชน
    • คลังสินค้า
    • ระบบการผลิต
    • PLM
    • ระบบการจัดซื้อ
    • การซ่อมบำรุง
    • ระบบจัดการคุณภาพ
    ทรัพยากรบุคคล
    • ข้อมูลพนักงาน
    • ระบบสรรหาบุคลากร
    • ระบบการลา
    • การประเมิน
    • ระบบการแนะนำพนักงาน
    • ระบบจัดการยานพาหนะ
    การตลาด
    • โซเชียลมาร์เก็ตติ้ง
    • การตลาดผ่านอีเมล
    • ระบบการตลาดผ่าน SMS
    • ระบบการจัดงานอีเวนต์
    • การตลาดแบบอัตโนมัติ
    • ระบบแบบสำรวจ
    การบริการ
    • โปรเจกต์
    • ระบบบันทึกเวลา
    • ระบบการจัดการบริการภาคสนาม
    • ระบบดูแลช่วยเหลือ
    • การวางแผน
    • การนัดหมาย
    ประสิทธิผล
    • ระบบแสดงความคิดเห็น
    • ระบบการอนุมัติ
    • ไอโอที
    • VoIP
    • คลังข้อมูล
    • WhatsApp
    แอปพลิเคชันของบุคคลที่สาม Odoo สตูดิโอ แพลตฟอร์มคลาวด์ของ Odoo
  • อุตสาหกรรม
    การค้าปลีก
    • ร้านขายหนังสือ
    • ร้านขายเสื้อผ้า
    • ร้านขายเฟอร์นิเจอร์
    • ร้านขายของชำ
    • ร้านขายฮาร์ดแวร์
    • ร้านขายของเล่น
    Food & Hospitality
    • บาร์และผับ
    • ร้านอาหาร
    • อาหารฟาสต์ฟู้ด
    • Guest House
    • ตัวแทนจำหน่ายเครื่องดื่ม
    • Hotel
    อสังหาริมทรัพย์
    • Real Estate Agency
    • บริษัทสถาปัตยกรรม
    • บริษัทรับเหมา
    • การจัดการอสังหาริมทรัพย์
    • การจัดสวน
    • สมาคมเจ้าของอสังหาริมทรัพย์
    ปรึกษา
    • สำนักงานบัญชี
    • Odoo พาร์ทเนอร์
    • เอเจนซี่การตลาด
    • สำนักงานกฎหมาย
    • บริการสรรหาบุคลากร
    • การตรวจสอบและการรับรอง
    ระบบการผลิต
    • Textile
    • เหล็ก
    • เฟอร์นิเจอร์
    • อาหาร
    • Brewery
    • ของขวัญขององค์กร
    สุขภาพ & ฟิตเนส
    • ชมรมกีฬา
    • ร้านขายแว่นตา
    • ฟิตเนส
    • ผู้ประกอบวิชาชีพด้านสุขภาพ
    • ร้านขายยา
    • ร้านทำผม
    Trades
    • ช่างซ่อม
    • ฮาร์ดแวร์และการสนับสนุนด้านไอที
    • ระบบพลังงานแสงอาทิตย์
    • ช่างทำรองเท้า
    • บริการทำความสะอาด
    • HVAC Services
    อื่น ๆ
    • Nonprofit Organization
    • สำนักงานสิ่งแวดล้อม
    • ร้านเช่าป้ายโฆษณา
    • การถ่ายภาพ
    • ร้านเช่าจักรยาน
    • ตัวแทนจำหน่ายซอฟต์แวร์
    Browse all Industries
  • คอมมูนิตี้
    ศึกษา
    • บทเรียน
    • เอกสารกำกับโปรแกรม
    • การรับรอง
    • การฝึกอบรม
    • บล็อก
    • พอดแคสต์
    เพิ่มศักยภาพให้กับการศึกษา
    • โปรแกรมการศึกษา
    • Scale Up! Business Game
    • เยี่ยมชม Odoo
    รับซอฟต์แวร์
    • ดาวน์โหลด
    • เปรียบเทียบรุ่น
    • เผยแพร่
    ทำงานร่วมกัน
    • Github
    • ฟอรั่ม
    • ระบบการจัดงานอีเวนต์
    • การแปล
    • ร่วมเป็นพาร์ทเนอร์
    • Services for Partners
    • ลงทะเบียนเพื่อสร้างบัญชีบริษัทของคุณ
    รับบริการ
    • ค้นหาพาร์ทเนอร์
    • ค้นหานักบัญชี
    • พบกับที่ปรึกษา
    • บริการติดตั้งระบบเพื่อใช้งาน
    • ข้อมูลอ้างอิงลูกค้า
    • การสนับสนุน
    • อัปเกรด
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    รับการสาธิต
  • ราคา
  • ช่วยเหลือ

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • ลูกค้าสัมพันธ์
  • e-Commerce
  • ระบบบัญชี
  • สินค้าคงคลัง
  • PoS
  • โปรเจกต์
  • MRP
All apps
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
All Posts คน เหรียญรางวัล
แท็ก (View all)
odoo accounting v14 pos v15
เกี่ยวกับฟอรั่มนี้
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
All Posts คน เหรียญรางวัล
แท็ก (View all)
odoo accounting v14 pos v15
เกี่ยวกับฟอรั่มนี้
ช่วยเหลือ

How to create two models in a function similar to fields ?

ติดตาม

รับการแจ้งเตือนเมื่อมีกิจกรรมในโพสต์นี้

คำถามนี้ถูกตั้งค่าสถานะ
javascriptspreadsheets
2 ตอบกลับ
8737 มุมมอง
อวตาร
divya

hi frnds,

for example i have a function like

fx=oe_browse("project.issue", "id name description user_id project_id partner_id day_open day_close working_hours_open working_hours_close")

how to add another model like project.project  in that same function

 

function onOpen() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var menuEntries = [{name: "Insert Selection Field", functionName: "menu_insertSelection"},
                     {name: "Settings", functionName: "menu_settings"} ];
  ss.addMenu("OpenERP", menuEntries);
  var a1 = ss.getRange("O60");
  if (a1.getFormula().indexOf('oe_settings') > -1 && ScriptProperties.getProperty('url')){
    a1.setFormula("");
  }
}

function menu_settings() {
  var params = [["url", "URL (with http:// or https://)"], ["dbname", "Database Name"], ["username", "Username"], ["password", "Password"]];
  for (var i = 0; i < params.length; i++){
    var input = Browser.inputBox("Server Settings", params[i][1], Browser.Buttons.OK_CANCEL);
    if (input === "cancel"){
      break;
    }
    else{
      ScriptProperties.setProperty(params[i][0], input);
    }
  }
}

function menu_insertSelection() {
  var input = Browser.inputBox('Insert Selection', 'Format: model, field, domain', Browser.Buttons.OK_CANCEL);
  if (input !== "cancel"){
    input = input.replace(/\s+/g, "").split(",");
    var model = input[0];
    var field = input[1];
    var domain = input.slice(2,input.length).join(",");
    var range = SpreadsheetApp.getActiveRange();
    oe_select(range, model, field, domain);
  }
}

function oe_settings(url, dbname, username, password){
  if (url)ScriptProperties.setProperty('url', url);
  if (dbname)ScriptProperties.setProperty('dbname', dbname);
  if (username)ScriptProperties.setProperty('username', username);
  if (password)ScriptProperties.setProperty('password', password);
}


function oe_browse(model, fields, domain, sort, limit){
  if(typeof model !== "string"){
 
   throw "model arg expecting string";
   
  }
  if(typeof fields !== "string"){
    throw "fields arg expecting comma separated field names";
  }
  if (!domain) domain = "[]";
  if(typeof domain !== "string"){
    throw "domain arg expecting string";
  }
  if(sort && typeof sort !== "string"){
    throw "sort arg expecting string";
  }
  if(limit && typeof limit !== "number"){
    throw "limit arg expecting number";
  }
 
  fields = fields.replace(/\s+/g, ",").split(",");
  if(domain) {
    domain = domain.replace(/\'/g, '"');
  }
  domain = Utilities.jsonParse(domain);
 
  var records = seach_read(model, fields, domain, sort, limit);
  return parse_records_for_ss(records, fields);
}

function oe_read_group(model, fields, groupby, domain, orderby, limit){
  if(typeof model !== "string"){
    throw "model arg expecting string";
  }
  if(fields && typeof fields !== "string"){
    throw "fields arg expecting comma separated field names";
  }
  if(groupby && typeof groupby !== "string"){
    throw "groupby arg expecting comma separated field names";
  }
  if (!domain) domain = "[]";
  if(typeof domain !== "string"){
    throw "domain arg expecting string";
  }
  if(orderby && typeof orderby !== "string"){
    throw "orderby arg expecting string";
  }
  if(limit && typeof limit !== "number"){
    throw "limit arg expecting number";
  }
 
  fields = fields ? fields.replace(/\s+/g, ",").split(",") : [];
  var fields_tosend = fields.slice();
  var count_index = fields_tosend.indexOf("_count");
  if (count_index !== -1){
    fields_tosend.splice(count_index, 1);
  }
  groupby = groupby ? groupby.replace(/\s+/g, ",").split(",") : "";
  if(domain) {
    domain = domain.replace(/\'/g, '"');
  }
  domain = domain ? Utilities.jsonParse(domain) : [];

  var kwargs = {
    "context" : {"group_by":groupby},
    "domain" : domain,
    "fields" : fields_tosend,
    "groupby": groupby,
    "limit": limit ? limit : 10,
    "offset": 0,
    "orderby": orderby ? orderby : false,
  }
  var records = call_kw(model, "read_group", [], {}, 0, kwargs);
  if (groupby.length > 0){
    for (var i = 0; i < records.length; i++){
      if (records[i]["__context"] && records[i]["__context"]["group_by"].length > 0){
        kwargs["domain"] = records[i]["__domain"]
        kwargs["context"] = records[i]["__context"]
        kwargs["groupby"] = records[i]["__context"]["group_by"]
        var sub_records = call_kw(model, "read_group", [], {}, 0, kwargs);
        sub_records.forEach(function(item){
          for(var j = 0; j < this.groupby_fields.length;j++){
            item[this.groupby_fields[j]] = records[i][this.groupby_fields[j]]
          }
        },{
          "groupby_fields" : groupby.slice(0,groupby.indexOf(kwargs["groupby"][0]))
        });
        records.splice.apply(records, [i,1].concat(sub_records));
        i--;
      }
    }
  }
  var count_index = fields.indexOf('_count');
  if (count_index !== -1){
    fields[count_index] = groupby instanceof Array && groupby.length > 0 ? groupby[groupby.length-1]+"_count" : groupby+"_count";
  }
  return parse_records_for_ss(records, fields);
}

function oe_select(range, model, field, domain){
  if(typeof model !== "string"){
    throw "model arg expecting string";
  }
  if(typeof field !== "string"){
    throw "field arg expecting field name";
  }
  if (!domain) domain = "[]";
  if(typeof domain !== "string"){
    throw "domain arg expecting String";
  }
  var records = oe_read_group(model, field, field, domain);
  var dv = range.getDataValidation();
  var result = [];
  for (var i = 0; i < records.length; i++){
    var value = records[i][0];
    if (value)result.push(value.replace(",", ""));
  }
  result = result.slice(0,10);
  dv.requireValuesInList(result);
  dv.setShowDropDown(true);
  range.setDataValidation(dv);
}

function parse_records_for_ss(records, fields){
  var result = [];
  var types = [];
  if (fields.length === 0 && records.length > 0){
    fields = Object.keys(records[0]);
    result.push(fields);
  }
  for (var i = 0; i < records.length; i++){
    recordArr = [];
    for (var j = 0; j < fields.length; j++){
      var value = records[i][fields[j]];
      if(typeof value === "number")types[fields[j]] = "number";
      if (value instanceof Array && value.length === 2 && typeof value[1] === "string")value = value[1];
      else if(value instanceof Array) value = value.join(','); //TODO: name_get on ids
      else if(typeof value !== "number" && !(value))value = types[fields[j]] && types[fields[j]] === "number" ? 0 : 'Undefined';
      recordArr.push(value);
    }
    result.push(recordArr);
  }
  return result.length > 0 ? result : 'No Result';
}

function seach_read(model, fields, domain, sort, limit){
  if(!(fields instanceof Array)){
    throw "fields arg expecting an Array, not "+typeof fields;
  }
  if (!domain)domain = [];
  if(!(domain instanceof Array)){
    throw "domain arg expecting an Array, not "+typeof domain;
  }
  var session_id = getScriptProperty("session_id");
  var context = {};
  var params = {
    "model" : model,
    "fields" : fields,
    "limit": limit ? limit : 80,
    "domain" : domain,
    "sort": sort,
    "session_id": session_id,
    "context": context,
  }
  var options =
      {
        "method" : "post",
        "contentType" : "application/json",
        "payload" : {
          "id": 1,
          "jsonrpc": "2.0",
          "method": "googlescript",
          "params" : params,
        }
      };
  var json_result = Utilities.jsonParse(oe_fetch(getScriptProperty('url')+'/web/dataset/search_read', options));
  if (!!json_result.error){
    throw format_openerp_error(json_result.error);
  }
  return json_result.result.records;
}

function call_kw(model, method, args, context, debug, kwargs){
  if (typeof model !== "string"){
    throw "model arg expecting a String, not "+typeof model;
  }
  if (typeof method !== "string"){
    throw "method arg expecting a String, not "+typeof model;
  }
  if(!(args instanceof Array)){
    throw "args arg expecting an Array, not "+typeof args;
  }
  if(!(context instanceof Object)){
    throw "context arg expecting an Object, not "+typeof context;
  }
  if(typeof debug !== "number"){
    throw "debug arg expecting a boolean Number, not "+typeof debug;
  }
  if(!(kwargs instanceof Object)){
    throw "kwargs arg expecting an Object, not "+typeof kwargs;
  }
  var session_id = getScriptProperty('session_id');
  var params = {
    "args": args,
    "context": context,
    "debug" : debug,
    "kwargs": kwargs,
    "method": method,
    "model": model,
    "session_id": session_id,
  }
  var options =
      {
        "method" : "post",
        "contentType" : "application/json",
        "payload" : {
          "id": 1,
          "jsonrpc": "2.0",
          "method": "googlescript",
          "params" : params,
        }
      };
  var json_result = Utilities.jsonParse(oe_fetch(getScriptProperty('url')+'/web/dataset/call_kw', options));
  if (!!json_result.error){
    throw format_openerp_error(json_result.error);
  }
  return json_result.result;
}

function authenticate(){
  Logger.log('Authentication requested!');
  var url = getScriptProperty("url");
  var dbname = getScriptProperty("dbname");
  var username = getScriptProperty("username");
  var password = getScriptProperty("password");
  if (!url || !dbname || !username || !password){
    throw "At least one connection detail is not set. You can set them OpenERP > Settings in the menu bar";
  }
  var params = {
    "db": dbname,
    "login": username,
    "password": password,
  }
  var options ={
    "method" : "post",
    "contentType" : "application/json",
    "payload" : Utilities.jsonStringify({
      "id": 1,
      "jsonrpc": "2.0",
      "method": "googlescript",
      "params" : params,
    })
  };
  var response = UrlFetchApp.fetch(url+'/web/session/authenticate', options);
  var json_response = Utilities.jsonParse(response);
  if (json_response.result.uid){
    var sid = response.getHeaders()["Set-Cookie"].split(" ")[0];
    var session_id = json_response.result.session_id;
    ScriptProperties.setProperty("sid", sid);
    ScriptProperties.setProperty("session_id", session_id)
    return {"sid": sid, "session_id": session_id};
  }
  throw "Authentication Error";
}

function oe_fetch(url, options){
  var sid = getScriptProperty("sid");
  var session_id = getScriptProperty("session_id");
  if (!sid || !session_id){
    var authentication = authenticate();
    sid = authentication.sid;
    session_id = authentication.session_id;
  }
  if (typeof options.headers === 'undefined')options['headers'] = {'cookie': sid};
  else options.headers['cookie'] = sid;
  options.payload.params['session_id'] = session_id;
  options['payload'] = Utilities.jsonStringify(options.payload);
  for (var i = 0; i < 1; i++){
    var result = UrlFetchApp.fetch(url, options);
    var json_result = Utilities.jsonParse(result);
    if (json_result.error && json_result.error.data.type === "client_exception" && json_result.error.data.debug.indexOf("SessionExpiredException") !== -1){
      authentication = authenticate();
      options['payload'] = Utilities.jsonParse(options.payload);
      options.headers['cookie'] = authentication.sid;
      options.payload.params['session_id'] = authentication.session_id;
      options['payload'] = Utilities.jsonStringify(options.payload);
    }
    else if(json_result.error){
      throw format_openerp_error(json_result.error);
    }
    else{
      return result;
    }
  }
  throw "Unable to fetch data due to session expired exception";
}

function getScriptProperty(key) {
  var FailLimit = 100;
  var RetryInterval = 50;
  var ScriptPropertyValue = "";
  var Retries=0;
  var randomnumber = 0;
  var TryAgain=true;
  while (TryAgain)
  {
    Retries++;
    randomnumber=Math.floor(Math.random()*59);
    Utilities.sleep(randomnumber*RetryInterval);
    Logger.log(randomnumber*RetryInterval);
    try
    {
      TryAgain=false;
      ScriptPropertyValue = ScriptProperties.getProperty(key);
    }
    catch(err)
    {
      TryAgain = (Retries<FailLimit);
      if (!TryAgain){
        throw 'Too many attempts to acces script property';
      }
      continue;
  }
  return ScriptPropertyValue;
  }
}

function format_openerp_error(error){
  var error_type = error.data.type;
  var trace = "";
  if (error_type === "client_exception")trace = error.data.debug;
  else if (error_type === "server_exception")trace= error.data.fault_code;
  else trace = Utilities.jsonStringify(error.data);
  return error.message + ": "+error_type+", "+ trace;
}

-1
อวตาร
ละทิ้ง
อวตาร
Ludo - 21South
คำตอบที่ดีที่สุด

I am not quite sure what you are trying to accomplish here? Have you read the documentation on the OpenERP ORM model? It looks like you are trying to make a function for looking through the database, while this might be very unnessary.

Trying looking through this:

https://doc.openerp.com/trunk/server/api_models/

0
อวตาร
ละทิ้ง
divya
ผู้เขียน

Hello Ludo, It is not related to ORM methods, This is the code which we are using for spreadsheets, In this it is taking one table data from database but i want to fetch mutiple table data with in one sheet.

อวตาร
divya
ผู้เขียน คำตอบที่ดีที่สุด

How to add mutiple model function in this ?

0
อวตาร
ละทิ้ง
สนุกกับการพูดคุยนี้ใช่ไหม? เข้าร่วมเลย!

สร้างบัญชีวันนี้เพื่อเพลิดเพลินไปกับฟีเจอร์พิเศษและมีส่วนร่วมกับคอมมูนิตี้ที่ยอดเยี่ยมของเรา!

ลงชื่อ
Related Posts ตอบกลับ มุมมอง กิจกรรม
Patch Spreadsheet Date Ranges in 17 แก้ไขแล้ว
javascript spreadsheets 17.0
อวตาร
อวตาร
อวตาร
3
ก.พ. 25
3028
Cannot import @website_sale/js/utils
javascript
อวตาร
อวตาร
2
พ.ย. 25
517
Can pivots from different models coexist in the same spreadsheet?
spreadsheets
อวตาร
อวตาร
1
ต.ค. 25
2471
How do I build a Dashboard from a Spreadsheet?
spreadsheets
อวตาร
อวตาร
อวตาร
2
ก.ย. 25
977
Dashboard & Spreadsheet
spreadsheets
อวตาร
1
ก.ย. 25
2204
คอมมูนิตี้
  • บทเรียน
  • เอกสารกำกับโปรแกรม
  • ฟอรั่ม
โอเพนซอร์ส
  • ดาวน์โหลด
  • Github
  • Runbot
  • การแปล
บริการ
  • โฮสติ้ง odoo.sh เซิร์ฟเวอร์
  • การสนับสนุน
  • อัปเกรด
  • การพัฒนาที่กำหนดเอง
  • การศึกษา
  • ค้นหานักบัญชี
  • ค้นหาพาร์ทเนอร์
  • ร่วมเป็นพาร์ทเนอร์
เกี่ยวกับเรา
  • บริษัทของเรา
  • ทรัพย์สินในรูปของเครื่องหมายการค้า
  • ติดต่อเรา
  • งาน
  • ระบบการจัดงานอีเวนต์
  • พอดแคสต์
  • บล็อก
  • ลูกค้า
  • กฎหมาย • ความเป็นส่วนตัว
  • ความปลอดภัย
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo เป็นชุดแอปธุรกิจแบบเปิดที่ครอบคลุมทุกความต้องการของบริษัทของคุณ อาธิ CRM eCommerce ระบบบัญชี ระบบสินค้าคงคลัง ระบบการขายหน้าร้าน โปรเจกต์ และ อีกมากมาย

ความเหนือกว่าอันเป็นเอกลักษณ์ของ Odoo คือการใช้งานที่ง่ายดายและผสานการทำงานอย่างสมบูรณ์แบบในเวลาเดียวกัน

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now