[tryton-debian-vcs] tryton-sao branch upstream-4.4 updated. upstream/4.4.6-1-g5b89c8e

Mathias Behrle tryton-debian-vcs at alioth.debian.org
Sun Jan 7 13:02:47 UTC 2018


The following commit has been merged in the upstream-4.4 branch:
https://alioth.debian.org/plugins/scmgit/cgi-bin/gitweb.cgi/?p=tryton/tryton-sao.git;a=commitdiff;h=upstream/4.4.6-1-g5b89c8e

commit 5b89c8e69c3cbb4c83685535d84a4199e79a73e2
Author: Mathias Behrle <mathiasb at m9s.biz>
Date:   Sat Jan 6 11:38:41 2018 +0100

    Adding upstream version 4.4.7.
    
    Signed-off-by: Mathias Behrle <mathiasb at m9s.biz>

diff --git a/CHANGELOG b/CHANGELOG
index ee58b36..24f8c67 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,6 @@
+Version 4.4.7 - 2018-01-04
+* Bug fixes (see mercurial logs for details)
+
 Version 4.4.6 - 2017-12-04
 * Bug fixes (see mercurial logs for details)
 
diff --git a/COPYRIGHT b/COPYRIGHT
index 5182570..b7f4c1a 100644
--- a/COPYRIGHT
+++ b/COPYRIGHT
@@ -1,7 +1,7 @@
 Copyright (C) 2012-2016 Nicolas Évrard.
-Copyright (C) 2012-2017 Cédric Krier.
+Copyright (C) 2012-2018 Cédric Krier.
 Copyright (C) 2012-2014 Bertrand Chenal.
-Copyright (C) 2012-2017 B2CK SPRL.
+Copyright (C) 2012-2018 B2CK SPRL.
 
 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
diff --git a/dist/tryton-sao.js b/dist/tryton-sao.js
index bb97b59..6927ef9 100644
--- a/dist/tryton-sao.js
+++ b/dist/tryton-sao.js
@@ -2799,6 +2799,11 @@ var Sao = {};
                     continue;
                 }
                 value[name] = field.get(this);
+                // Sending an empty x2MField breaks ModelFieldAccess.check
+                if ((field instanceof Sao.field.One2Many) &&
+                        (value[name].length === 0)) {
+                    delete value[name];
+                }
             }
             return value;
         },
diff --git a/dist/tryton-sao.min.js b/dist/tryton-sao.min.js
index 1245549..e0fcb5c 100644
--- a/dist/tryton-sao.min.js
+++ b/dist/tryton-sao.min.js
@@ -1,8 +1,8 @@
-/*! tryton-sao-4.4.6 | GPL-3
+/*! tryton-sao-4.4.7 | GPL-3
 This file is part of Tryton.  The COPYRIGHT file at the top level of
 this repository contains the full copyright notices and license terms. */
 function eval_pyson(value){with(Sao.PYSON.eval)return eval(value)}var Sao={};!function(){"use strict";function a(){var a=1040;jQuery(".modal.in").each(function(b){var c=jQuery(this);a++,c.css("zIndex",a),c.next(".modal-backdrop.in").addClass("hidden").css("zIndex",a-1)}),jQuery(".modal.in:visible:last").focus().next(".modal-backdrop.in").removeClass("hidden")}"contains"in String.prototype||(String.prototype.contains=function(a,b){return-1!==String.prototype.indexOf.call(this,a,b)}),String.prototype.startsWith||Object.defineProperty(String.prototype,"startsWith",{enumerable:!1,configurable:!1,writable:!1,value:function(a,b){return b=b||0,this.indexOf(a,b)===b}}),String.prototype.endsWith||Object.defineProperty(String.prototype,"endsWith",{enumerable:!1,configurable:!1,writable:!1,value:function(a,b){b=b||this.length,b-=a.length;var c=this.lastIndexOf(a);return-1!==c&&c===b}}),Array.prototype.some||(Array.prototype.some=function(a){if(null===this)throw new TypeError;var b,c,d=Object(this),e=d.length>>>0;if("function"!=typeof a)throw new TypeError;for(b=arguments[1],c=0;c<e;c++)if(c in d&&a.call(b,d[c],c,d))return!0;return!1});try{document.execCommand("styleWithCSS",!1,!1)}catch(c){}try{document.execCommand("useCSS",!1,!0)}catch(c){}jQuery.fn.extend({uniqueId:function(){var a=0;return function(){return this.each(function(){this.id||(this.id="ui-id-"+ ++a)})}}()}),Sao.class_=function(a,b){var c=function(){if(!(this instanceof c))throw new Error("Constructor function requires new operator");this.Class=c,this.init&&this.init.apply(this,arguments)};if(c.prototype=Object.create(a.prototype),c._super=a.prototype,b)for(var d in b)c.prototype[d]=b[d];return c},Sao.Decimal=Number,Sao.Date=function(a,b,c){var d=moment();return d.year(a),d.month(b),d.date(c),d.set({hour:0,minute:0,second:0,millisecond:0}),d.isDate=!0,d},Sao.Date.min=moment(new Date(-864e13)),Sao.Date.min.set({hour:0,minute:0,second:0,millisecond:0}),Sao.Date.min.isDate=!0,Sao.Date.max=moment(new Date(864e13)),Sao.Date.max.set({hour:0,minute:0,second:0,millisecond:0}),Sao.Date.max.isDate=!0,Sao.DateTime=function(a,b,c,d,e,f,g,h){var i;return void 0===b?(i=moment(a),a=void 0):i=moment(),h&&i.utc(),i.year(a),i.month(b),i.date(c),void 0!==b&&(i.hour(d||0),i.minute(e||0),i.second(f||0),i.milliseconds(g||0)),i.isDateTime=!0,i.local(),i},Sao.DateTime.combine=function(a,b){var c=a.clone();return c.set({hour:b.hour(),minute:b.minute(),second:b.second(),millisecond:b.millisecond()}),c.isDateTime=!0,c},Sao.DateTime.min=moment(new Date(-864e13)).local(),Sao.DateTime.min.isDateTime=!0,Sao.DateTime.max=moment(new Date(864e13)).local(),Sao.DateTime.max.isDateTime=!0,Sao.Time=function(a,b,c,d){var e=moment({hour:a,minute:b,second:c,millisecond:d||0});return e.isTime=!0,e},Sao.TimeDelta=function(a,b,c,d,e,f){var g=moment.duration({days:a,seconds:b,milliseconds:c,minutes:d,hours:e,weeks:f});return g.isTimeDelta=!0,g},Sao.config={},Sao.config.limit=1e3,Sao.config.display_size=20,Sao.config.roundup={},Sao.config.roundup.url="http://bugs.tryton.org/roundup/",Sao.config.title="Tryton",Sao.i18n=i18n(),Sao.i18n.setlang=function(a){return a||(a=(navigator.language||navigator.browserLanguage||navigator.userLanguage||"en").replace("-","_")),Sao.i18n.setLocale(a),moment.locale(a.slice(0,2)),jQuery.getJSON("locale/"+a+".json",function(b){b[""].language||(b[""].language=a),b[""]["plural-forms"]||(b[""]["plural-forms"]="nplurals=2; plural=(n!=1);");for(var c in b)""!==c&&(b[c]=2==b[c].length?b[c][1]:b[c].slice(1));Sao.i18n.loadJSON(b)})},Sao.i18n.getlang=function(){return Sao.i18n.getLocale()},Sao.i18n.setlang(),Sao.get_preferences=function(){var a=Sao.Session.current_session;return a.reload_context().then(function(){return Sao.rpc({method:"model.res.user.get_preferences",params:[!1,{}]},a).then(function(a){var b=[];return b.push(Sao.common.MODELACCESS.load_models()),b.push(Sao.common.ICONFACTORY.load_icons()),b.push(Sao.common.MODELHISTORY.load_history()),b.push(Sao.common.VIEW_SEARCH.load_searches()),jQuery.when.apply(jQuery,b).then(function(){(a.actions||[]).forEach(function(a){Sao.Action.execute(a,{},null,{})});var b=Sao.config.title;jQuery.isEmptyObject(a.status_bar)||(b+=" - "+a.status_bar),document.title=b;var c=a.language!=Sao.i18n.getLocale(),d=jQuery.Deferred();return Sao.i18n.setlang(a.language).always(function(){c&&Sao.user_menu(a),d.resolve(a)}),d})})})},Sao.login=function(){Sao.Session.get_credentials().then(function(a){return Sao.Session.current_session=a,a.reload_context()}).then(Sao.get_preferences).then(function(a){Sao.menu(a),Sao.user_menu(a)})},Sao.logout=function(){var a=Sao.Session.current_session;Sao.Tab.tabs.close(!0).done(function(){jQuery("#user-preferences").children().remove(),jQuery("#user-logout").children().remove(),jQuery("#user-favorites").children().remove(),jQuery("#menu").children().remove(),document.title=Sao.config.title,a.do_logout().always(Sao.login)})},Sao.preferences=function(){Sao.Tab.tabs.close(!0).done(function(){jQuery("#user-preferences").children().remove(),jQuery("#user-favorites").children().remove(),jQuery("#user-logout").children().remove(),jQuery("#menu").children().remove(),new Sao.Window.Preferences(function(){Sao.get_preferences().then(function(a){Sao.menu(a),Sao.user_menu(a)})})})},Sao.favorites_menu=function(){var a=function(){e&&e.remove()};if(jQuery(window).click(function(){a()}),0!==jQuery("#user-favorites").children(".dropdown-menu").length)a();else{var b=Sao.main_menu_screen.model_name+".favorite",c=Sao.Session.current_session,d={method:"model."+b+".get"},e=jQuery("<ul/>",{class:"dropdown-menu","aria-expanded":"false"});jQuery("#user-favorites").append(e),Sao.rpc(d,c).then(function(b){b.forEach(function(b){var c=jQuery("<a/>",{href:"#"}),d=b[0],f=jQuery("<li/>",{role:"presentation"}),g=jQuery("<img/>",{class:"favorite-icon"});c.append(g),f.append(c),g.attr("src",Sao.common.ICONFACTORY.get_icon_url(b[2])),c.append(b[1]),c.click(function(){a(),Sao.Action.exec_keyword("tree_open",{model:Sao.main_menu_screen.model_name,id:d,ids:[d]})}),e.append(f)}),e.append(jQuery("<li/>",{class:"divider"})),jQuery("<li/>",{role:"presentation"}).append(jQuery("<a/>",{href:"#"}).click(function(){a(),Sao.Tab.create({model:Sao.main_menu_screen.model_name+".favorite",mode:["tree","form"],name:Sao.i18n.gettext("Manage favorites")})}).text(Sao.i18n.gettext("Manage favorites"))).appendTo(e)})}},Sao.user_menu=function(a){jQuery("#user-preferences").children().remove(),jQuery("#user-favorites").children().remove(),jQuery("#user-logout").children().remove(),jQuery("#user-preferences").append(jQuery("<a/>",{href:"#"}).click(Sao.preferences).append(a.status_bar)),jQuery("#user-logout").append(jQuery("<a/>",{href:"#"}).click(Sao.logout).append(Sao.i18n.gettext("Logout"))),jQuery("#user-favorites").append(jQuery("<a/>",{href:"#","data-toggle":"dropdown"}).click(Sao.favorites_menu).append(Sao.i18n.gettext("Favorites")))},Sao.menu=function(a){var c=new Sao.PYSON.Decoder,d=c.decode(a.pyson_menu),e=!1;jQuery.isEmptyObject(d.views)?d.view_id&&(e=[d.view_id[0]]):e=d.views.map(function(a){return a[0]}),c=new Sao.PYSON.Decoder(Sao.Session.current_session.context);var f=c.decode(d.pyson_context||"{}"),g=c.decode(d.pyson_domain),h=new Sao.Tab.Form(d.res_model,{mode:["tree"],view_ids:e,domain:g,context:f,selection_mode:Sao.common.SELECTION_NONE,limit:null});Sao.Tab.tabs.splice(Sao.Tab.tabs.indexOf(h),1),h.view_prm.done(function(){Sao.main_menu_screen=h.screen,h.screen.current_view.table.find("thead").hide(),jQuery("#menu").children().remove();var a=new Sao.GlobalSearch;jQuery("#menu").append(a.el),jQuery("#menu").append(h.screen.screen_container.content_box.detach()),h.screen.views[0].columns.push(new b(h.screen.model.fields.favorite))})},Sao.main_menu_screen=null;var b=Sao.class_(Object,{init:function(a){this.field=a,this.header=jQuery("<th/>"),this.attributes=jQuery.extend({},this.field.description),this.attributes.name=this.field.name},get_cell:function(){return jQuery("<span/>",{tabindex:0})},render:function(a,b){return b||(b=this.get_cell()),a.load(this.field.name).done(function(){if(null!==a._values.favorite){var c="glyphicon glyphicon-star";a._values.favorite||(c+="-empty"),b.addClass(c),b.click({record:a,button:b},this.favorite_click)}}.bind(this)),b},favorite_click:function(a){a.stopImmediatePropagation();var b,c=a.data.button;c.hasClass("glyphicon-star-empty")?(c.removeClass("glyphicon-star-empty"),c.addClass("glyphicon-star"),b="set"):(c.removeClass("glyphicon-star"),c.addClass("glyphicon-star-empty"),b="unset");var d=Sao.main_menu_screen.model_name+".favorite",e=Sao.Session.current_session,f={method:"model."+d+"."+b,params:[a.data.record.id,e.context]};Sao.rpc(f,e)}});Sao.Dialog=Sao.class_(Object,{init:function(a,b,c){c=c||"sm",this.modal=jQuery("<div/>",{class:b+" modal fade",role:"dialog","data-backdrop":"static"}),this.content=jQuery("<form/>",{class:"modal-content"}).appendTo(jQuery("<div/>",{class:"modal-dialog modal-"+c}).appendTo(this.modal)),this.header=jQuery("<div/>",{class:"modal-header"}).appendTo(this.content),a&&this.add_title(a),this.body=jQuery("<div/>",{class:"modal-body"}).appendTo(this.content),this.footer=jQuery("<div/>",{class:"modal-footer"}).appendTo(this.content)},add_title:function(a){this.header.append(jQuery("<h4/>",{class:"modal-title"}).append(a))}}),Sao.GlobalSearch=Sao.class_(Object,{init:function(){this.el=jQuery("<div/>",{class:"global-search-container"}),this.search_entry=jQuery("<input>",{class:"form-control",placeholder:Sao.i18n.gettext("Search...")}),this.el.append(this.search_entry);new Sao.common.InputCompletion(this.search_entry,this.update.bind(this),this.match_selected.bind(this),this.format.bind(this))},format:function(a){var b=jQuery("<div/>"),c=jQuery("<img/>",{class:"global-search-icon"}).appendTo(b);return Sao.common.ICONFACTORY.register_icon(a.icon).then(function(a){c.attr("src",a)}),jQuery("<span/>",{class:"global-search-text"}).text(a.record_name).appendTo(b),b},update:function(a){return new Sao.Model("ir.model").execute("global_search",[a,Sao.config.limit,Sao.main_menu_screen.model_name],Sao.main_menu_screen.context).then(function(a){for(var b=[],c=0,d=a.length;c<d;c++)b.push({model:a[c][1],model_name:a[c][2],record_id:a[c][3],record_name:a[c][4],icon:a[c][5]});return b}.bind(this))},match_selected:function(a){if(a.model==Sao.main_menu_screen.model_name)Sao.Action.exec_keyword("tree_open",{model:a.model,id:a.record_id,ids:[a.record_id]},Sao.main_menu_screen.context);else{var b={model:a.model,res_id:a.record_id,mode:["form","tree"],name:a.model_name};Sao.Tab.create(b)}this.search_entry.val("")}}),jQuery(document).on("show.bs.modal",".modal",function(a){jQuery(this).appendTo(jQuery("body"))}).on("shown.bs.modal",".modal.in",function(b){a()}).on("hidden.bs.modal",".modal",function(b){a()})}(),function(){"use strict";Sao.rpc=function(a,b){var c=jQuery.Deferred();b||(b=new Sao.Session);var d=jQuery.extend([],a.params);d.push(jQuery.extend({},b.context,d.pop()));var e=Sao.common.processing.show(),f=jQuery.ajax({headers:{Authorization:"Session "+b.get_auth()},contentType:"application/json",data:JSON.stringify(Sao.rpc.prepareObject({id:Sao.rpc.id++,method:a.method,params:d})),dataType:"json",url:"/"+(b.database||"")+"/",type:"post",complete:[function(){Sao.common.processing.hide(e)}]}),g=function(d){if(null===d)Sao.common.warning.run("",Sao.i18n.gettext("Unable to reach the server")),c.reject();else if(d.error){var e,f,g;if("UserWarning"==d.error[0])return e=d.error[1][0],f=d.error[1][1],g=d.error[1][2],void Sao.common.userwarning.run(f,g).done(function(d){if(!~["always","ok"].indexOf(d))return void c.reject();Sao.rpc({method:"model.res.user.warning.create",params:[[{user:b.user_id,name:e,always:"always"==d}],{}]},b).done(function(){Sao.rpc(a,b).then(c.resolve,c.reject)})});if("UserError"==d.error[0])return f=d.error[1][0],g=d.error[1][1],void Sao.common.warning.run(g,f).always(c.reject);if("ConcurrencyException"==d.error[0]){if(a.method.startsWith("model.")&&(a.method.endsWith(".write")||a.method.endsWith(".delete"))){var h=a.method.split(".").slice(1,-1).join(".");return void Sao.common.concurrency.run(h,a.params[0][0],a.params.slice(-1)[0]).then(function(){delete a.params.slice(-1)[0]._timestamp,Sao.rpc(a,b).then(c.resolve,c.reject)},c.reject)}return void Sao.common.message.run("Concurrency Exception","glyphicon-alert").always(c.reject)}Sao.common.error.run(d.error[0],d.error[1]),c.reject()}else c.resolve(d.result)},h=function(d,e,f){if(403==d.status)return void Sao.Session.renew(b).then(function(){Sao.rpc(a,b).then(c.resolve,c.reject)},c.reject);Sao.common.error.run(e,f),c.reject()};return f.success(g),f.error(h),c.promise()},Sao.rpc.id=0,Sao.rpc.convertJSONObject=function(a,b,c){if(a instanceof Array)for(var d=0,e=a.length;d<e;d++)Sao.rpc.convertJSONObject(a[d],d,a);else if("string"!=typeof a&&"number"!=typeof a&&null!==a)if(a&&a.__class__){switch(a.__class__){case"datetime":a=Sao.DateTime(a.year,a.month-1,a.day,a.hour,a.minute,a.second,a.microsecond/1e3,!0);break;case"date":a=Sao.Date(a.year,a.month-1,a.day);break;case"time":a=Sao.Time(a.hour,a.minute,a.second,a.microsecond/1e3);break;case"timedelta":a=Sao.TimeDelta(null,a.seconds);break;case"bytes":for(var f=atob(a.base64.replace(/\s/g,"")),g=new ArrayBuffer(f.length),h=new Uint8Array(g),i=0;i<f.length;i++)h[i]=f.charCodeAt(i);a=h;break;case"Decimal":a=new Sao.Decimal(a.decimal)}c&&(c[b]=a)}else for(var j in a)Sao.rpc.convertJSONObject(a[j],j,a);return c||a},Sao.rpc.prepareObject=function(a,b,c){if(a instanceof Array){a=jQuery.extend([],a);for(var d=0,e=a.length;d<e;d++)Sao.rpc.prepareObject(a[d],d,a)}else if("string"!=typeof a&&"number"!=typeof a&&"boolean"!=typeof a&&null!==a&&void 0!==a)if(a.isDate)a={__class__:"date",year:a.year(),month:a.month()+1,day:a.date()};else if(a.isDateTime)a=a.clone(),a={__class__:"datetime",year:a.utc().year(),month:a.utc().month()+1,day:a.utc().date(),hour:a.utc().hour(),minute:a.utc().minute(),second:a.utc().second(),microsecond:1e3*a.utc().millisecond()};else if(a.isTime)a={__class__:"time",hour:a.hour(),minute:a.minute(),second:a.second(),microsecond:1e3*a.millisecond()};else if(a.isTimeDelta)a={__class__:"timedelta",seconds:a.asSeconds()};else if(a instanceof Sao.Decimal)a={__class__:"Decimal",decimal:a.toString()};else if(a instanceof Uint8Array){for(var f=[],g=65535,h=0;h*g<a.length;h++)f.push(String.fromCharCode.apply(null,a.subarray(h*g,(h+1)*g)));a={__class__:"bytes",base64:btoa(f.join(""))}}else{a=jQuery.extend({},a);for(var i in a)Sao.rpc.prepareObject(a[i],i,a)}return c&&(c[b]=a),c||a},jQuery.ajaxSetup({converters:{"text json":function(a){return Sao.rpc.convertJSONObject(jQuery.parseJSON(a))}}})}(),function(){"use strict";Sao.PYSON={},Sao.PYSON.eval={},Sao.PYSON.PYSON=Sao.class_(Object,{init:function(){},pyson:function(){throw"NotImplementedError"},types:function(){throw"NotImplementedError"},toString:function(){return this.pyson().__class__+"("+this.__string_params__().map(function(a){return a instanceof Sao.PYSON.PYSON?a.toString():JSON.stringify(a)}).join(", ")+")"},__string_params__:function(){throw"NotImplementedError"}}),Sao.PYSON.PYSON.eval_=function(a,b){throw"NotImplementedError"},Sao.PYSON.PYSON.init_from_object=function(a){throw"NotImplementedError"},Sao.PYSON.Encoder=Sao.class_(Object,{prepare:function(a,b,c){if(null!==a&&void 0!==a)if(a instanceof Array){a=jQuery.extend([],a);for(var d=0,e=a.length;d<e;d++)this.prepare(a[d],d,a)}else a._isAMomentObject&&(a=a.isDate?new Sao.PYSON.Date(a.year(),a.month()+1,a.date()).pyson():new Sao.PYSON.DateTime(a.year(),a.month()+1,a.date(),a.hours(),a.minutes(),a.seconds(),1e3*a.milliseconds()).pyson());return c&&(c[b]=a),c||a},encode:function(a){return a=this.prepare(a),JSON.stringify(a,function(a,b){return b instanceof Sao.PYSON.PYSON?b.pyson():null===b||void 0===b?null:b})}}),Sao.PYSON.Decoder=Sao.class_(Object,{init:function(a,b){this.__context=a||{},this.noeval=b||!1},decode:function(a){var b=function(a,b){if("object"==typeof b&&null!==b){var c=Sao.PYSON[b.__class__];if(c){if(this.noeval){var d=jQuery.extend({},b);return delete d.__class__,Sao.PYSON[b.__class__].init_from_object(d)}return c.eval_(b,this.__context)}}return b};return JSON.parse(a,b.bind(this))}}),Sao.PYSON.eval.Eval=function(a,b){return new Sao.PYSON.Eval(a,b)},Sao.PYSON.Eval=Sao.class_(Sao.PYSON.PYSON,{init:function(a,b){void 0===b&&(b=""),Sao.PYSON.Eval._super.init.call(this),this._value=a,this._default=b},pyson:function(){return{__class__:"Eval",v:this._value,d:this._default}},types:function(){return this._default instanceof Sao.PYSON.PYSON?this._default.types():[typeof this._default]},__string_params__:function(){return[this._value,this._default]}}),Sao.PYSON.Eval.eval_=function(a,b){return a.v in b?b[a.v]:a.d},Sao.PYSON.Eval.init_from_object=function(a){return new Sao.PYSON.Eval(a.v,a.d)},Sao.PYSON.eval.Not=function(a){return new Sao.PYSON.Not(a)},Sao.PYSON.Not=Sao.class_(Sao.PYSON.PYSON,{init:function(a){if(Sao.PYSON.Not._super.init.call(this),a instanceof Sao.PYSON.PYSON){if(jQuery(a.types()).not(["boolean","object"]).length||jQuery(["boolean"]).not(a.types()).length)throw"value must be boolean"}else if("boolean"!=typeof a)throw"value must be boolean";this._value=a},pyson:function(){return{__class__:"Not",v:this._value}},types:function(){return["boolean"]},__string_params__:function(){return[this._value]}}),Sao.PYSON.Not.eval_=function(a,b){return!a.v},Sao.PYSON.Not.init_from_object=function(a){return new Sao.PYSON.Not(a.v)},Sao.PYSON.eval.Bool=function(a){return new Sao.PYSON.Bool(a)},Sao.PYSON.Bool=Sao.class_(Sao.PYSON.PYSON,{init:function(a){Sao.PYSON.Bool._super.init.call(this),this._value=a},pyson:function(){return{__class__:"Bool",v:this._value}},types:function(){return["boolean"]},__string_params__:function(){return[this._value]}}),Sao.PYSON.Bool.eval_=function(a,b){return moment.isMoment(a.v)&&a.v.isTime?Boolean(a.v.hour()||a.v.minute()||a.v.second()||a.v.millisecond()):moment.isDuration(a.v)?Boolean(a.v.valueOf()):a.v instanceof Number?Boolean(a.v.valueOf()):a.v instanceof Object?!jQuery.isEmptyObject(a.v):Boolean(a.v)},Sao.PYSON.Bool.init_from_object=function(a){return new Sao.PYSON.Bool(a.v)},Sao.PYSON.eval.And=function(a){return new Sao.PYSON.And(a)},Sao.PYSON.And=Sao.class_(Sao.PYSON.PYSON,{init:function(a){void 0===a&&(a=[]),Sao.PYSON.And._super.init.call(this);for(var b=0,c=a.length;b<c;b++){var d=a[b];if(d instanceof Sao.PYSON.PYSON){if(jQuery(d.types()).not(["boolean"]).length||jQuery(["boolean"]).not(d.types()).length)throw"statement must be boolean"}else if("boolean"!=typeof d)throw"statement must be boolean"}if(a.length<2)throw"must have at least 2 statements";this._statements=a},pyson:function(){return{__class__:"And",s:this._statements}},types:function(){return["boolean"]},__string_params__:function(){return this._statements}}),Sao.PYSON.And.eval_=function(a,b){for(var c=!0,d=0,e=a.s.length;d<e;d++){var f=a.s[d];c=c&&f}return c},Sao.PYSON.And.init_from_object=function(a){return new Sao.PYSON.And(a.s)},Sao.PYSON.eval.Or=function(a){return new Sao.PYSON.Or(a)},Sao.PYSON.Or=Sao.class_(Sao.PYSON.And,{pyson:function(){var a=Sao.PYSON.Or._super.pyson.call(this);return a.__class__="Or",a}}),Sao.PYSON.Or.eval_=function(a,b){for(var c=!1,d=0,e=a.s.length;d<e;d++){var f=a.s[d];c=c||f}return c},Sao.PYSON.Or.init_from_object=function(a){return new Sao.PYSON.Or(a.s)},Sao.PYSON.eval.Equal=function(a,b){return new Sao.PYSON.Equal(a,b)},Sao.PYSON.Equal=Sao.class_(Sao.PYSON.PYSON,{init:function(a,b){Sao.PYSON.Equal._super.init.call(this);var c,d;if(c=a instanceof Sao.PYSON.PYSON?a.types():[typeof a],d=b instanceof Sao.PYSON.PYSON?b.types():[typeof b],jQuery(c).not(d).length||jQuery(d).not(c).length)throw"statements must have the same type";this._statement1=a,this._statement2=b},pyson:function(){return{__class__:"Equal",s1:this._statement1,s2:this._statement2}},types:function(){return["boolean"]},__string_params__:function(){return[this._statement1,this._statement2]}}),Sao.PYSON.Equal.eval_=function(a,b){return a.s1 instanceof Array&&a.s2 instanceof Array?Sao.common.compare(a.s1,a.s2):a.s1==a.s2},Sao.PYSON.Equal.init_from_object=function(a){return new Sao.PYSON.Equal(a.s1,a.s2)},Sao.PYSON.eval.Greater=function(a,b,c){return new Sao.PYSON.Greater(a,b,c)},Sao.PYSON.Greater=Sao.class_(Sao.PYSON.PYSON,{init:function(a,b,c){Sao.PYSON.Greater._super.init.call(this);for(var d=[a,b],e=0;e<2;e++){var f=d[e];if(f instanceof Sao.PYSON.PYSON){if(jQuery(f).not(["number"]).length)throw"statement must be an integer or a float"}else if(!~["number","object"].indexOf(typeof f))throw"statement must be an integer or a float"}if(void 0===c&&(c=!1),c instanceof Sao.PYSON.PYSON){if(jQuery(c.types()).not(["boolean"]).length||jQuery(["boolean"]).not(c.types()).length)throw"equal must be boolean"}else if("boolean"!=typeof c)throw"equal must be boolean";this._statement1=a,this._statement2=b,this._equal=c},pyson:function(){return{__class__:"Greater",s1:this._statement1,s2:this._statement2,e:this._equal}},types:function(){return["boolean"]},__string_params__:function(){return[this._statement1,this._statement2,this._equal]}}),Sao.PYSON.Greater._convert=function(a){return a=jQuery.extend({},a),a.s1=Number(a.s1),a.s2=Number(a.s2),a},Sao.PYSON.Greater.eval_=function(a,b){return a=Sao.PYSON.Greater._convert(a),a.e?a.s1>=a.s2:a.s1>a.s2},Sao.PYSON.Greater.init_from_object=function(a){return new Sao.PYSON.Greater(a.s1,a.s2,a.e)},Sao.PYSON.eval.Less=function(a,b,c){return new Sao.PYSON.Less(a,b,c)},Sao.PYSON.Less=Sao.class_(Sao.PYSON.Greater,{pyson:function(){var a=Sao.PYSON.Less._super.pyson.call(this);return a.__class__="Less",a}}),Sao.PYSON.Less._convert=Sao.PYSON.Greater._convert,Sao.PYSON.Less.eval_=function(a,b){return a=Sao.PYSON.Less._convert(a),a.e?a.s1<=a.s2:a.s1<a.s2},Sao.PYSON.Less.init_from_object=function(a){return new Sao.PYSON.Less(a.s1,a.s2,a.e)},Sao.PYSON.eval.If=function(a,b,c){return new Sao.PYSON.If(a,b,c)},Sao.PYSON.If=Sao.class_(Sao.PYSON.PYSON,{init:function(a,b,c){if(Sao.PYSON.If._super.init.call(this),a instanceof Sao.PYSON.PYSON){if(jQuery(a.types()).not(["boolean"]).length||jQuery(["boolean"]).not(a.types()).length)throw"condition must be boolean"}else if("boolean"!=typeof a)throw"condition must be boolean";var d,e;if(d=b instanceof Sao.PYSON.PYSON?b.types():[typeof b],void 0===c&&(c=null),e=c instanceof Sao.PYSON.PYSON?c.types():[typeof c],jQuery(d).not(e).length||jQuery(e).not(d).length)throw"then and else statements must be the same type";this._condition=a,this._then_statement=b,this._else_statement=c},pyson:function(){return{__class__:"If",c:this._condition,t:this._then_statement,e:this._else_statement}},types:function(){return this._then_statement instanceof Sao.PYSON.PYSON?this._then_statement.types():[typeof this._then_statement]},__string_params__:function(){return[this._condition,this._then_statement,this._else_statement]}}),Sao.PYSON.If.eval_=function(a,b){return a.c?a.t:a.e},Sao.PYSON.If.init_from_object=function(a){return new Sao.PYSON.If(a.c,a.t,a.e)},Sao.PYSON.eval.Get=function(a,b,c){return new Sao.PYSON.Get(a,b,c)},Sao.PYSON.Get=Sao.class_(Sao.PYSON.PYSON,{init:function(a,b,c){if(Sao.PYSON.Get._super.init.call(this),void 0===c&&(c=null),a instanceof Sao.PYSON.PYSON){if(jQuery(a.types()).not(["object"]).length||jQuery(["object"]).not(a.types()).length)throw"obj must be a dict"}else if(!(a instanceof Object))throw"obj must be a dict";if(this._obj=a,b instanceof Sao.PYSON.PYSON){if(jQuery(b.types()).not(["string"]).length||jQuery(["string"]).not(b.types()).length)throw"key must be a string"}else if("string"!=typeof b)throw"key must be a string";this._key=b,this._default=c},pyson:function(){return{__class__:"Get",v:this._obj,k:this._key,d:this._default}},types:function(){return this._default instanceof Sao.PYSON.PYSON?this._default.types():[typeof this._default]},__string_params__:function(){return[this._obj,this._key,this._default]}}),Sao.PYSON.Get.eval_=function(a,b){return a.k in a.v?a.v[a.k]:a.d},Sao.PYSON.Get.init_from_object=function(a){return new Sao.PYSON.Get(a.v,a.k,a.d)},Sao.PYSON.eval.In=function(a,b){return new Sao.PYSON.In(a,b)},Sao.PYSON.In=Sao.class_(Sao.PYSON.PYSON,{init:function(a,b){if(Sao.PYSON.In._super.init.call(this),a instanceof Sao.PYSON.PYSON){if(jQuery(a.types()).not(["string","number"]).length)throw"key must be a string or a number"}else if(!~["string","number"].indexOf(typeof a))throw"key must be a string or a number";if(b instanceof Sao.PYSON.PYSON){if(jQuery(b.types()).not(["object"]).length||jQuery(["object"]).not(b.types()).length)throw"obj must be a dict or a list"}else if(!(b instanceof Object))throw"obj must be a dict or a list";this._key=a,this._obj=b},pyson:function(){return{__class__:"In",k:this._key,v:this._obj}},types:function(){return["boolean"]},__string_params__:function(){return[this._key,this._obj]}}),Sao.PYSON.In.eval_=function(a,b){return a.v.indexOf?Boolean(~a.v.indexOf(a.k)):!!a.v[a.k]},Sao.PYSON.In.init_from_object=function(a){return new Sao.PYSON.In(a.k,a.v)},Sao.PYSON.eval.Date=function(a,b,c,d,e,f){return new Sao.PYSON.Date(a,b,c,d,e,f)},Sao.PYSON.Date=Sao.class_(Sao.PYSON.PYSON,{init:function(a,b,c,d,e,f){Sao.PYSON.Date._super.init.call(this),void 0===a&&(a=null),void 0===b&&(b=null),void 0===c&&(c=null),void 0===d&&(d=0),void 0===e&&(e=0),void 0===f&&(f=0),this._test(a,"year"),this._test(b,"month"),this._test(c,"day"),this._test(d,"delta_years"),this._test(f,"delta_days"),this._test(e,"delta_months"),this._year=a,this._month=b,this._day=c,this._delta_years=d,this._delta_months=e,this._delta_days=f},pyson:function(){return{__class__:"Date",y:this._year,M:this._month,d:this._day,dy:this._delta_years,dM:this._delta_months,dd:this._delta_days}},types:function(){return["object"]},_test:function(a,b){if(a instanceof Sao.PYSON.PYSON){if(jQuery(a.types()).not(["number","object"]).length)throw b+" must be an integer or None"}else if("number"!=typeof a&&null!==a)throw b+" must be an integer or None"},__string_params__:function(){return[this._year,this._month,this._day,this._delta_years,this._delta_months,this._delta_days]}}),Sao.PYSON.Date.eval_=function(a,b){var c=Sao.Date(a.y,a.M&&a.M-1,a.d);return a.dy&&c.add(a.dy,"y"),a.dM&&c.add(a.dM,"M"),a.dd&&c.add(a.dd,"d"),c},Sao.PYSON.Date.init_from_object=function(a){return new Sao.PYSON.Date(a.y,a.M,a.d,a.dy,a.dM,a.dd)},Sao.PYSON.eval.DateTime=function(a,b,c,d,e,f,g,h,i,j,k,l,m,n){return new Sao.PYSON.DateTime(a,b,c,d,e,f,g,h,i,j,k,l,m,n)},Sao.PYSON.DateTime=Sao.class_(Sao.PYSON.Date,{init:function(a,b,c,d,e,f,g,h,i,j,k,l,m,n){Sao.PYSON.DateTime._super.init.call(this,a,b,c,h,i,j),void 0===d&&(d=null),void 0===e&&(e=null),void 0===f&&(f=null),void 0===g&&(g=null),void 0===k&&(k=0),void 0===l&&(l=0),void 0===m&&(m=0),void 0===n&&(n=0),this._test(d,"hour"),this._test(e,"minute"),this._test(f,"second"),this._test(g,"microsecond"),this._test(k,"delta_hours"),this._test(l,"delta_minutes"),this._test(m,"delta_seconds"),this._test(n,"delta_microseconds"),this._hour=d,this._minute=e,this._second=f,this._microsecond=g,this._delta_hours=k,this._delta_minutes=l,this._delta_seconds=m,this._delta_microseconds=n},pyson:function(){var a=Sao.PYSON.DateTime._super.pyson.call(this);return a.__class__="DateTime",a.h=this._hour,a.m=this._minute,a.s=this._second,a.ms=this._microsecond,a.dh=this._delta_hours,a.dm=this._delta_minutes,a.ds=this._delta_seconds,a.dms=this._delta_microseconds,a},__string_params__:function(){var a=Sao.PYSON.DateTime._super.__string_params__.call(this);return[a[0],a[1],a[2],this._hour,this._minute,this._second,this._microsecond,a[3],a[4],a[5],this._delta_hours,this._delta_minutes,this._delta_seconds,this._delta_microseconds]}}),Sao.PYSON.DateTime.eval_=function(a,b){var c=Sao.DateTime(a.y,a.M&&a.M-1,a.d,a.h,a.m,a.s,a.ms&&a.ms/1e3);return a.dy&&c.add(a.dy,"y"),a.dM&&c.add(a.dM,"M"),a.dd&&c.add(a.dd,"d"),a.dh&&c.add(a.dh,"h"),a.dm&&c.add(a.dm,"m"),a.ds&&c.add(a.ds,"s"),a.dms&&c.add(a.dms/1e3,"ms"),c},Sao.PYSON.DateTime.init_from_object=function(a){return new Sao.PYSON.DateTime(a.y,a.M,a.d,a.h,a.m,a.s,a.ms,a.dy,a.dM,a.dd,a.dh,a.dm,a.ds,a.dms)},Sao.PYSON.eval.Len=function(a){return new Sao.PYSON.Len(a)},Sao.PYSON.Len=Sao.class_(Sao.PYSON.PYSON,{init:function(a){if(Sao.PYSON.Len._super.init.call(this),a instanceof Sao.PYSON.PYSON){if(jQuery(a.types()).not(["object","string"]).length||jQuery(["object","string"]).not(a.types()).length)throw"value must be an object or a string"}else if("object"!=typeof a&&"string"!=typeof a)throw"value must be an object or a string";this._value=a},pyson:function(){return{__class__:"Len",v:this._value}},types:function(){return["integer"]},__string_params__:function(){return[this._value]}}),Sao.PYSON.Len.eval_=function(a,b){return"object"==typeof a.v?Object.keys(a.v).length:a.v.length},Sao.PYSON.Len.init_from_object=function(a){return new Sao.PYSON.Len(a.v)}}(),function(){"use strict";function a(a){return window.btoa(unescape(encodeURIComponent(a)))}Sao.Session=Sao.class_(Object,{init:function(a,b){this.user_id=null,this.session=null,this.prm=jQuery.when(),this.database=a,this.login=b,this.context={},Sao.Session.current_session||(Sao.Session.current_session=this)},get_auth:function(){return a(this.login+":"+this.user_id+":"+this.session)},do_login:function(a,b){var c=jQuery.Deferred(),d=function(b){return{method:"common.db.login",params:[a,b,Sao.i18n.getlang()]}};return new Sao.Login(d,this).run().then(function(a){this.user_id=a[0],this.session=a[1],c.resolve()}.bind(this),function(){this.user_id=null,this.session=null,c.reject()}),c.promise()},do_logout:function(){if(!this.user_id||!this.session)return jQuery.when();var a={id:0,method:"common.db.logout",params:[]},b=jQuery.ajax({headers:{Authorization:"Session "+this.get_auth()},contentType:"application/json",data:JSON.stringify(a),dataType:"json",url:"/"+this.database+"/",type:"post"});return this.database=null,this.login=null,this.user_id=null,this.session=null,Sao.Session.current_session===this&&(Sao.Session.current_session=null),b},reload_context:function(){var a={method:"model.res.user.get_preferences",params:[!0,{}]},b=jQuery.extend({},this);return b.context={},Sao.rpc(a,b).then(function(a){this.context=a}.bind(this))}}),Sao.Session.login_dialog=function(){var a=new Sao.Dialog(Sao.i18n.gettext("Login"),"lg");return a.database_select=jQuery("<select/>",{class:"form-control",id:"login-database"}).hide(),a.database_input=jQuery("<input/>",{class:"form-control",id:"login-database"}).hide(),a.login_input=jQuery("<input/>",{class:"form-control",id:"login-login",placeholder:Sao.i18n.gettext("User name")}),a.body.append(jQuery("<div/>",{class:"form-group"}).append(jQuery("<label/>",{class:"control-label",for:"login-database"}).append(Sao.i18n.gettext("Database"))).append(a.database_select).append(a.database_input)).append(jQuery("<div/>",{class:"form-group"}).append(jQuery("<label/>",{class:"control-label",for:"login-login"}).append(Sao.i18n.gettext("User name"))).append(a.login_input)),a.button=jQuery("<button/>",{class:"btn btn-primary",type:"submit"}).append(Sao.i18n.gettext("Login")).appendTo(a.footer),a},Sao.Session.get_credentials=function(){var a=jQuery.Deferred(),b=window.location.hash.replace(/^(#(!|))/,"")||null,c=Sao.Session.login_dialog(),d=function(){return c.modal.find("input,select").filter(":visible").filter(function(){return!jQuery(this).val()})},e=function(){var b=c.login_input.val(),e=e||c.database_select.val()||c.database_input.val();if(c.modal.find(".has-error").removeClass("has-error"),!b||!e)return void d().closest(".form-group").addClass("has-error");c.button.focus(),c.button.prop("disabled",!0),c.modal.modal("hide");var f=new Sao.Session(e,b);f.do_login(b).then(function(){a.resolve(f),c.modal.remove()},function(){c.button.prop("disabled",!1),c.modal.modal("show"),d().closest(".form-group").addClass("has-error"),d().first().focus()})};return c.modal.modal({backdrop:!1,keyboard:!1}),c.modal.find("form").unbind().submit(function(a){e(),a.preventDefault()}),
-jQuery.when(Sao.DB.list()).then(function(a){var e;a=a||[],a.length<=1?(b=a[0],e=c.database_input):(e=c.database_select,a.forEach(function(a){e.append(jQuery("<option/>",{value:a,text:a}))})),e.prop("readonly",1==a.length),e.show(),e.val(b||""),d().first().focus()}),a.promise()},Sao.Session.renew=function(a){if("pending"==a.prm.state())return a.prm;var b=jQuery.Deferred();return a.prm=b.promise(),a.login?(a.do_login(a.login).then(b.resolve,b.reject),a.prm):(b.reject(),a.prm)},Sao.Session.current_session=null,Sao.Login=Sao.class_(Object,{init:function(a,b){this.func=a,this.session=b||Sao.Session.current_session},run:function(a){void 0===a&&(a={});var b=jQuery.Deferred(),c=Sao.common.processing.show(),d=this.func(a);d.id=0;var e={contentType:"application/json",data:JSON.stringify(d),dataType:"json",url:"/"+this.session.database+"/",type:"post",complete:[function(){Sao.common.processing.hide(c)}]};this.session.user_id&&this.session.session&&(e.headers={Authorization:"Session "+this.session.get_auth()});var f=jQuery.ajax(e),g=function(c){if(null===c)Sao.common.warning.run("",Sao.i18n.gettext("Unable to reach the server.")),b.reject();else if(c.error){if(c.error[0].startsWith("403"))return this.run({}).then(b.resolve,b.reject);if(c.error[0].startsWith("404"))b.reject();else if("LoginException"!=c.error[0])Sao.common.error.run(c.error[0],c.error[1]),b.reject();else{var d=c.error[1],e=d[0],f=d[1],g=d[2];this["get_"+g](f).then(function(c){return a[e]=c,this.run(a).then(b.resolve,b.reject)}.bind(this),b.reject)}}else b.resolve(c.result)};return f.success(g.bind(this)),f.error(b.reject),b.promise()},get_char:function(a){return Sao.common.ask.run(a)},get_password:function(a){return Sao.common.ask.run(a,!1)}}),Sao.DB={},Sao.DB.list=function(){var a=Sao.common.processing.show();return jQuery.ajax({contentType:"application/json",data:JSON.stringify({id:0,method:"common.db.list",params:[]}),dataType:"json",url:"/",type:"post",complete:[function(){Sao.common.processing.hide(a)}]}).then(function(a){return a.result})}}(),function(){"use strict";Sao.Model=Sao.class_(Object,{init:function(a,b){b=b||{},this.name=a,this.session=Sao.Session.current_session,this.fields={}},add_fields:function(a){var b=[];for(var c in a)if(a.hasOwnProperty(c)&&!(c in this.fields)){var d=a[c],e=Sao.field.get(d.type);this.fields[c]=new e(d),b.push(c)}return b},execute:function(a,b,c){void 0===c&&(c={});var d={method:"model."+this.name+"."+a,params:b.concat(c)};return Sao.rpc(d,this.session)},find:function(a,b,c,d,e){b||(b=0);var f=this,g=this.execute("search",[a,b,c,d],e),h=function(a){return Sao.Group(f,e,a.map(function(a){return new Sao.Record(f,a)}))};return g.pipe(h)},delete_:function(a){if(jQuery.isEmptyObject(a))return jQuery.when();var b=a[0],c=b.group.root_group();console.assert(a.every(function(a){return a.model.name==b.model.name}),"records not from the same model"),console.assert(a.every(function(a){return a.group.root_group()==b.group.root_group()}),"records not from the same root group"),a=a.filter(function(a){return a.id>=0});var d={};d._timestamp={},a.forEach(function(a){jQuery.extend(d._timestamp,a.get_timestamp())});var e=a.map(function(a){return a.id});return c.on_write_ids(e).then(function(a){return a=a.filter(function(a){return!~e.indexOf(a)}),this.execute("delete",[e],d).then(function(){c.reload(a)})}.bind(this))},copy:function(a,b){if(jQuery.isEmptyObject(a))return jQuery.when();var c=a.map(function(a){return a.id});return this.execute("copy",[c,{}],b)}}),Sao.Group=function(a,b,c){return c.prm=jQuery.when(),c.model=a,c._context=b,c.on_write=[],c.parent=void 0,c.screens=[],c.parent_name="",c.children=[],c.child_name="",c.parent_datetime_field=void 0,c.record_removed=[],c.record_deleted=[],c.__readonly=!1,c.skip_model_access=!1,c.forEach(function(a,b,c){a.group=c}),c.get_readonly=function(){var a=Sao.common.MODELACCESS.get(this.model.name);return!(!this.context._datetime&&(a.write||a.create||this.skip_model_access))||this.__readonly},c.set_readonly=function(a){this.__readonly=a},c.load=function(a,b){var c,d,e=[];for(c=0,d=a.length;c<d;c++){var f=a[c],g=this.get(f);g||(g=new Sao.Record(this.model,f),g.group=this,this.push(g)),e.push(g)}var h,i=[];for(c=0,d=this.record_removed.length;c<d;c++)h=this.record_removed[c],~a.indexOf(h.id)||i.push(h);this.record_removed=i;var j=[];for(c=0,d=this.record_deleted.length;c<d;c++)h=this.record_deleted[c],~a.indexOf(h.id)||j.push(h);if(this.record_deleted=j,e.length&&b){var k=this.root_group();this.changed().then(function(){k.screens.forEach(function(a){a.display()})})}},c.get=function(a){for(var b=0,c=this.length;b<c;b++){var d=this[b];if(d.id==a)return d}},c.new_=function(a,b,c){var d=new Sao.Record(this.model,b);return d.group=this,a&&d.default_get(c),d},c.add=function(a,b,c){void 0!==b&&-1!=b||(b=this.length),void 0===c&&(c=!0),a.group!=this&&(a.group=this),this.splice(b,0,a);for(var d in this.record_removed)d.id==a.id&&this.record_removed.splice(this.record_removed.indexOf(d),1);for(var e in this.record_deleted)e.id==a.id&&this.record_deleted.splice(this.record_deleted.indexOf(e),1);if(a._changed.id=!0,c&&(this.changed(),this.parent&&this.model.fields[this.parent_name])){var f=this.model.fields[this.parent_name];if(f instanceof Sao.field.Many2One||f instanceof Sao.field.Reference){var g=[this.parent.id,""];f instanceof Sao.field.Reference&&(g=[this.parent.model.name,g]),f.set_client(a,g)}}return a},c.remove=function(a,b,c,d){void 0===c&&(c=!0);this.indexOf(a);a.id>=0&&(b?(~this.record_deleted.indexOf(a)&&this.record_deleted.splice(this.record_deleted.indexOf(a),1),this.record_removed.push(a)):(~this.record_removed.indexOf(a)&&this.record_removed.splice(this.record_removed.indexOf(a),1),this.record_deleted.push(a))),a.group.parent&&(a.group.parent._changed.id=!0),c&&(a._changed.id=!0),(a.id<0||d)&&this._remove(a),a.group.changed()},c._remove=function(a){var b=this.indexOf(a);this.splice(b,1)},c.unremove=function(a){this.record_removed.splice(this.record_removed.indexOf(a),1),this.record_deleted.splice(this.record_deleted.indexOf(a),1),a.group.changed()},c.changed=function(){if(!this.parent)return jQuery.when.apply(jQuery,this.screens.map(function(a){return a.display()}));this.parent._changed[this.child_name]=!0;var a=this.parent.model.fields[this.child_name].changed(this.parent);return a||(a=jQuery.when()),a.then(function(){this.parent.validate(null,!0).done(function(){return this.parent.group.changed()}.bind(this))}.bind(this))},c.root_group=function(){for(var a=this,b=this.parent;b;)a=b.group,b=b.parent;return a},c.save=function(){var a=[];return this.forEach(function(b){a.push(b.save())}),jQuery.isEmptyObject(this.record_deleted)||(this.record_deleted.forEach(function(a){this._remove(a)}.bind(this)),a.push(this.model.delete_(this.record_deleted)),this.record_deleted.splice(0,this.record_deleted.length)),jQuery.when.apply(jQuery,a)},c.written=function(a){return"number"==typeof a&&(a=[a]),this.on_write_ids(a).then(function(b){b=b.filter(function(b){return!~a.indexOf(b)}),this.root_group().reload(b)}.bind(this))},c.reload=function(a){this.children.forEach(function(b){b.reload(a)}),a.forEach(function(a){var b=this.get(a);b&&jQuery.isEmptyObject(b._changed)&&b.cancel()}.bind(this))},c.on_write_ids=function(a){var b=[],c=[];return this.on_write.forEach(function(d){var e=this.model.execute(d,[a],this._context).then(function(a){jQuery.extend(c,a)});b.push(e)}.bind(this)),jQuery.when.apply(jQuery,b).then(function(){return c.filter(function(a,b,c){return b==c.indexOf(a)})})},c.set_parent=function(a){this.parent=a,a&&a.model.name==this.model.name&&this.parent.group.children.push(this)},c.add_fields=function(a){var b=this.model.add_fields(a);if(!jQuery.isEmptyObject(this)){var c=[];this.forEach(function(a){a.id<0&&c.push(a)}),c.length&&b.length&&this.model.execute("default_get",[b,this.context()]).then(function(a){c.forEach(function(b){b.set_default(a)})})}},c.destroy=function(){if(this.parent){var a=this.parent.group.children.indexOf(this);~a&&this.parent.group.children.splice(a,1)}this.parent=null},c.domain=function(){var a=[];if(this.screens.forEach(function(b){b.attributes.domain&&a.push(b.attributes.domain)}),this.parent&&this.child_name){var b=this.parent.model.fields[this.child_name];return[a,b.get_domain(this.parent)]}return a},c.context=function(){var a=jQuery.extend({},this._context);if(this.parent&&(jQuery.extend(a,this.parent.get_context()),this.child_name in this.parent.model.fields)){var b=this.parent.model.fields[this.child_name];jQuery.extend(a,b.get_context(this.parent))}return jQuery.extend(a,this._context),this.parent_datetime_field&&(a._datetime=this.parent.get_eval()[this.parent_datetime_field]),a},c.set_context=function(a){this._context=jQuery.extend({},a)},c.clean4inversion=function(a){if(jQuery.isEmptyObject(a))return[];var b=new Sao.common.DomainInversion,c=a[0],d=a.slice(1);if(~["AND","OR"].indexOf(c));else if(b.is_leaf(c)){var e=c[0];e in this.model.fields&&this.model.fields[e].description.readonly&&(c=[])}else c=this.clean4inversion(c);return[c].concat(this.clean4inversion(d))},c.domain4inversion=function(){var a=this.domain();return this.__domain4inversion&&Sao.common.compare(this.__domain4inversion[0],a)||(this.__domain4inversion=[a,this.clean4inversion(a)]),this.__domain4inversion[1]},c.get_by_path=function(a){a=jQuery.extend([],a);var b=null,c=this,d=function(){if(jQuery.isEmptyObject(a))return b;var e=a[0][0],f=a[0][1];return a.splice(0,1),b=c.get(f),b?e?b.load(e).then(function(){return c=b._values[e],c?d():null}):d():null};return jQuery.when().then(d)},c.sort=function(a){var b={};this.forEach(function(a){b[a.id]=a}),a.forEach(function(a,c){this[c]=b[a.id]}.bind(this))},c},Sao.Record=Sao.class_(Object,{id_counter:-1,init:function(a,b){this.model=a,this.group=Sao.Group(a,{},[]),this.id=void 0===b||null===b?Sao.Record.prototype.id_counter:b,this.id<0&&Sao.Record.prototype.id_counter--,this._values={},this._changed={},this._loaded={},this.fields={},this._timestamp=null,this.attachment_count=-1,this.unread_note=-1,this.button_clicks={},this.state_attrs={},this.autocompletion={},this.exception=!1},has_changed:function(){return!jQuery.isEmptyObject(this._changed)},save:function(a){void 0===a&&(a=!1);var b=this.get_context(),c=jQuery.when(),d=this.get();if(this.id<0||!jQuery.isEmptyObject(d)){if(this.id<0){c=this.model.execute("create",[[d]],b);var e=function(a){this.id=a[0]};c.done(e.bind(this))}else jQuery.isEmptyObject(d)||(b._timestamp=this.get_timestamp(),c=this.model.execute("write",[[this.id],d],b));c=c.done(function(){if(this.cancel(),a)return this.reload()}.bind(this)),this.group&&(c=c.done(function(){return this.group.written(this.id)}.bind(this)))}return this.group.parent&&(delete this.group.parent._changed[this.group.child_name],c=c.done(function(){return this.group.parent.save(a)}.bind(this))),c},reload:function(a){if(this.id<0)return jQuery.when();if(a){var b=a.map(function(a){return this.load(a)}.bind(this));return jQuery.when.apply(jQuery,b)}return this.load("*")},load:function(a){var b,c;if(this.id<0||a in this._loaded)return jQuery.when();if("pending"==this.group.prm.state())return c=jQuery.Deferred(),this.group.prm.then(function(){this.load(a).then(c.resolve,c.reject)}.bind(this)),c;var d={};d[this.id]=this;var e;if("*"==a){e="eager";for(b in this.model.fields)if(this.model.fields.hasOwnProperty(b)){var f=this.model.fields[b].description.loading||"eager";if("eager"!=f){e="lazy";break}}}else e=this.model.fields[a].description.loading||"eager";var g=[];if("eager"==e)for(b in this.model.fields)this.model.fields.hasOwnProperty(b)&&"eager"==(this.model.fields[b].description.loading||"eager")&&g.push(b);else g=Object.keys(this.model.fields);g=g.filter(function(a,b,c){return!(a in this._loaded)}.bind(this));var h=g.slice(),i=["many2one","one2one","reference"];for(var j in g){b=g[j];var k=this.model.fields[b].description;~i.indexOf(k.type)&&h.push(b+".rec_name")}~g.indexOf("rec_name")||h.push("rec_name"),h.push("_timestamp");var l=jQuery.extend({},this.get_context());if("eager"==e){var m,n,o=parseInt(Sao.config.limit/h.length,10),p=function(b){return!(a in b._loaded)&&b.id>=0},q=function(a){return p(a)&&void 0===d[a.id]&&(a.group===this.group||JSON.stringify(a.get_context())===JSON.stringify(l))}.bind(this);this.group.parent&&this.group.parent.model.name==this.model.name?(m=[],m=m.concat.apply(m,this.group.parent.group.children),n=q):(m=this.group,n=p);var r=m.indexOf(this);if(~r)for(var s=m.length,t=1;Object.keys(d).length<o&&(r-t>=0||r+t<s)&&t<2*o;){var u;r-t>=0&&(u=m[r-t],n(u)&&(d[u.id]=u)),r+t<s&&(u=m[r+t],n(u)&&(d[u.id]=u)),t++}}for(b in this.model.fields)this.model.fields.hasOwnProperty(b)&&"binary"==this.model.fields[b].description.type&&~h.indexOf(b,h)&&(l[this.model.name+"."+b]="size");c=this.model.execute("read",[Object.keys(d).map(function(a){return parseInt(a,10)}),h],l);var v=function(a,b){void 0===b&&(b=!1);var c={},e=[];a.forEach(function(a,b,d){c[a.id]=a});for(var f in d)if(d.hasOwnProperty(f)){var g=d[f];g.exception||(g.exception=b);var h=c[f];if(g&&h){for(var i in this._changed)this._changed.hasOwnProperty(i)&&delete h[i];e.push(g.set(h))}}return jQuery.when.apply(jQuery,e)}.bind(this),w=function(){var a,b=[];for(var c in d){a={id:c};for(var e in h)a[h[e]]=null;b.push(a)}return v(b,!0)};return this.group.prm=c.then(v,w),this.group.prm},set:function(a,b){void 0===b&&(b=!0);var c,d,e={},f=[];for(c in a)if(a.hasOwnProperty(c))if(d=a[c],"_timestamp"!=c)if(c in this.model.fields){if(this.model.fields[c]instanceof Sao.field.One2Many&&(e[c]=d),this.model.fields[c]instanceof Sao.field.Many2One||this.model.fields[c]instanceof Sao.field.Reference){var g=c+".rec_name";a.hasOwnProperty(g)?this._values[g]=a[g]:this._values.hasOwnProperty(g)&&delete this._values[g]}this.model.fields[c].set(this,d),this._loaded[c]=!0,f.push(c)}else"rec_name"==c&&(this._values[c]=d);else this._timestamp||(this._timestamp=d);for(c in e)d=e[c],this.model.fields[c].set(this,d),this._loaded[c]=!0;return b?this.validate(f,!0):jQuery.when()},get:function(){var a={};for(var b in this.model.fields)if(this.model.fields.hasOwnProperty(b)){var c=this.model.fields[b];(!c.description.readonly||c instanceof Sao.field.One2Many)&&(void 0===this._changed[b]&&this.id>=0||(a[b]=c.get(this)))}return a},invalid_fields:function(){var a={};for(var b in this.model.fields){var c=this.model.fields[b],d=c.get_state_attrs(this).invalid;d&&(a[b]=d)}return a},get_context:function(){return this.group.context()},field_get:function(a){return this.model.fields[a].get(this)},field_set:function(a,b){this.model.fields[a].set(this,b)},field_get_client:function(a){return this.model.fields[a].get_client(this)},field_set_client:function(a,b,c){this.model.fields[a].set_client(this,b,c)},default_get:function(a){if(!jQuery.isEmptyObject(this.model.fields)){var b=this.get_context();void 0===b.default_rec_name&&(b.default_rec_name=a);return this.model.execute("default_get",[Object.keys(this.model.fields)],b).then(function(a){if(this.group.parent&&this.group.parent_name in this.group.model.fields){var b=this.group.model.fields[this.group.parent_name];b instanceof Sao.field.Reference?a[this.group.parent_name]=[this.group.parent.model.name,this.group.parent.id]:b.description.relation==this.group.parent.model.name&&(a[this.group.parent_name]=this.group.parent.id)}return this.set_default(a)}.bind(this))}return jQuery.when()},set_default:function(a,b){void 0===b&&(b=!0);var c=[],d=[];for(var e in a)if(a.hasOwnProperty(e)){var f=a[e];if(e in this.model.fields){if(this.model.fields[e]instanceof Sao.field.Many2One||this.model.fields[e]instanceof Sao.field.Reference){var g=e+".rec_name";a.hasOwnProperty(g)?this._values[g]=a[g]:this._values.hasOwnProperty(g)&&delete this._values[g]}c.push(this.model.fields[e].set_default(this,f)),this._loaded[e]=!0,d.push(e)}}return jQuery.when.apply(jQuery,c).then(function(){return this.on_change(d).then(function(){return this.on_change_with(d).then(function(){var a=function(){return this.group.root_group().screens.forEach(function(a){return a.display()})}.bind(this);return b?this.validate(null,!0).then(a):a()}.bind(this))}.bind(this))}.bind(this))},get_timestamp:function(){var a={};a[this.model.name+","+this.id]=this._timestamp;for(var b in this.model.fields)this.model.fields.hasOwnProperty(b)&&b in this._loaded&&jQuery.extend(a,this.model.fields[b].get_timestamp(this));return a},get_eval:function(){var a={};for(var b in this.model.fields)!this.model.fields.hasOwnProperty(b)&&this.id>=0||(a[b]=this.model.fields[b].get_eval(this));return a.id=this.id,a},get_on_change_value:function(a){var b={};for(var c in this.model.fields)a&&~a.indexOf(c)||(!(this.id>=0)||this._loaded[c]&&this._changed[c])&&(b[c]=this.model.fields[c].get_on_change_value(this));return b.id=this.id,b},_get_on_change_args:function(a){var b={},c=Sao.common.EvalEnvironment(this,"on_change");return a.forEach(function(a){var d=c;a.split(".").forEach(function(a){void 0!==d&&(d=d[a])}),b[a]=d}),b.id=this.id,b},on_change:function(a){var b={};return a.forEach(function(a){var c=this.model.fields[a].description.on_change;jQuery.isEmptyObject(c)||(b=jQuery.extend(b,this._get_on_change_args(c)))}.bind(this)),jQuery.isEmptyObject(b)?jQuery.when():this.model.execute("on_change",[b,a],this.get_context()).then(function(a){a.forEach(this.set_on_change.bind(this))}.bind(this))},on_change_with:function(a){var b,c,d={},e={},f={};for(b in this.model.fields)if(this.model.fields.hasOwnProperty(b)&&(c=this.model.fields[b].description.on_change_with,!jQuery.isEmptyObject(c))){for(var g=0;g<a.length&&!~c.indexOf(a[g]);g++);g>=a.length||(jQuery.isEmptyObject(Sao.common.intersect(Object.keys(d).sort(),c.sort()))?(d[b]=!0,e=jQuery.extend(e,this._get_on_change_args(c)),(this.model.fields[b]instanceof Sao.field.Many2One||this.model.fields[b]instanceof Sao.field.Reference)&&delete this._values[b+".rec_name"]):f[b]=!0)}var h,i=[];jQuery.isEmptyObject(d)||(h=this.model.execute("on_change_with",[e,Object.keys(d)],this.get_context()),i.push(h.then(this.set_on_change.bind(this))));var j=function(a){return function(b){this.model.fields[a].set_on_change(this,b)}};for(b in f)f.hasOwnProperty(b)&&(c=this.model.fields[b].description.on_change_with,e=this._get_on_change_args(c),h=this.model.execute("on_change_with_"+b,[e],this.get_context()),i.push(h.then(j(b).bind(this))));return jQuery.when.apply(jQuery,i)},set_on_change:function(a){var b,c;for(b in a)if(a.hasOwnProperty(b)&&(c=a[b],b in this.model.fields)){if(this.model.fields[b]instanceof Sao.field.Many2One||this.model.fields[b]instanceof Sao.field.Reference){var d=b+".rec_name";a.hasOwnProperty(d)?this._values[d]=a[d]:this._values.hasOwnProperty(d)&&delete this._values[d]}this.model.fields[b].set_on_change(this,c)}},autocomplete_with:function(a){var b=[];for(var c in this.model.fields){~(this.model.fields[c].description.autocomplete||[]).indexOf(a)&&b.push(this.do_autocomplete(c))}return jQuery.when.apply(jQuery,b)},do_autocomplete:function(a){this.autocompletion[a]=[];var b=this.model.fields[a],c=b.description.autocomplete,d=this._get_on_change_args(c);return this.model.execute("autocomplete_"+a,[d],this.get_context()).then(function(b){this.autocompletion[a]=b}.bind(this))},expr_eval:function(a){if("string"!=typeof a)return a;var b=jQuery.extend({},this.model.session.context);if(b.context=jQuery.extend({},b),jQuery.extend(b.context,this.get_context()),jQuery.extend(b,this.get_eval()),b.active_model=this.model.name,b.active_id=this.id,b._user=this.model.session.user_id,this.group.parent&&this.group.parent_name){var c=Sao.common.EvalEnvironment(this.group.parent);b["_parent_"+this.group.parent_name]=c}return new Sao.PYSON.Decoder(b).decode(a)},rec_name:function(){return this.model.execute("read",[[this.id],["rec_name"]],this.get_context()).then(function(a){return a[0].rec_name})},validate:function(a,b,c,d){var e=function(){var e=!0,f=[];this.group.screens.forEach(function(a){a.exclude_field&&f.push(a.exclude_field)});for(var g in this.model.fields)if((!(d&&this.id>=0)||g in this._loaded)&&this.model.fields.hasOwnProperty(g)){var h=this.model.fields[g];a&&!~a.indexOf(g)||h.description.readonly||~f.indexOf(g)||h.validate(this,b,c)||(e=!1)}return e}.bind(this);return d?e():this._check_load(a).then(e)},pre_validate:function(){if(jQuery.isEmptyObject(this._changed))return jQuery.Deferred().resolve(!0);var a=this._get_on_change_args(Object.keys(this._changed));return this.model.execute("pre_validate",[a],this.get_context()).then(function(){return!0},function(){return!1})},cancel:function(){this._loaded={},this._changed={},this._timestamp=null,this.button_clicks={}},_check_load:function(a){return this.get_loaded(a)?jQuery.when():this.reload(a)},get_loaded:function(a){if(!jQuery.isEmptyObject(a)){var b=!0;return a.forEach(function(a){a in this._loaded||a in this._changed||(b=!1)}.bind(this)),b}return Sao.common.compare(Object.keys(this.model.fields).sort(),Object.keys(this._loaded).sort())},root_parent:function(){for(var a=this;a.group.parent;)a=a.group.parent;return a},get_path:function(a){for(var b=[],c=this,d="";c&&(b.push([d,c.id]),c.group!==a);)d=c.group.child_name,c=c.group.parent;return b.reverse(),b},deleted:function(){return Boolean(~this.group.record_deleted.indexOf(this))},removed:function(){return Boolean(~this.group.record_removed.indexOf(this))},readonly:function(){return this.deleted()||this.removed()||this.exception},set_field_context:function(){for(var a in this.model.fields)if(this.model.fields.hasOwnProperty(a)){var b=this.model.fields[a],c=this._values[a];if(c&&c.set_context){var d=b.description.context;d&&c.set_context(this.expr_eval(d))}}},get_attachment_count:function(a){var b=jQuery.Deferred();return this.id<0?(b.resolve(0),b):(this.attachment_count<0||a?b=Sao.rpc({method:"model.ir.attachment.search_count",params:[[["resource","=",this.model.name+","+this.id]],this.get_context()]},this.model.session).then(function(a){return this.attachment_count=a,a}.bind(this)):b.resolve(this.attachment_count),b)},get_unread_note:function(a){var b=jQuery.Deferred();return this.id<0?(b.resolve(0),b):(this.unread_note<0||a?b=Sao.rpc({method:"model.ir.note.search_count",params:[[["resource","=",this.model.name+","+this.id],["unread","=",!0]],this.get_context()]},this.model.session).then(function(a){return this.unread_note=a,a}.bind(this)):b.resolve(this.unread_note),b)},get_button_clicks:function(a){if(this.id<0)return jQuery.when();var b=this.button_clicks[a];return void 0!==b?jQuery.when(b):Sao.rpc({method:"model.ir.model.button.click.get_click",params:[this.model.name,a,this.id,{}]},this.model.session).then(function(b){return this.button_clicks[a]=b,b}.bind(this))}}),Sao.field={},Sao.field.get=function(a){switch(a){case"char":return Sao.field.Char;case"selection":return Sao.field.Selection;case"datetime":return Sao.field.DateTime;case"date":return Sao.field.Date;case"time":return Sao.field.Time;case"timedelta":return Sao.field.TimeDelta;case"float":return Sao.field.Float;case"numeric":return Sao.field.Numeric;case"integer":return Sao.field.Integer;case"boolean":return Sao.field.Boolean;case"many2one":return Sao.field.Many2One;case"one2one":return Sao.field.One2One;case"one2many":return Sao.field.One2Many;case"many2many":return Sao.field.Many2Many;case"reference":return Sao.field.Reference;case"binary":return Sao.field.Binary;case"dict":return Sao.field.Dict;default:return Sao.field.Char}},Sao.field.Field=Sao.class_(Object,{_default:null,init:function(a){this.description=a,this.name=a.name},set:function(a,b){a._values[this.name]=b},get:function(a){var b=a._values[this.name];return void 0===b&&(b=this._default),b},set_client:function(a,b,c){var d=this.get(a);this.set(a,b),JSON.stringify(d)!=JSON.stringify(this.get(a))?(a._changed[this.name]=!0,this.changed(a).done(function(){a.validate(null,!0).then(function(){a.group.changed()})})):c&&(a._changed[this.name]=!0,this.changed(a).done(function(){a.validate(null,!0).then(function(){a.group.root_group().screens.forEach(function(a){a.display()})})}))},get_client:function(a){return this.get(a)},set_default:function(a,b){a._values[this.name]=b,a._changed[this.name]=!0},set_on_change:function(a,b){a._values[this.name]=b,a._changed[this.name]=!0},changed:function(a){var b=[];return b.push(a.on_change([this.name])),b.push(a.on_change_with([this.name])),b.push(a.autocomplete_with(this.name)),a.set_field_context(),jQuery.when.apply(jQuery,b)},get_timestamp:function(a){return{}},get_context:function(a){var b=jQuery.extend({},a.get_context());return a.group.parent&&jQuery.extend(b,a.group.parent.get_context()),jQuery.extend(b,a.expr_eval(this.description.context||{})),b},get_domains:function(a,b){var c=new Sao.common.DomainInversion,d=c.domain_inversion([a.group.domain4inversion(),b||[]],this.name,Sao.common.EvalEnvironment(a));return"boolean"!=typeof d||d?"boolean"==typeof d&&d&&(d=[]):d=[["id","=",null]],[d,a.expr_eval(this.description.domain||[])]},get_domain:function(a){var b=this.get_domains(a),c=b[0],d=b[1],e=new Sao.common.DomainInversion;return e.concat([e.localize_domain(c),d])},validation_domains:function(a,b){return(new Sao.common.DomainInversion).concat(this.get_domains(a,b))},get_eval:function(a){return this.get(a)},get_on_change_value:function(a){return this.get_eval(a)},set_state:function(a,b){void 0===b&&(b=["readonly","required","invisible"]);var c=a.expr_eval(this.description.states||{});b.forEach(function(b){"readonly"==b&&this.description.readonly||(void 0!==c[b]?this.get_state_attrs(a)[b]=c[b]:void 0!==this.description[b]&&(this.get_state_attrs(a)[b]=this.description[b]))}.bind(this)),(a.group.get_readonly()||this.get_state_attrs(a).domain_readonly)&&(this.get_state_attrs(a).readonly=!0)},get_state_attrs:function(a){return this.name in a.state_attrs||(a.state_attrs[this.name]=jQuery.extend({},this.description)),(a.group.get_readonly()||a.readonly())&&(a.state_attrs[this.name].readonly=!0),a.state_attrs[this.name]},check_required:function(a){var b=this.get_state_attrs(a);return!(1==b.required&&!this.get(a)&&1!=b.readonly)},validate:function(a,b,c){if(this.description.readonly)return!0;var d=!1;this.get_state_attrs(a).domain_readonly=!1;var e=new Sao.common.DomainInversion,f=e.simplify(this.validation_domains(a,c));if(b||this.check_required(a)||(d="required"),"boolean"==typeof f)f||(d="domain");else if(Sao.common.compare(f,[["id","=",null]]))d="domain";else{var g=e.unique_value(f),h=g[0],i=g[1],j=g[2];if(h){!1===j&&(j=null);var k,l=!0;k=jQuery.isEmptyObject(a.group.domain())?e.merge(f):e.merge(a.group.domain());var m="AND"==k[0];if(i.contains(".")){var n=i.split(".",1)[0],o=i.split(".",1)[1],p=[];m&&e.localize_domain(k.slice(1)).forEach(function(a){p.push(a)}),"id"==o&&~p.indexOf(n)||(l=!1)}l&&!c&&(this.set_client(a,j),this.get_state_attrs(a).domain_readonly=m)}e.eval_domain(f,Sao.common.EvalEnvironment(a))||(d=f)}return this.get_state_attrs(a).invalid=d,!d}}),Sao.field.Char=Sao.class_(Sao.field.Field,{_default:"",get:function(a){return Sao.field.Char._super.get.call(this,a)||this._default}}),Sao.field.Selection=Sao.class_(Sao.field.Field,{_default:null}),Sao.field.DateTime=Sao.class_(Sao.field.Field,{_default:null,time_format:function(a){return a.expr_eval(this.description.format)},set_client:function(a,b,c){var d;b&&(b.isTime?(d=this.get(a),b=d?Sao.DateTime.combine(d,b):null):b.isDate&&(d=this.get(a))&&(b=Sao.DateTime.combine(b,d))),Sao.field.DateTime._super.set_client.call(this,a,b,c)},date_format:function(a){var b=this.get_context(a);return Sao.common.date_format(b.date_format)}}),Sao.field.Date=Sao.class_(Sao.field.Field,{_default:null,set_client:function(a,b,c){b&&!b.isDate&&(b.isDate=!0,b.isDateTime=!1),Sao.field.Date._super.set_client.call(this,a,b,c)},date_format:function(a){var b=this.get_context(a);return Sao.common.date_format(b.date_format)}}),Sao.field.Time=Sao.class_(Sao.field.Field,{_default:null,time_format:function(a){return a.expr_eval(this.description.format)},set_client:function(a,b,c){b&&(b.isDate||b.isDateTime)&&(b=Sao.Time(b.hour(),b.minute(),b.second(),b.millisecond())),Sao.field.Time._super.set_client.call(this,a,b,c)}}),Sao.field.TimeDelta=Sao.class_(Sao.field.Field,{_default:null,converter:function(a){return a.model.session.context[this.description.converter]},set_client:function(a,b,c){"string"==typeof b&&(b=Sao.common.timedelta.parse(b,this.converter(a))),Sao.field.TimeDelta._super.set_client.call(this,a,b,c)},get_client:function(a){var b=Sao.field.TimeDelta._super.get_client.call(this,a);return Sao.common.timedelta.format(b,this.converter(a))}}),Sao.field.Float=Sao.class_(Sao.field.Field,{_default:null,digits:function(a,b){void 0===b&&(b=1);var c=a.expr_eval(this.description.digits);if(c&&c.every(function(a){return null!==a})){var d=Math.round(Math.log(Math.abs(b))/Math.LN10);return[c[0]+d,c[1]-d]}},check_required:function(a){var b=this.get_state_attrs(a);return 1!=b.required||null!==this.get(a)||1==b.readonly},convert:function(a){return a?(a=Number(a),isNaN(a)&&(a=this._default),a):null},apply_factor:function(a,b){return null!==a&&(a/=b),a},set_client:function(a,b,c,d){void 0===d&&(d=1),b=this.apply_factor(this.convert(b),d),Sao.field.Float._super.set_client.call(this,a,b,c)},get_client:function(a,b){void 0===b&&(b=1);var c=this.get(a);if(null!==c){var d=this.digits(a,b);return d?(c*b).toFixed(d[1]):""+c*b}return""}}),Sao.field.Numeric=Sao.class_(Sao.field.Float,{convert:function(a){return a?(a=new Sao.Decimal(a),isNaN(a.valueOf())&&(a=this._default),a):null},apply_factor:function(a,b){return a=Sao.field.Numeric._super.apply_factor(a,b),null!==a&&(a=new Sao.Decimal(a)),a}}),Sao.field.Integer=Sao.class_(Sao.field.Float,{convert:function(a){return a=parseInt(a,10),isNaN(a)&&(a=this._default),a}}),Sao.field.Boolean=Sao.class_(Sao.field.Field,{_default:!1,set_client:function(a,b,c){b=Boolean(b),Sao.field.Boolean._super.set_client.call(this,a,b,c)},get:function(a){return Boolean(a._values[this.name])},get_client:function(a){return Boolean(a._values[this.name])}}),Sao.field.Many2One=Sao.class_(Sao.field.Field,{_default:null,check_required:function(a){var b=this.get_state_attrs(a);return 1!=b.required||null!==this.get(a)||1==b.readonly},get_client:function(a){var b=a._values[this.name+".rec_name"];return void 0===b&&(this.set(a,this.get(a)),b=a._values[this.name+".rec_name"]||""),b},set:function(a,b){var c=a._values[this.name+".rec_name"]||"",d=function(b){a._values[this.name+".rec_name"]=b[0].rec_name};if(!c&&b>=0&&null!==b){var e=a.model.fields[this.name].description.relation;Sao.rpc({method:"model."+e+".read",params:[[b],["rec_name"],a.get_context()]},a.model.session).done(d.bind(this)).done(function(){a.group.root_group().screens.forEach(function(a){a.display()})})}else d.call(this,[{rec_name:c}]);a._values[this.name]=b},set_client:function(a,b,c){var d;b instanceof Array?(d=b[1],b=b[0]):d=b==this.get(a)?a._values[this.name+".rec_name"]||"":"",a._values[this.name+".rec_name"]=d,Sao.field.Many2One._super.set_client.call(this,a,b,c)},get_context:function(a){var b=Sao.field.Many2One._super.get_context.call(this,a);return this.description.datetime_field&&(b._datetime=a.get_eval()[this.description.datetime_field]),b},validation_domains:function(a,b){return this.get_domains(a,b)[0]},get_domain:function(a){var b=this.get_domains(a),c=b[0],d=b[1],e=new Sao.common.DomainInversion;return e.concat([e.localize_domain(e.inverse_leaf(c),this.name),d])},get_on_change_value:function(a){return a.group.parent_name==this.name&&a.group.parent?a.group.parent.get_on_change_value([a.group.child_name]):Sao.field.Many2One._super.get_on_change_value.call(this,a)}}),Sao.field.One2One=Sao.class_(Sao.field.Many2One,{}),Sao.field.One2Many=Sao.class_(Sao.field.Field,{init:function(a){Sao.field.One2Many._super.init.call(this,a)},_default:null,_set_value:function(a,b,c){this._set_default_value(a);var d=a._values[this.name],e=jQuery.when();jQuery.isEmptyObject(b)&&(b=[]);var f
+jQuery.when(Sao.DB.list()).then(function(a){var e;a=a||[],a.length<=1?(b=a[0],e=c.database_input):(e=c.database_select,a.forEach(function(a){e.append(jQuery("<option/>",{value:a,text:a}))})),e.prop("readonly",1==a.length),e.show(),e.val(b||""),d().first().focus()}),a.promise()},Sao.Session.renew=function(a){if("pending"==a.prm.state())return a.prm;var b=jQuery.Deferred();return a.prm=b.promise(),a.login?(a.do_login(a.login).then(b.resolve,b.reject),a.prm):(b.reject(),a.prm)},Sao.Session.current_session=null,Sao.Login=Sao.class_(Object,{init:function(a,b){this.func=a,this.session=b||Sao.Session.current_session},run:function(a){void 0===a&&(a={});var b=jQuery.Deferred(),c=Sao.common.processing.show(),d=this.func(a);d.id=0;var e={contentType:"application/json",data:JSON.stringify(d),dataType:"json",url:"/"+this.session.database+"/",type:"post",complete:[function(){Sao.common.processing.hide(c)}]};this.session.user_id&&this.session.session&&(e.headers={Authorization:"Session "+this.session.get_auth()});var f=jQuery.ajax(e),g=function(c){if(null===c)Sao.common.warning.run("",Sao.i18n.gettext("Unable to reach the server.")),b.reject();else if(c.error){if(c.error[0].startsWith("403"))return this.run({}).then(b.resolve,b.reject);if(c.error[0].startsWith("404"))b.reject();else if("LoginException"!=c.error[0])Sao.common.error.run(c.error[0],c.error[1]),b.reject();else{var d=c.error[1],e=d[0],f=d[1],g=d[2];this["get_"+g](f).then(function(c){return a[e]=c,this.run(a).then(b.resolve,b.reject)}.bind(this),b.reject)}}else b.resolve(c.result)};return f.success(g.bind(this)),f.error(b.reject),b.promise()},get_char:function(a){return Sao.common.ask.run(a)},get_password:function(a){return Sao.common.ask.run(a,!1)}}),Sao.DB={},Sao.DB.list=function(){var a=Sao.common.processing.show();return jQuery.ajax({contentType:"application/json",data:JSON.stringify({id:0,method:"common.db.list",params:[]}),dataType:"json",url:"/",type:"post",complete:[function(){Sao.common.processing.hide(a)}]}).then(function(a){return a.result})}}(),function(){"use strict";Sao.Model=Sao.class_(Object,{init:function(a,b){b=b||{},this.name=a,this.session=Sao.Session.current_session,this.fields={}},add_fields:function(a){var b=[];for(var c in a)if(a.hasOwnProperty(c)&&!(c in this.fields)){var d=a[c],e=Sao.field.get(d.type);this.fields[c]=new e(d),b.push(c)}return b},execute:function(a,b,c){void 0===c&&(c={});var d={method:"model."+this.name+"."+a,params:b.concat(c)};return Sao.rpc(d,this.session)},find:function(a,b,c,d,e){b||(b=0);var f=this,g=this.execute("search",[a,b,c,d],e),h=function(a){return Sao.Group(f,e,a.map(function(a){return new Sao.Record(f,a)}))};return g.pipe(h)},delete_:function(a){if(jQuery.isEmptyObject(a))return jQuery.when();var b=a[0],c=b.group.root_group();console.assert(a.every(function(a){return a.model.name==b.model.name}),"records not from the same model"),console.assert(a.every(function(a){return a.group.root_group()==b.group.root_group()}),"records not from the same root group"),a=a.filter(function(a){return a.id>=0});var d={};d._timestamp={},a.forEach(function(a){jQuery.extend(d._timestamp,a.get_timestamp())});var e=a.map(function(a){return a.id});return c.on_write_ids(e).then(function(a){return a=a.filter(function(a){return!~e.indexOf(a)}),this.execute("delete",[e],d).then(function(){c.reload(a)})}.bind(this))},copy:function(a,b){if(jQuery.isEmptyObject(a))return jQuery.when();var c=a.map(function(a){return a.id});return this.execute("copy",[c,{}],b)}}),Sao.Group=function(a,b,c){return c.prm=jQuery.when(),c.model=a,c._context=b,c.on_write=[],c.parent=void 0,c.screens=[],c.parent_name="",c.children=[],c.child_name="",c.parent_datetime_field=void 0,c.record_removed=[],c.record_deleted=[],c.__readonly=!1,c.skip_model_access=!1,c.forEach(function(a,b,c){a.group=c}),c.get_readonly=function(){var a=Sao.common.MODELACCESS.get(this.model.name);return!(!this.context._datetime&&(a.write||a.create||this.skip_model_access))||this.__readonly},c.set_readonly=function(a){this.__readonly=a},c.load=function(a,b){var c,d,e=[];for(c=0,d=a.length;c<d;c++){var f=a[c],g=this.get(f);g||(g=new Sao.Record(this.model,f),g.group=this,this.push(g)),e.push(g)}var h,i=[];for(c=0,d=this.record_removed.length;c<d;c++)h=this.record_removed[c],~a.indexOf(h.id)||i.push(h);this.record_removed=i;var j=[];for(c=0,d=this.record_deleted.length;c<d;c++)h=this.record_deleted[c],~a.indexOf(h.id)||j.push(h);if(this.record_deleted=j,e.length&&b){var k=this.root_group();this.changed().then(function(){k.screens.forEach(function(a){a.display()})})}},c.get=function(a){for(var b=0,c=this.length;b<c;b++){var d=this[b];if(d.id==a)return d}},c.new_=function(a,b,c){var d=new Sao.Record(this.model,b);return d.group=this,a&&d.default_get(c),d},c.add=function(a,b,c){void 0!==b&&-1!=b||(b=this.length),void 0===c&&(c=!0),a.group!=this&&(a.group=this),this.splice(b,0,a);for(var d in this.record_removed)d.id==a.id&&this.record_removed.splice(this.record_removed.indexOf(d),1);for(var e in this.record_deleted)e.id==a.id&&this.record_deleted.splice(this.record_deleted.indexOf(e),1);if(a._changed.id=!0,c&&(this.changed(),this.parent&&this.model.fields[this.parent_name])){var f=this.model.fields[this.parent_name];if(f instanceof Sao.field.Many2One||f instanceof Sao.field.Reference){var g=[this.parent.id,""];f instanceof Sao.field.Reference&&(g=[this.parent.model.name,g]),f.set_client(a,g)}}return a},c.remove=function(a,b,c,d){void 0===c&&(c=!0);this.indexOf(a);a.id>=0&&(b?(~this.record_deleted.indexOf(a)&&this.record_deleted.splice(this.record_deleted.indexOf(a),1),this.record_removed.push(a)):(~this.record_removed.indexOf(a)&&this.record_removed.splice(this.record_removed.indexOf(a),1),this.record_deleted.push(a))),a.group.parent&&(a.group.parent._changed.id=!0),c&&(a._changed.id=!0),(a.id<0||d)&&this._remove(a),a.group.changed()},c._remove=function(a){var b=this.indexOf(a);this.splice(b,1)},c.unremove=function(a){this.record_removed.splice(this.record_removed.indexOf(a),1),this.record_deleted.splice(this.record_deleted.indexOf(a),1),a.group.changed()},c.changed=function(){if(!this.parent)return jQuery.when.apply(jQuery,this.screens.map(function(a){return a.display()}));this.parent._changed[this.child_name]=!0;var a=this.parent.model.fields[this.child_name].changed(this.parent);return a||(a=jQuery.when()),a.then(function(){this.parent.validate(null,!0).done(function(){return this.parent.group.changed()}.bind(this))}.bind(this))},c.root_group=function(){for(var a=this,b=this.parent;b;)a=b.group,b=b.parent;return a},c.save=function(){var a=[];return this.forEach(function(b){a.push(b.save())}),jQuery.isEmptyObject(this.record_deleted)||(this.record_deleted.forEach(function(a){this._remove(a)}.bind(this)),a.push(this.model.delete_(this.record_deleted)),this.record_deleted.splice(0,this.record_deleted.length)),jQuery.when.apply(jQuery,a)},c.written=function(a){return"number"==typeof a&&(a=[a]),this.on_write_ids(a).then(function(b){b=b.filter(function(b){return!~a.indexOf(b)}),this.root_group().reload(b)}.bind(this))},c.reload=function(a){this.children.forEach(function(b){b.reload(a)}),a.forEach(function(a){var b=this.get(a);b&&jQuery.isEmptyObject(b._changed)&&b.cancel()}.bind(this))},c.on_write_ids=function(a){var b=[],c=[];return this.on_write.forEach(function(d){var e=this.model.execute(d,[a],this._context).then(function(a){jQuery.extend(c,a)});b.push(e)}.bind(this)),jQuery.when.apply(jQuery,b).then(function(){return c.filter(function(a,b,c){return b==c.indexOf(a)})})},c.set_parent=function(a){this.parent=a,a&&a.model.name==this.model.name&&this.parent.group.children.push(this)},c.add_fields=function(a){var b=this.model.add_fields(a);if(!jQuery.isEmptyObject(this)){var c=[];this.forEach(function(a){a.id<0&&c.push(a)}),c.length&&b.length&&this.model.execute("default_get",[b,this.context()]).then(function(a){c.forEach(function(b){b.set_default(a)})})}},c.destroy=function(){if(this.parent){var a=this.parent.group.children.indexOf(this);~a&&this.parent.group.children.splice(a,1)}this.parent=null},c.domain=function(){var a=[];if(this.screens.forEach(function(b){b.attributes.domain&&a.push(b.attributes.domain)}),this.parent&&this.child_name){var b=this.parent.model.fields[this.child_name];return[a,b.get_domain(this.parent)]}return a},c.context=function(){var a=jQuery.extend({},this._context);if(this.parent&&(jQuery.extend(a,this.parent.get_context()),this.child_name in this.parent.model.fields)){var b=this.parent.model.fields[this.child_name];jQuery.extend(a,b.get_context(this.parent))}return jQuery.extend(a,this._context),this.parent_datetime_field&&(a._datetime=this.parent.get_eval()[this.parent_datetime_field]),a},c.set_context=function(a){this._context=jQuery.extend({},a)},c.clean4inversion=function(a){if(jQuery.isEmptyObject(a))return[];var b=new Sao.common.DomainInversion,c=a[0],d=a.slice(1);if(~["AND","OR"].indexOf(c));else if(b.is_leaf(c)){var e=c[0];e in this.model.fields&&this.model.fields[e].description.readonly&&(c=[])}else c=this.clean4inversion(c);return[c].concat(this.clean4inversion(d))},c.domain4inversion=function(){var a=this.domain();return this.__domain4inversion&&Sao.common.compare(this.__domain4inversion[0],a)||(this.__domain4inversion=[a,this.clean4inversion(a)]),this.__domain4inversion[1]},c.get_by_path=function(a){a=jQuery.extend([],a);var b=null,c=this,d=function(){if(jQuery.isEmptyObject(a))return b;var e=a[0][0],f=a[0][1];return a.splice(0,1),b=c.get(f),b?e?b.load(e).then(function(){return c=b._values[e],c?d():null}):d():null};return jQuery.when().then(d)},c.sort=function(a){var b={};this.forEach(function(a){b[a.id]=a}),a.forEach(function(a,c){this[c]=b[a.id]}.bind(this))},c},Sao.Record=Sao.class_(Object,{id_counter:-1,init:function(a,b){this.model=a,this.group=Sao.Group(a,{},[]),this.id=void 0===b||null===b?Sao.Record.prototype.id_counter:b,this.id<0&&Sao.Record.prototype.id_counter--,this._values={},this._changed={},this._loaded={},this.fields={},this._timestamp=null,this.attachment_count=-1,this.unread_note=-1,this.button_clicks={},this.state_attrs={},this.autocompletion={},this.exception=!1},has_changed:function(){return!jQuery.isEmptyObject(this._changed)},save:function(a){void 0===a&&(a=!1);var b=this.get_context(),c=jQuery.when(),d=this.get();if(this.id<0||!jQuery.isEmptyObject(d)){if(this.id<0){c=this.model.execute("create",[[d]],b);var e=function(a){this.id=a[0]};c.done(e.bind(this))}else jQuery.isEmptyObject(d)||(b._timestamp=this.get_timestamp(),c=this.model.execute("write",[[this.id],d],b));c=c.done(function(){if(this.cancel(),a)return this.reload()}.bind(this)),this.group&&(c=c.done(function(){return this.group.written(this.id)}.bind(this)))}return this.group.parent&&(delete this.group.parent._changed[this.group.child_name],c=c.done(function(){return this.group.parent.save(a)}.bind(this))),c},reload:function(a){if(this.id<0)return jQuery.when();if(a){var b=a.map(function(a){return this.load(a)}.bind(this));return jQuery.when.apply(jQuery,b)}return this.load("*")},load:function(a){var b,c;if(this.id<0||a in this._loaded)return jQuery.when();if("pending"==this.group.prm.state())return c=jQuery.Deferred(),this.group.prm.then(function(){this.load(a).then(c.resolve,c.reject)}.bind(this)),c;var d={};d[this.id]=this;var e;if("*"==a){e="eager";for(b in this.model.fields)if(this.model.fields.hasOwnProperty(b)){var f=this.model.fields[b].description.loading||"eager";if("eager"!=f){e="lazy";break}}}else e=this.model.fields[a].description.loading||"eager";var g=[];if("eager"==e)for(b in this.model.fields)this.model.fields.hasOwnProperty(b)&&"eager"==(this.model.fields[b].description.loading||"eager")&&g.push(b);else g=Object.keys(this.model.fields);g=g.filter(function(a,b,c){return!(a in this._loaded)}.bind(this));var h=g.slice(),i=["many2one","one2one","reference"];for(var j in g){b=g[j];var k=this.model.fields[b].description;~i.indexOf(k.type)&&h.push(b+".rec_name")}~g.indexOf("rec_name")||h.push("rec_name"),h.push("_timestamp");var l=jQuery.extend({},this.get_context());if("eager"==e){var m,n,o=parseInt(Sao.config.limit/h.length,10),p=function(b){return!(a in b._loaded)&&b.id>=0},q=function(a){return p(a)&&void 0===d[a.id]&&(a.group===this.group||JSON.stringify(a.get_context())===JSON.stringify(l))}.bind(this);this.group.parent&&this.group.parent.model.name==this.model.name?(m=[],m=m.concat.apply(m,this.group.parent.group.children),n=q):(m=this.group,n=p);var r=m.indexOf(this);if(~r)for(var s=m.length,t=1;Object.keys(d).length<o&&(r-t>=0||r+t<s)&&t<2*o;){var u;r-t>=0&&(u=m[r-t],n(u)&&(d[u.id]=u)),r+t<s&&(u=m[r+t],n(u)&&(d[u.id]=u)),t++}}for(b in this.model.fields)this.model.fields.hasOwnProperty(b)&&"binary"==this.model.fields[b].description.type&&~h.indexOf(b,h)&&(l[this.model.name+"."+b]="size");c=this.model.execute("read",[Object.keys(d).map(function(a){return parseInt(a,10)}),h],l);var v=function(a,b){void 0===b&&(b=!1);var c={},e=[];a.forEach(function(a,b,d){c[a.id]=a});for(var f in d)if(d.hasOwnProperty(f)){var g=d[f];g.exception||(g.exception=b);var h=c[f];if(g&&h){for(var i in this._changed)this._changed.hasOwnProperty(i)&&delete h[i];e.push(g.set(h))}}return jQuery.when.apply(jQuery,e)}.bind(this),w=function(){var a,b=[];for(var c in d){a={id:c};for(var e in h)a[h[e]]=null;b.push(a)}return v(b,!0)};return this.group.prm=c.then(v,w),this.group.prm},set:function(a,b){void 0===b&&(b=!0);var c,d,e={},f=[];for(c in a)if(a.hasOwnProperty(c))if(d=a[c],"_timestamp"!=c)if(c in this.model.fields){if(this.model.fields[c]instanceof Sao.field.One2Many&&(e[c]=d),this.model.fields[c]instanceof Sao.field.Many2One||this.model.fields[c]instanceof Sao.field.Reference){var g=c+".rec_name";a.hasOwnProperty(g)?this._values[g]=a[g]:this._values.hasOwnProperty(g)&&delete this._values[g]}this.model.fields[c].set(this,d),this._loaded[c]=!0,f.push(c)}else"rec_name"==c&&(this._values[c]=d);else this._timestamp||(this._timestamp=d);for(c in e)d=e[c],this.model.fields[c].set(this,d),this._loaded[c]=!0;return b?this.validate(f,!0):jQuery.when()},get:function(){var a={};for(var b in this.model.fields)if(this.model.fields.hasOwnProperty(b)){var c=this.model.fields[b];(!c.description.readonly||c instanceof Sao.field.One2Many)&&(void 0===this._changed[b]&&this.id>=0||(a[b]=c.get(this),c instanceof Sao.field.One2Many&&0===a[b].length&&delete a[b]))}return a},invalid_fields:function(){var a={};for(var b in this.model.fields){var c=this.model.fields[b],d=c.get_state_attrs(this).invalid;d&&(a[b]=d)}return a},get_context:function(){return this.group.context()},field_get:function(a){return this.model.fields[a].get(this)},field_set:function(a,b){this.model.fields[a].set(this,b)},field_get_client:function(a){return this.model.fields[a].get_client(this)},field_set_client:function(a,b,c){this.model.fields[a].set_client(this,b,c)},default_get:function(a){if(!jQuery.isEmptyObject(this.model.fields)){var b=this.get_context();void 0===b.default_rec_name&&(b.default_rec_name=a);return this.model.execute("default_get",[Object.keys(this.model.fields)],b).then(function(a){if(this.group.parent&&this.group.parent_name in this.group.model.fields){var b=this.group.model.fields[this.group.parent_name];b instanceof Sao.field.Reference?a[this.group.parent_name]=[this.group.parent.model.name,this.group.parent.id]:b.description.relation==this.group.parent.model.name&&(a[this.group.parent_name]=this.group.parent.id)}return this.set_default(a)}.bind(this))}return jQuery.when()},set_default:function(a,b){void 0===b&&(b=!0);var c=[],d=[];for(var e in a)if(a.hasOwnProperty(e)){var f=a[e];if(e in this.model.fields){if(this.model.fields[e]instanceof Sao.field.Many2One||this.model.fields[e]instanceof Sao.field.Reference){var g=e+".rec_name";a.hasOwnProperty(g)?this._values[g]=a[g]:this._values.hasOwnProperty(g)&&delete this._values[g]}c.push(this.model.fields[e].set_default(this,f)),this._loaded[e]=!0,d.push(e)}}return jQuery.when.apply(jQuery,c).then(function(){return this.on_change(d).then(function(){return this.on_change_with(d).then(function(){var a=function(){return this.group.root_group().screens.forEach(function(a){return a.display()})}.bind(this);return b?this.validate(null,!0).then(a):a()}.bind(this))}.bind(this))}.bind(this))},get_timestamp:function(){var a={};a[this.model.name+","+this.id]=this._timestamp;for(var b in this.model.fields)this.model.fields.hasOwnProperty(b)&&b in this._loaded&&jQuery.extend(a,this.model.fields[b].get_timestamp(this));return a},get_eval:function(){var a={};for(var b in this.model.fields)!this.model.fields.hasOwnProperty(b)&&this.id>=0||(a[b]=this.model.fields[b].get_eval(this));return a.id=this.id,a},get_on_change_value:function(a){var b={};for(var c in this.model.fields)a&&~a.indexOf(c)||(!(this.id>=0)||this._loaded[c]&&this._changed[c])&&(b[c]=this.model.fields[c].get_on_change_value(this));return b.id=this.id,b},_get_on_change_args:function(a){var b={},c=Sao.common.EvalEnvironment(this,"on_change");return a.forEach(function(a){var d=c;a.split(".").forEach(function(a){void 0!==d&&(d=d[a])}),b[a]=d}),b.id=this.id,b},on_change:function(a){var b={};return a.forEach(function(a){var c=this.model.fields[a].description.on_change;jQuery.isEmptyObject(c)||(b=jQuery.extend(b,this._get_on_change_args(c)))}.bind(this)),jQuery.isEmptyObject(b)?jQuery.when():this.model.execute("on_change",[b,a],this.get_context()).then(function(a){a.forEach(this.set_on_change.bind(this))}.bind(this))},on_change_with:function(a){var b,c,d={},e={},f={};for(b in this.model.fields)if(this.model.fields.hasOwnProperty(b)&&(c=this.model.fields[b].description.on_change_with,!jQuery.isEmptyObject(c))){for(var g=0;g<a.length&&!~c.indexOf(a[g]);g++);g>=a.length||(jQuery.isEmptyObject(Sao.common.intersect(Object.keys(d).sort(),c.sort()))?(d[b]=!0,e=jQuery.extend(e,this._get_on_change_args(c)),(this.model.fields[b]instanceof Sao.field.Many2One||this.model.fields[b]instanceof Sao.field.Reference)&&delete this._values[b+".rec_name"]):f[b]=!0)}var h,i=[];jQuery.isEmptyObject(d)||(h=this.model.execute("on_change_with",[e,Object.keys(d)],this.get_context()),i.push(h.then(this.set_on_change.bind(this))));var j=function(a){return function(b){this.model.fields[a].set_on_change(this,b)}};for(b in f)f.hasOwnProperty(b)&&(c=this.model.fields[b].description.on_change_with,e=this._get_on_change_args(c),h=this.model.execute("on_change_with_"+b,[e],this.get_context()),i.push(h.then(j(b).bind(this))));return jQuery.when.apply(jQuery,i)},set_on_change:function(a){var b,c;for(b in a)if(a.hasOwnProperty(b)&&(c=a[b],b in this.model.fields)){if(this.model.fields[b]instanceof Sao.field.Many2One||this.model.fields[b]instanceof Sao.field.Reference){var d=b+".rec_name";a.hasOwnProperty(d)?this._values[d]=a[d]:this._values.hasOwnProperty(d)&&delete this._values[d]}this.model.fields[b].set_on_change(this,c)}},autocomplete_with:function(a){var b=[];for(var c in this.model.fields){~(this.model.fields[c].description.autocomplete||[]).indexOf(a)&&b.push(this.do_autocomplete(c))}return jQuery.when.apply(jQuery,b)},do_autocomplete:function(a){this.autocompletion[a]=[];var b=this.model.fields[a],c=b.description.autocomplete,d=this._get_on_change_args(c);return this.model.execute("autocomplete_"+a,[d],this.get_context()).then(function(b){this.autocompletion[a]=b}.bind(this))},expr_eval:function(a){if("string"!=typeof a)return a;var b=jQuery.extend({},this.model.session.context);if(b.context=jQuery.extend({},b),jQuery.extend(b.context,this.get_context()),jQuery.extend(b,this.get_eval()),b.active_model=this.model.name,b.active_id=this.id,b._user=this.model.session.user_id,this.group.parent&&this.group.parent_name){var c=Sao.common.EvalEnvironment(this.group.parent);b["_parent_"+this.group.parent_name]=c}return new Sao.PYSON.Decoder(b).decode(a)},rec_name:function(){return this.model.execute("read",[[this.id],["rec_name"]],this.get_context()).then(function(a){return a[0].rec_name})},validate:function(a,b,c,d){var e=function(){var e=!0,f=[];this.group.screens.forEach(function(a){a.exclude_field&&f.push(a.exclude_field)});for(var g in this.model.fields)if((!(d&&this.id>=0)||g in this._loaded)&&this.model.fields.hasOwnProperty(g)){var h=this.model.fields[g];a&&!~a.indexOf(g)||h.description.readonly||~f.indexOf(g)||h.validate(this,b,c)||(e=!1)}return e}.bind(this);return d?e():this._check_load(a).then(e)},pre_validate:function(){if(jQuery.isEmptyObject(this._changed))return jQuery.Deferred().resolve(!0);var a=this._get_on_change_args(Object.keys(this._changed));return this.model.execute("pre_validate",[a],this.get_context()).then(function(){return!0},function(){return!1})},cancel:function(){this._loaded={},this._changed={},this._timestamp=null,this.button_clicks={}},_check_load:function(a){return this.get_loaded(a)?jQuery.when():this.reload(a)},get_loaded:function(a){if(!jQuery.isEmptyObject(a)){var b=!0;return a.forEach(function(a){a in this._loaded||a in this._changed||(b=!1)}.bind(this)),b}return Sao.common.compare(Object.keys(this.model.fields).sort(),Object.keys(this._loaded).sort())},root_parent:function(){for(var a=this;a.group.parent;)a=a.group.parent;return a},get_path:function(a){for(var b=[],c=this,d="";c&&(b.push([d,c.id]),c.group!==a);)d=c.group.child_name,c=c.group.parent;return b.reverse(),b},deleted:function(){return Boolean(~this.group.record_deleted.indexOf(this))},removed:function(){return Boolean(~this.group.record_removed.indexOf(this))},readonly:function(){return this.deleted()||this.removed()||this.exception},set_field_context:function(){for(var a in this.model.fields)if(this.model.fields.hasOwnProperty(a)){var b=this.model.fields[a],c=this._values[a];if(c&&c.set_context){var d=b.description.context;d&&c.set_context(this.expr_eval(d))}}},get_attachment_count:function(a){var b=jQuery.Deferred();return this.id<0?(b.resolve(0),b):(this.attachment_count<0||a?b=Sao.rpc({method:"model.ir.attachment.search_count",params:[[["resource","=",this.model.name+","+this.id]],this.get_context()]},this.model.session).then(function(a){return this.attachment_count=a,a}.bind(this)):b.resolve(this.attachment_count),b)},get_unread_note:function(a){var b=jQuery.Deferred();return this.id<0?(b.resolve(0),b):(this.unread_note<0||a?b=Sao.rpc({method:"model.ir.note.search_count",params:[[["resource","=",this.model.name+","+this.id],["unread","=",!0]],this.get_context()]},this.model.session).then(function(a){return this.unread_note=a,a}.bind(this)):b.resolve(this.unread_note),b)},get_button_clicks:function(a){if(this.id<0)return jQuery.when();var b=this.button_clicks[a];return void 0!==b?jQuery.when(b):Sao.rpc({method:"model.ir.model.button.click.get_click",params:[this.model.name,a,this.id,{}]},this.model.session).then(function(b){return this.button_clicks[a]=b,b}.bind(this))}}),Sao.field={},Sao.field.get=function(a){switch(a){case"char":return Sao.field.Char;case"selection":return Sao.field.Selection;case"datetime":return Sao.field.DateTime;case"date":return Sao.field.Date;case"time":return Sao.field.Time;case"timedelta":return Sao.field.TimeDelta;case"float":return Sao.field.Float;case"numeric":return Sao.field.Numeric;case"integer":return Sao.field.Integer;case"boolean":return Sao.field.Boolean;case"many2one":return Sao.field.Many2One;case"one2one":return Sao.field.One2One;case"one2many":return Sao.field.One2Many;case"many2many":return Sao.field.Many2Many;case"reference":return Sao.field.Reference;case"binary":return Sao.field.Binary;case"dict":return Sao.field.Dict;default:return Sao.field.Char}},Sao.field.Field=Sao.class_(Object,{_default:null,init:function(a){this.description=a,this.name=a.name},set:function(a,b){a._values[this.name]=b},get:function(a){var b=a._values[this.name];return void 0===b&&(b=this._default),b},set_client:function(a,b,c){var d=this.get(a);this.set(a,b),JSON.stringify(d)!=JSON.stringify(this.get(a))?(a._changed[this.name]=!0,this.changed(a).done(function(){a.validate(null,!0).then(function(){a.group.changed()})})):c&&(a._changed[this.name]=!0,this.changed(a).done(function(){a.validate(null,!0).then(function(){a.group.root_group().screens.forEach(function(a){a.display()})})}))},get_client:function(a){return this.get(a)},set_default:function(a,b){a._values[this.name]=b,a._changed[this.name]=!0},set_on_change:function(a,b){a._values[this.name]=b,a._changed[this.name]=!0},changed:function(a){var b=[];return b.push(a.on_change([this.name])),b.push(a.on_change_with([this.name])),b.push(a.autocomplete_with(this.name)),a.set_field_context(),jQuery.when.apply(jQuery,b)},get_timestamp:function(a){return{}},get_context:function(a){var b=jQuery.extend({},a.get_context());return a.group.parent&&jQuery.extend(b,a.group.parent.get_context()),jQuery.extend(b,a.expr_eval(this.description.context||{})),b},get_domains:function(a,b){var c=new Sao.common.DomainInversion,d=c.domain_inversion([a.group.domain4inversion(),b||[]],this.name,Sao.common.EvalEnvironment(a));return"boolean"!=typeof d||d?"boolean"==typeof d&&d&&(d=[]):d=[["id","=",null]],[d,a.expr_eval(this.description.domain||[])]},get_domain:function(a){var b=this.get_domains(a),c=b[0],d=b[1],e=new Sao.common.DomainInversion;return e.concat([e.localize_domain(c),d])},validation_domains:function(a,b){return(new Sao.common.DomainInversion).concat(this.get_domains(a,b))},get_eval:function(a){return this.get(a)},get_on_change_value:function(a){return this.get_eval(a)},set_state:function(a,b){void 0===b&&(b=["readonly","required","invisible"]);var c=a.expr_eval(this.description.states||{});b.forEach(function(b){"readonly"==b&&this.description.readonly||(void 0!==c[b]?this.get_state_attrs(a)[b]=c[b]:void 0!==this.description[b]&&(this.get_state_attrs(a)[b]=this.description[b]))}.bind(this)),(a.group.get_readonly()||this.get_state_attrs(a).domain_readonly)&&(this.get_state_attrs(a).readonly=!0)},get_state_attrs:function(a){return this.name in a.state_attrs||(a.state_attrs[this.name]=jQuery.extend({},this.description)),(a.group.get_readonly()||a.readonly())&&(a.state_attrs[this.name].readonly=!0),a.state_attrs[this.name]},check_required:function(a){var b=this.get_state_attrs(a);return!(1==b.required&&!this.get(a)&&1!=b.readonly)},validate:function(a,b,c){if(this.description.readonly)return!0;var d=!1;this.get_state_attrs(a).domain_readonly=!1;var e=new Sao.common.DomainInversion,f=e.simplify(this.validation_domains(a,c));if(b||this.check_required(a)||(d="required"),"boolean"==typeof f)f||(d="domain");else if(Sao.common.compare(f,[["id","=",null]]))d="domain";else{var g=e.unique_value(f),h=g[0],i=g[1],j=g[2];if(h){!1===j&&(j=null);var k,l=!0;k=jQuery.isEmptyObject(a.group.domain())?e.merge(f):e.merge(a.group.domain());var m="AND"==k[0];if(i.contains(".")){var n=i.split(".",1)[0],o=i.split(".",1)[1],p=[];m&&e.localize_domain(k.slice(1)).forEach(function(a){p.push(a)}),"id"==o&&~p.indexOf(n)||(l=!1)}l&&!c&&(this.set_client(a,j),this.get_state_attrs(a).domain_readonly=m)}e.eval_domain(f,Sao.common.EvalEnvironment(a))||(d=f)}return this.get_state_attrs(a).invalid=d,!d}}),Sao.field.Char=Sao.class_(Sao.field.Field,{_default:"",get:function(a){return Sao.field.Char._super.get.call(this,a)||this._default}}),Sao.field.Selection=Sao.class_(Sao.field.Field,{_default:null}),Sao.field.DateTime=Sao.class_(Sao.field.Field,{_default:null,time_format:function(a){return a.expr_eval(this.description.format)},set_client:function(a,b,c){var d;b&&(b.isTime?(d=this.get(a),b=d?Sao.DateTime.combine(d,b):null):b.isDate&&(d=this.get(a))&&(b=Sao.DateTime.combine(b,d))),Sao.field.DateTime._super.set_client.call(this,a,b,c)},date_format:function(a){var b=this.get_context(a);return Sao.common.date_format(b.date_format)}}),Sao.field.Date=Sao.class_(Sao.field.Field,{_default:null,set_client:function(a,b,c){b&&!b.isDate&&(b.isDate=!0,b.isDateTime=!1),Sao.field.Date._super.set_client.call(this,a,b,c)},date_format:function(a){var b=this.get_context(a);return Sao.common.date_format(b.date_format)}}),Sao.field.Time=Sao.class_(Sao.field.Field,{_default:null,time_format:function(a){return a.expr_eval(this.description.format)},set_client:function(a,b,c){b&&(b.isDate||b.isDateTime)&&(b=Sao.Time(b.hour(),b.minute(),b.second(),b.millisecond())),Sao.field.Time._super.set_client.call(this,a,b,c)}}),Sao.field.TimeDelta=Sao.class_(Sao.field.Field,{_default:null,converter:function(a){return a.model.session.context[this.description.converter]},set_client:function(a,b,c){"string"==typeof b&&(b=Sao.common.timedelta.parse(b,this.converter(a))),Sao.field.TimeDelta._super.set_client.call(this,a,b,c)},get_client:function(a){var b=Sao.field.TimeDelta._super.get_client.call(this,a);return Sao.common.timedelta.format(b,this.converter(a))}}),Sao.field.Float=Sao.class_(Sao.field.Field,{_default:null,digits:function(a,b){void 0===b&&(b=1);var c=a.expr_eval(this.description.digits);if(c&&c.every(function(a){return null!==a})){var d=Math.round(Math.log(Math.abs(b))/Math.LN10);return[c[0]+d,c[1]-d]}},check_required:function(a){var b=this.get_state_attrs(a);return 1!=b.required||null!==this.get(a)||1==b.readonly},convert:function(a){return a?(a=Number(a),isNaN(a)&&(a=this._default),a):null},apply_factor:function(a,b){return null!==a&&(a/=b),a},set_client:function(a,b,c,d){void 0===d&&(d=1),b=this.apply_factor(this.convert(b),d),Sao.field.Float._super.set_client.call(this,a,b,c)},get_client:function(a,b){void 0===b&&(b=1);var c=this.get(a);if(null!==c){var d=this.digits(a,b);return d?(c*b).toFixed(d[1]):""+c*b}return""}}),Sao.field.Numeric=Sao.class_(Sao.field.Float,{convert:function(a){return a?(a=new Sao.Decimal(a),isNaN(a.valueOf())&&(a=this._default),a):null},apply_factor:function(a,b){return a=Sao.field.Numeric._super.apply_factor(a,b),null!==a&&(a=new Sao.Decimal(a)),a}}),Sao.field.Integer=Sao.class_(Sao.field.Float,{convert:function(a){return a=parseInt(a,10),isNaN(a)&&(a=this._default),a}}),Sao.field.Boolean=Sao.class_(Sao.field.Field,{_default:!1,set_client:function(a,b,c){b=Boolean(b),Sao.field.Boolean._super.set_client.call(this,a,b,c)},get:function(a){return Boolean(a._values[this.name])},get_client:function(a){return Boolean(a._values[this.name])}}),Sao.field.Many2One=Sao.class_(Sao.field.Field,{_default:null,check_required:function(a){var b=this.get_state_attrs(a);return 1!=b.required||null!==this.get(a)||1==b.readonly},get_client:function(a){var b=a._values[this.name+".rec_name"];return void 0===b&&(this.set(a,this.get(a)),b=a._values[this.name+".rec_name"]||""),b},set:function(a,b){var c=a._values[this.name+".rec_name"]||"",d=function(b){a._values[this.name+".rec_name"]=b[0].rec_name};if(!c&&b>=0&&null!==b){var e=a.model.fields[this.name].description.relation;Sao.rpc({method:"model."+e+".read",params:[[b],["rec_name"],a.get_context()]},a.model.session).done(d.bind(this)).done(function(){a.group.root_group().screens.forEach(function(a){a.display()})})}else d.call(this,[{rec_name:c}]);a._values[this.name]=b},set_client:function(a,b,c){var d;b instanceof Array?(d=b[1],b=b[0]):d=b==this.get(a)?a._values[this.name+".rec_name"]||"":"",a._values[this.name+".rec_name"]=d,Sao.field.Many2One._super.set_client.call(this,a,b,c)},get_context:function(a){var b=Sao.field.Many2One._super.get_context.call(this,a);return this.description.datetime_field&&(b._datetime=a.get_eval()[this.description.datetime_field]),b},validation_domains:function(a,b){return this.get_domains(a,b)[0]},get_domain:function(a){var b=this.get_domains(a),c=b[0],d=b[1],e=new Sao.common.DomainInversion;return e.concat([e.localize_domain(e.inverse_leaf(c),this.name),d])},get_on_change_value:function(a){return a.group.parent_name==this.name&&a.group.parent?a.group.parent.get_on_change_value([a.group.child_name]):Sao.field.Many2One._super.get_on_change_value.call(this,a)}}),Sao.field.One2One=Sao.class_(Sao.field.Many2One,{}),Sao.field.One2Many=Sao.class_(Sao.field.Field,{init:function(a){Sao.field.One2Many._super.init.call(this,a)},_default:null,_set_value:function(a,b,c){this._set_default_value(a);var d=a._values[this.name],e=jQuery.when();jQuery.isEmptyObject(b)&&(b=[]);var f
 ;if("list values"==(f=jQuery.isEmptyObject(b)||!isNaN(parseInt(b[0],10))?"list ids":"list values")){var g=this.get_context(a),h={};if(b.forEach(function(a){for(var b in a)a.hasOwnProperty(b)&&(b in d.model.fields||~b.indexOf(".")||(h[b]=!0))}),!jQuery.isEmptyObject(h)){var i={method:"model."+this.description.relation+".fields_get",params:[Object.keys(h),g]};e=Sao.rpc(i,a.model.session)}}var j=function(e){var g=[];if(jQuery.isEmptyObject(e)||d.add_fields(e),a._values[this.name]=d,"list ids"==f){for(var h=0,i=d.length;h<i;h++){var j=d[h];~b.indexOf(j.id)||d.remove(j,!0)}d.load(b)}else b.forEach(function(a){var b=d.new_(!1);c?(g.push(b.set_default(a,!1)),d.add(b)):(g.push(b.set(a)),d.push(b))});return jQuery.when.apply(jQuery,g)};return e.then(j)},set:function(a,b,c){void 0===c&&(c=!1);var d,e=a._values[this.name];return void 0!==e?(d=e.model,e.destroy()):d=a.model.name==this.description.relation?a.model:new Sao.Model(this.description.relation),a._values[this.name]=void 0,this._set_default_value(a,d),this._set_value(a,b,c)},get:function(a){var b=a._values[this.name];if(void 0===b)return[];for(var c=b.record_removed,d=b.record_deleted,e=[],f=this.description.relation_field||"",g=[],h=[],i=[],j=0,k=b.length;j<k;j++){var l=b[j];if(!~c.indexOf(l)&&!~d.indexOf(l)){var m;l.id>=0?(m=l.get(),delete m[f],l.has_changed()&&!jQuery.isEmptyObject(m)&&(i.push([l.id]),i.push(m)),g.push(l.id)):(m=l.get(),delete m[f],h.push(m))}}return jQuery.isEmptyObject(g)||e.push(["add",g]),jQuery.isEmptyObject(h)||e.push(["create",h]),jQuery.isEmptyObject(i)||e.push(["write"].concat(i)),jQuery.isEmptyObject(c)||e.push(["remove",c.map(function(a){return a.id})]),jQuery.isEmptyObject(d)||e.push(["delete",d.map(function(a){return a.id})]),e},set_client:function(a,b,c){null===b&&(b=[]),"number"==typeof b&&(b=[b]);var d=this.get_eval(a);this._set_value(a,b),Sao.common.compare(d.sort(),b.sort())?c&&(a._changed[this.name]=!0,this.changed(a).done(function(){a.validate(null,!0).then(function(){a.group.root_group().screens.forEach(function(a){a.display()})})})):(a._changed[this.name]=!0,this.changed(a).done(function(){a.validate(null,!0).then(function(){a.group.changed()})}))},get_client:function(a){return this._set_default_value(a),a._values[this.name]},set_default:function(a,b){return a._changed[this.name]=!0,this.set(a,b,!0)},set_on_change:function(a,b){if(a._changed[this.name]=!0,this._set_default_value(a),b instanceof Array)return void this._set_value(a,b);var c=jQuery.when();if(b.add||b.update){var d=this.get_context(a),e=a._values[this.name].model.fields,f={},g=[];if(b.add)for(var h=0;h<b.add.length;h++)g.push(b.add[h][1]);if([g,b.update].forEach(function(a){jQuery.isEmptyObject(a)||a.forEach(function(a){Object.keys(a).forEach(function(a){a in e||"id"==a||(f[a]=!0)})})}),!jQuery.isEmptyObject(f)){var i={method:"model."+this.description.relation+".fields_get",params:[Object.keys(f),d]};c=Sao.rpc(i,a.model.session)}}var j=[],k=a._values[this.name];k.forEach(function(a){a.id||j.push(a)}),b.remove&&b.remove.forEach(function(a){var b=k.get(a);b&&j.push(b)}.bind(this)),j.forEach(function(a){k.remove(a,!1,!0,!1)}.bind(this)),(b.add||b.update)&&c.then(function(a){k.add_fields(a),b.add&&b.add.forEach(function(a){var b=a[0],c=a[1],d=k.new_(!1);k.add(d,b,!1),d.set_on_change(c)}),b.update&&b.update.forEach(function(a){if(a.id){var b=k.get(a.id);b&&b.set_on_change(a)}})}.bind(this))},_set_default_value:function(a,b){if(void 0===a._values[this.name]){b||(b=new Sao.Model(this.description.relation)),a.model.name==this.description.relation&&(b=a.model);var c=a.expr_eval(this.description.context||{}),d=Sao.Group(b,c,[]);d.set_parent(a),d.parent_name=this.description.relation_field,d.child_name=this.name,a._values[this.name]=d}},get_timestamp:function(a){var b=a._values[this.name];if(void 0===b)return{};for(var c,d={},e=0,f=b.length;e<f;e++)c=b[e],jQuery.extend(d,c.get_timestamp());return d},get_eval:function(a){var b=[],c=a._values[this.name];if(void 0===c)return b;for(var d=c.record_removed,e=c.record_deleted,f=0,g=a._values[this.name].length;f<g;f++){var h=c[f];~d.indexOf(h)||~e.indexOf(h)||b.push(h.id)}return b},get_on_change_value:function(a){var b=[],c=a._values[this.name];if(void 0===c)return b;for(var d=0,e=a._values[this.name].length;d<e;d++){var f=c[d];f.deleted()&&f.removed()||b.push(f.get_on_change_value([this.description.relation_field||""]))}return b},get_removed_ids:function(a){return a._values[this.name].record_removed.map(function(a){return a.id})},get_domain:function(a){return this.get_domains(a)[1]},validation_domains:function(a,b){return this.get_domains(a,b)[0]},validate:function(a,b,c){var d=!1,e=new Sao.common.DomainInversion,f=e.localize_domain(e.domain_inversion(a.group.clean4inversion(c||[]),this.name,Sao.common.EvalEnvironment(a)),this.name);"boolean"==typeof f&&(f=f?[]:[["id","=",null]]);for(var g=0,h=(a._values[this.name]||[]).length;g<h;g++){var i=a._values[this.name][g];!i.get_loaded()&&i.id>=0&&!c||(i.validate(null,b,f,!0)||(d="children"))}var j=Sao.field.One2Many._super.validate.call(this,a,b,c);return j&&d?(this.get_state_attrs(a).invalid=d,!1):j},set_state:function(a,b){this._set_default_value(a),Sao.field.One2Many._super.set_state.call(this,a,b)}}),Sao.field.Many2Many=Sao.class_(Sao.field.One2Many,{get_on_change_value:function(a){return this.get_eval(a)}}),Sao.field.Reference=Sao.class_(Sao.field.Field,{_default:null,get_client:function(a){if(a._values[this.name]){return[a._values[this.name][0],a._values[this.name+".rec_name"]||""]}return null},get:function(a){return a._values[this.name]&&a._values[this.name][0]&&a._values[this.name][1]>=-1?a._values[this.name].join(","):null},set_client:function(a,b,c){if(b){"string"==typeof b&&(b=b.split(","));var d,e=b[0],f=b[1];f instanceof Array?(d=f[1],f=f[0]):(f&&!isNaN(parseInt(f,10))&&(f=parseInt(f,10)),d=[e,f].join(",")==this.get(a)?a._values[this.name+".rec_name"]||"":""),a._values[this.name+".rec_name"]=d,b=[e,f]}Sao.field.Reference._super.set_client.call(this,a,b,c)},set:function(a,b){if(!b)return void(a._values[this.name]=this._default);var c,d;"string"==typeof b?(c=b.split(",")[0],d=b.split(",")[1],d?isNaN(parseInt(d,10))||(d=parseInt(d,10)):d=null):(c=b[0],d=b[1]);var e=a._values[this.name+".rec_name"]||"",f=function(b){a._values[this.name+".rec_name"]=b}.bind(this);c&&null!==d&&d>=0?!e&&d>=0&&Sao.rpc({method:"model."+c+".read",params:[[d],["rec_name"],a.get_context()]},a.model.session).done(function(a){f(a[0].rec_name)}):e=c?"":d,a._values[this.name]=[c,d],f(e)},get_on_change_value:function(a){return a.group.parent_name==this.name&&a.group.parent?[a.group.parent.model.name,a.group.parent.get_on_change_value([a.group.child_name])]:Sao.field.Reference._super.get_on_change_value.call(this,a)},get_context:function(a){var b=Sao.field.Reference._super.get_context.call(this,a);return this.description.datetime_field&&(b._datetime=a.get_eval()[this.description.datetime_field]),b},validation_domains:function(a,b){return this.get_domains(a,b)[0]},get_domain:function(a){var b=null;a._values[this.name]&&(b=a._values[this.name][0]);var c=this.get_domains(a),d=c[0],e=c[1],f=new Sao.common.DomainInversion;return f.concat([f.localize_domain(f.filter_leaf(d,this.name,b),!0),e])}}),Sao.field.Binary=Sao.class_(Sao.field.Field,{_default:null,get_size:function(a){var b=a._values[this.name]||0;return b instanceof Uint8Array?b.length:b},get_data:function(a){var b=a._values[this.name]||[],c=jQuery.when(b);if(!(b instanceof Uint8Array)){if(a.id<0)return c;var d=a.get_context();c=a.model.execute("read",[[a.id],[this.name]],d).then(function(a){return a[0][this.name]}.bind(this))}return c}}),Sao.field.Dict=Sao.class_(Sao.field.Field,{_default:{},set:function(a,b){if(b){var c=[];for(var d in b)c.push(d);c.sort();var e={};for(var f in c)d=c[f],e[d]=b[d];b=e}Sao.field.Dict._super.set.call(this,a,b)},get:function(a){return Sao.field.Dict._super.get.call(this,a)||this._default},get_client:function(a){return Sao.field.Dict._super.get_client.call(this,a)||this._default},validation_domains:function(a,b){return this.get_domains(a,b)[0]},get_domain:function(a){var b=new Sao.common.DomainInversion,c=this.get_domains(a),d=c[0],e=c[1];return b.concat([b.localize_domain(b.inverse_leaf(d)),e])},date_format:function(a){var b=this.get_context(a);return Sao.common.date_format(b.date_format)},time_format:function(a){return"%X"}})}(),function(){"use strict";Sao.Tab=Sao.class_(Object,{init:function(){Sao.Tab.tabs.push(this),this.buttons={},this.id="tab-"+Sao.Tab.counter++,this.name="",this.name_el=jQuery("<span/>")},create_tabcontent:function(){this.el=jQuery("<div/>",{class:this.class_});var a=this.create_toolbar().appendTo(this.el);this.title=a.find(".title"),this.content=jQuery("<div/>").appendTo(this.el),this.info_bar&&this.el.append(this.info_bar.el)},set_menu:function(a){this.menu_def().forEach(function(b){var c=b[0],d=b[1],e=b[2],f=jQuery("<li/>",{role:"presentation"}).appendTo(a),g=jQuery("<a/>",{role:"menuitem",href:"#",tabindex:-1}).append(jQuery("<span/>",{class:"glyphicon "+c,"aria-hidden":"true"})).append(" "+d).appendTo(f);e?g.click(function(){this[e]()}.bind(this)):f.addClass("disabled")}.bind(this))},create_toolbar:function(){var a=jQuery("<nav/>",{class:"toolbar navbar navbar-default",role:"toolbar"}).append(jQuery("<div/>",{class:"container-fluid"}).append(jQuery("<div/>",{class:"dropdown navbar-header navbar-left"}).append(jQuery("<a/>",{href:"#",class:"navbar-brand dropdown-toggle","data-toggle":"dropdown",role:"button","aria-expanded":!1,"aria-haspopup":!0}).append(jQuery("<span/>",{class:"title"})).append(jQuery("<span/>",{class:"caret"}))).append(jQuery("<ul/>",{class:"dropdown-menu",role:"menu"})).append(jQuery("<button/>",{type:"button",class:"close visible-xs visible-sm","aria-label":Sao.i18n.gettext("Close")}).append(jQuery("<span/>",{"aria-hidden":!0}).append("×")).click(function(){this.close()}.bind(this)))).append(jQuery("<div/>",{class:"btn-toolbar navbar-right",role:"toolbar"}))),b=jQuery("<div/>",{class:"toolbar-wrapper"}).append(a);this.set_menu(a.find('ul[role*="menu"]'));var c,d=function(b){if(!b)return void(c=null);c||(c=jQuery("<div/>",{class:"btn-group",role:"group"}).appendTo(a.find(".btn-toolbar"))),this.buttons[b[0]]=jQuery("<button/>",{type:"button",class:"btn btn-default navbar-btn",title:b[2],id:b[0]}).append(jQuery("<span/>",{class:"glyphicon "+b[1],"aria-hidden":"true"})).appendTo(c).data("toggle","tooltip").data("placement","bottom").tooltip(),b[3]?this.buttons[b[0]].click(this[b[3]].bind(this)):item.addClass("disabled")};this.toolbar_def().forEach(d.bind(this)),a.find(".btn-toolbar > .btn-group").last().addClass("hidden-xs");var e=jQuery("#tabs");return a.affix({target:e.parent(),offset:{top:function(){return jQuery("#main_navbar").height()}}}),a.on("affix.bs.affix",function(){b.height(jQuery("#main_navbar").height())}),a.on("affix-top.bs.affix affix-bottom.bs.affix",function(){b.height("")}),a.on("affixed.bs.affix",function(){Sao.Tab.affix_set_with(a)}),a.on("affixed-top.bs.affix affixed-bottom.bs.affix",function(){Sao.Tab.affix_unset_width(a)}),b},close:function(){var a=jQuery("#tabs"),b=jQuery("#tablist"),c=b.find("#nav-"+this.id),d=a.find("#"+this.id);return b.find('a[href="#'+this.id+'"]').tab("show"),this._close_allowed().then(function(){var b=c.nextAll("li").first();b.length||(b=c.prevAll("li").first()),c.tooltip("destroy").remove(),d.remove(),Sao.Tab.tabs.splice(Sao.Tab.tabs.indexOf(this),1),b&&b.find("a").tab("show"),a.trigger("ready")}.bind(this))},_close_allowed:function(){return jQuery.when()},set_name:function(a){this.name=a,this.name_el.text(Sao.common.ellipsize(a,20)),this.name_el.parents("li").first().attr("title",a).tooltip()}}),Sao.Tab.affix_set_with=function(a){var b=jQuery(a.parent()).width();a.css("width",b)},Sao.Tab.affix_unset_width=function(a){a.css("width","")},jQuery(window).resize(function(){jQuery(".toolbar").each(function(a,b){b=jQuery(b),b.affix("checkPosition"),b.hasClass("affix")?Sao.Tab.affix_set_with(b):Sao.Tab.affix_unset_width(b)})}),Sao.Tab.counter=0,Sao.Tab.tabs=[],Sao.Tab.tabs.close=function(a){if(a&&Sao.Tab.tabs.length)return Sao.common.sur.run(Sao.i18n.gettext("The following action requires to close all tabs.\nDo you want to continue?")).then(function(){return Sao.Tab.tabs.close(!1)});if(Sao.Tab.tabs.length){var b=Sao.Tab.tabs[0];return b.close().then(function(){return~Sao.Tab.tabs.indexOf(b)?jQuery.Deferred().reject():Sao.Tab.tabs.close()})}return Sao.main_menu_screen?Sao.main_menu_screen.save_tree_state().then(function(){Sao.main_menu_screen=null}):jQuery.when()},Sao.Tab.tabs.get_current=function(){var a=jQuery("#tablist"),b=a.find("li").index(a.find("li.active"));return Sao.Tab.tabs[b]},Sao.Tab.tabs.close_current=function(){this.get_current().close()},Sao.Tab.create=function(a){void 0===a.context&&(a.context={});var b;b=a.model?new Sao.Tab.Form(a.model,a):new Sao.Tab.Board(a),Sao.Tab.add(b)},Sao.Tab.add=function(a){var b=jQuery("#tabs"),c=jQuery("#tablist"),d=jQuery("#tabcontent"),e=jQuery("<a/>",{"aria-controls":a.id,role:"tab","data-toggle":"tab",href:"#"+a.id}).append(jQuery("<button/>",{class:"close"}).append(jQuery("<span/>",{"aria-hidden":!0}).append("×")).append(jQuery("<span/>",{class:"sr-only"}).append(Sao.i18n.gettext("Close"))).click(function(){a.close()})).append(a.name_el);jQuery("<li/>",{role:"presentation","data-toggle":"tooltip","data-placement":"bottom",id:"nav-"+a.id}).append(e).appendTo(c),jQuery("<div/>",{role:"tabpanel",class:"tab-pane",id:a.id}).html(a.el).appendTo(d),e.on("shown.bs.tab",function(){Sao.View.resize(a.el)}),e.tab("show"),b.trigger("ready")},Sao.Tab.Form=Sao.class_(Sao.Tab,{class_:"tab-form",init:function(a,b){Sao.Tab.Form._super.init.call(this);var c=new Sao.Screen(a,b);c.tab=this,this.screen=c,this.attributes=jQuery.extend({},b),this.info_bar=new Sao.Window.InfoBar,this.create_tabcontent(),this.set_buttons_sensitive(),this.view_prm=this.screen.switch_view().done(function(){this.set_name(b.name||""),this.content.append(c.screen_container.el),b.res_id?(jQuery.isArray(b.res_id)||(b.res_id=[b.res_id]),c.group.load(b.res_id),c.set_current_record(c.group.get(b.res_id)),c.display()):("form"==c.current_view.view_type&&c.new_(),~["tree","graph","calendar"].indexOf(c.current_view.view_type)&&c.search_filter()),this.update_revision()}.bind(this))},toolbar_def:function(){return[["new","glyphicon-edit",Sao.i18n.gettext("Create a new record"),"new_"],["save","glyphicon-save",Sao.i18n.gettext("Save this record"),"save"],["switch","glyphicon-list-alt",Sao.i18n.gettext("Switch view"),"switch_"],["reload","glyphicon-refresh",Sao.i18n.gettext("Reload"),"reload"],null,["previous","glyphicon-chevron-left",Sao.i18n.gettext("Previous Record"),"previous"],["next","glyphicon-chevron-right",Sao.i18n.gettext("Next Record"),"next"],null,["attach","glyphicon-paperclip",Sao.i18n.gettext("Add an attachment to the record"),"attach"],["note","glyphicon-comment",Sao.i18n.gettext("Add a note to the record"),"note"]]},menu_def:function(){return[["glyphicon-edit",Sao.i18n.gettext("New"),"new_"],["glyphicon-save",Sao.i18n.gettext("Save"),"save"],["glyphicon-list-alt",Sao.i18n.gettext("Switch"),"switch_"],["glyphicon-refresh",Sao.i18n.gettext("Reload/Undo"),"reload"],["glyphicon-duplicate",Sao.i18n.gettext("Duplicate"),"copy"],["glyphicon-trash",Sao.i18n.gettext("Delete"),"delete_"],["glyphicon-chevron-left",Sao.i18n.gettext("Previous"),"previous"],["glyphicon-chevron-right",Sao.i18n.gettext("Next"),"next"],["glyphicon-search",Sao.i18n.gettext("Search"),"search"],["glyphicon-time",Sao.i18n.gettext("View Logs..."),"logs"],["glyphicon-time",Sao.i18n.gettext("Show revisions..."),Sao.common.MODELHISTORY.contains(this.screen.model_name)?"revision":null],["glyphicon-remove",Sao.i18n.gettext("Close Tab"),"close"],["glyphicon-paperclip",Sao.i18n.gettext("Attachment"),"attach"],["glyphicon-comment",Sao.i18n.gettext("Note"),"note"],["glyphicon-cog",Sao.i18n.gettext("Action"),"action"],["glyphicon-share-alt",Sao.i18n.gettext("Relate"),"relate"],["glyphicon-print",Sao.i18n.gettext("Print"),"print"],["glyphicon-export",Sao.i18n.gettext("Export"),"export"],["glyphicon-import",Sao.i18n.gettext("Import"),"import"]]},create_toolbar:function(){var a=Sao.Tab.Form._super.create_toolbar.call(this),b=this.screen,c=this.buttons;return b.model.execute("view_toolbar_get",[],b.context).done(function(d){[["action","glyphicon-cog",Sao.i18n.gettext("Launch action")],["relate","glyphicon-share-alt",Sao.i18n.gettext("Open related records")],["print","glyphicon-print",Sao.i18n.gettext("Print report")]].forEach(function(e){var f=!1;"action"!=e[0]&&(f=!d[e[0]].length);var g=jQuery("<div/>",{class:"btn-group",role:"group"}).append(jQuery("<button/>",{type:"button",class:"btn btn-default navbar-btn dropdown-toggle","data-toggle":"dropdown","aria-expanded":!1,"aria-haspopup":!0,title:e[2],id:e[0],disabled:f}).append(jQuery("<span/>",{class:"glyphicon "+e[1],"aria-hidden":"true"})).append(jQuery("<span/>",{class:"caret"})).data("toggle","tooltip").data("placement","bottom").tooltip()).append(jQuery("<ul/>",{class:"dropdown-menu",role:"menu","aria-labelledby":e[0]})).appendTo(a.find(".btn-toolbar > .btn-group").last());c[e[0]]=g;var h=(g.on("show.bs.dropdown",function(){jQuery(this).parents(".btn-group").removeClass("hidden-xs")}).on("hide.bs.dropdown",function(){jQuery(this).parents(".btn-group").addClass("hidden-xs")}),g.find('ul[role*="menu"]'));"action"==e[0]&&g.click(function(){h.find(".action_button").remove(),b.get_buttons().forEach(function(a){jQuery("<li/>",{role:"presentation",class:"action_button"}).append(jQuery("<a/>",{role:"menuitem",href:"#",tabindex:-1}).append(a.attributes.string||"")).click(function(){b.button(a.attributes)}).appendTo(h)})}),d[e[0]].forEach(function(a){jQuery("<li/>",{role:"presentation"}).append(jQuery("<a/>",{role:"menuitem",href:"#",tabindex:-1}).append(a.name)).click(function(){b.save_current().then(function(){var c=jQuery.extend({},a),d=null;b.current_record&&(d=b.current_record.id);var f=b.current_view.selected_records().map(function(a){return a.id});c=Sao.Action.evaluate(c,e[0],b.current_record);var g={model:b.model_name,id:d,ids:f};Sao.Action.exec_action(c,g,b.context)})}).appendTo(h)})})}),a},_close_allowed:function(){return this.modified_save()},modified_save:function(){return this.screen.save_tree_state(),this.screen.current_view.set_value(),this.screen.modified()?Sao.common.sur_3b.run(Sao.i18n.gettext("This record has been modified\ndo you want to save it?")).then(function(a){switch(a){case"ok":return this.save();case"ko":return this.reload(!1);default:return jQuery.Deferred().reject()}}.bind(this)):jQuery.when()},new_:function(){Sao.common.MODELACCESS.get(this.screen.model_name).create&&this.modified_save().done(function(){this.screen.new_().then(function(){this.info_bar.message()}.bind(this))}.bind(this))},save:function(){var a=Sao.common.MODELACCESS.get(this.screen.model_name);return a.write||a.create?this.screen.save_current().then(function(){this.info_bar.message(Sao.i18n.gettext("Record saved."),"info"),this.screen.count_tab_domain()}.bind(this),function(){this.info_bar.message(this.screen.invalid_message(),"danger")}.bind(this)):jQuery.when()},switch_:function(){this.modified_save().done(function(){this.screen.switch_view()}.bind(this))},reload:function(a){void 0===a&&(a=!0);var b=function(){return this.screen.cancel_current().then(function(){return this.screen.save_tree_state(!1),"form"!=this.screen.current_view.view_type&&this.screen.search_filter(this.screen.screen_container.search_entry.val()),this.screen.count_tab_domain(),this.screen.display().then(function(){this.info_bar.message()}.bind(this))}.bind(this))}.bind(this);return a?this.modified_save().then(b):b()},copy:function(){Sao.common.MODELACCESS.get(this.screen.model_name).create&&this.modified_save().done(function(){this.screen.copy().then(function(){this.info_bar.message(Sao.i18n.gettext("Working now on the duplicated record(s)."),"info"),this.screen.count_tab_domain()}.bind(this))}.bind(this))},delete_:function(){if(Sao.common.MODELACCESS.get(this.screen.model_name).delete){var a;a="form"==this.screen.current_view.view_type?Sao.i18n.gettext("Are you sure to remove this record?"):Sao.i18n.gettext("Are you sure to remove those records?"),Sao.common.sur.run(a).done(function(){this.screen.remove(!0,!1,!0).then(function(){this.info_bar.message(Sao.i18n.gettext("Records removed."),"info"),this.screen.count_tab_domain()}.bind(this),function(){this.info_bar.message(Sao.i18n.gettext("Records not removed."),"danger")}.bind(this))}.bind(this))}},previous:function(){this.modified_save().done(function(){this.screen.display_previous(),this.info_bar.message()}.bind(this))},next:function(){this.modified_save().done(function(){this.screen.display_next(),this.info_bar.message()}.bind(this))},search:function(){var a=this.screen.screen_container.search_entry;a.is(":visible")&&window.setTimeout(function(){a.focus()},0)},logs:function(){var a=this.screen.current_record;if(!a||a.id<0)return void this.info_bar.message(Sao.i18n.gettext("You have to select one record."),"info");var b=[["id",Sao.i18n.gettext("ID:")],["create_uid.rec_name",Sao.i18n.gettext("Creation User:")],["create_date",Sao.i18n.gettext("Creation Date:")],["write_uid.rec_name",Sao.i18n.gettext("Latest Modification by:")],["write_date",Sao.i18n.gettext("Latest Modification Date:")]];this.screen.model.execute("read",[[a.id],b.map(function(a){return a[0]})],this.screen.context).then(function(a){a=a[0];var c="";b.forEach(function(b){var d=b[0],e=b[1],f=a[d]||"/";a[d]&&~["create_date","write_date"].indexOf(d)&&(f=Sao.common.format_datetime(Sao.common.date_format(),"%H:%M:%S",f)),c+=e+" "+f+"\n"}),c+=Sao.i18n.gettext("Model: ")+this.screen.model.name,Sao.common.message.run(c)}.bind(this))},revision:function(){var a=null;this.screen.current_record&&(a=this.screen.current_record.id);var b=function(b){return function(c){c&&c.add(1,"milliseconds"),"form"==this.screen.current_view.view_type&&c<b[b.length-1][0]&&(c=b[b.length-1][0]),c!=this.screen.context._datetime&&(this.screen.context._datetime=c,"form"!=this.screen.current_view.view_type?this.screen.search_filter(this.screen.screen_container.search_entry.val()):this.screen.new_group([a]),this.screen.display(!0),this.update_revision())}.bind(this)}.bind(this);this.modified_save().done(function(){var a=this.screen.current_view.selected_records().map(function(a){return a.id});this.screen.model.execute("history_revisions",[a],this.screen.context).then(function(a){new Sao.Window.Revision(a,b(a))})}.bind(this))},update_revision:function(){var a,b=this.screen.context._datetime;if(b){var c=Sao.common.date_format();b=Sao.common.format_datetime(c,"%H:%M:%S.%f",b),a=this.name+" @ "+b}else a=this.name;this.title.html(a),this.set_buttons_sensitive(b)},set_buttons_sensitive:function(a){if(a)["new","save"].forEach(function(a){this.buttons[a].parent().addClass("disabled")}.bind(this));else{var b=Sao.common.MODELACCESS.get(this.screen.model_name);[["new",b.create],["save",b.create||b.write]].forEach(function(a){var b=a[0];a[1]?this.buttons[b].parent().removeClass("disabled"):this.buttons[b].parent().addClass("disabled")}.bind(this))}},attach:function(){var a=this.screen.current_record;!a||a.id<0||new Sao.Window.Attachment(a,function(){this.update_attachment_count(!0)}.bind(this))},update_attachment_count:function(a){var b=this.screen.current_record;b?b.get_attachment_count(a).always(this.attachment_count.bind(this)):this.attachment_count(0)},attachment_count:function(a){var b=this.buttons.attach.find(".badge");b.length||(b=jQuery("<span/>",{class:"badge"}).appendTo(this.buttons.attach)),b.text(a);var c=this.screen.get_id();this.buttons.attach.prop("disabled",c<0||null===c)},note:function(){var a=this.screen.current_record;!a||a.id<0||new Sao.Window.Note(a,function(){this.update_unread_note(!0)}.bind(this))},update_unread_note:function(a){var b=this.screen.current_record;b?b.get_unread_note(a).always(this._unread_note.bind(this)):this._unread_note(0)},_unread_note:function(a){var b=this.buttons.note.find(".badge");b.length||(b=jQuery("<span/>",{class:"badge"}).appendTo(this.buttons.note)),b.text(a);var c=this.screen.get_id();this.buttons.note.prop("disabled",c<0||null===c)},record_message:function(){this.info_bar.message()},action:function(){window.setTimeout(function(){this.buttons.action.find("button").click()}.bind(this))},relate:function(){window.setTimeout(function(){this.buttons.relate.find("button").click()}.bind(this))},print:function(){window.setTimeout(function(){this.buttons.print.find("button").click()}.bind(this))},export:function(){new Sao.Window.Export(this.screen,this.screen.current_view.selected_records().map(function(a){return a.id}),this.screen.current_view.get_fields(),this.screen.context)},import:function(){new Sao.Window.Import(this.screen)}}),Sao.Tab.Board=Sao.class_(Sao.Tab,{class_:"tab-board",init:function(a){var b,c;Sao.Tab.Board._super.init.call(this),this.model=a.model,this.view_id=a.view_ids.length>0?a.view_ids[0]:null,this.context=a.context,this.name=a.name||"",this.dialogs=[],this.board=null,b=new Sao.Model("ir.ui.view"),c=b.execute("read",[[this.view_id],["arch"]],this.context),c.done(function(a){var b;b=jQuery(jQuery.parseXML(a[0].arch)),this.board=new Sao.View.Board(b,this.context),this.board.actions_prms.done(function(){var a,b,c;for(a=0,b=this.board.actions.length;a<b;a++)c=this.board.actions[a],c.screen.tab=this}.bind(this)),this.el.append(this.board.el)}.bind(this)),this.create_tabcontent(),this.set_name(this.name),this.title.html(this.name_el.text())},toolbar_def:function(){return[["reload","glyphicon-refresh",Sao.i18n.gettext("Reload"),"reload"]]},menu_def:function(){return[["glyphicon-refresh",Sao.i18n.gettext("Reload/Undo"),"reload"]]},reload:function(){this.board.reload()},record_message:function(){var a,b,c;for(b=this.board.actions.length,a=0,b=b;a<b;a++)c=this.board.actions[a],c.update_domain(this.board.actions)},attachment_count:function(){},note:function(){},update_unread_note:function(){}}),Sao.Tab.Wizard=Sao.class_(Sao.Tab,{class_:"tab-wizard",init:function(a){Sao.Tab.Wizard._super.init.call(this),this.wizard=a,this.set_name(a.name),a.tab=this,this.create_tabcontent(),this.title.html(this.name_el.text()),this.el.append(a.form)},create_toolbar:function(){return jQuery("<span/>")},_close_allowed:function(){var a=this.wizard,b=jQuery.when();a.state!==a.end_state&&a.end_state in a.states&&(b=a.response(a.end_state));var c=jQuery.Deferred();return b.always(function(){a.state===a.end_state?c.resolve():c.reject()}),c.promise()}})}(),function(){"use strict";Sao.ScreenContainer=Sao.class_(Object,{init:function(a){this.alternate_viewport=jQuery("<div/>",{class:"screen-container"}),this.alternate_view=!1,this.search_modal=null,this.search_form=null,this.last_search_text="",this.tab_domain=a||[],this.tab_counter=[],this.el=jQuery("<div/>",{class:"screen-container"}),this.filter_box=jQuery("<form/>",{class:"filter-box"}).submit(function(a){this.do_search(),a.preventDefault()}.bind(this));var b=jQuery("<div/>",{class:"row"}).appendTo(this.filter_box);this.el.append(this.filter_box),this.filter_button=jQuery("<button/>",{type:"button",class:"btn btn-default"}).append(Sao.i18n.gettext("Filters")),this.filter_button.click(this.search_box.bind(this)),this.search_entry=jQuery("<input/>",{class:"form-control",placeholder:Sao.i18n.gettext("Search")}),this.search_list=jQuery("<datalist/>"),this.search_list.uniqueId(),this.search_entry.attr("list",this.search_list.attr("id")),this.search_entry.keypress(this.key_press.bind(this)),this.search_entry.on("input",this.update.bind(this));var c=jQuery("<button/>",{type:"submit",class:"btn btn-default","aria-label":Sao.i18n.gettext("Search")}).append(jQuery("<span/>",{class:"glyphicon glyphicon-search"}));this.but_bookmark=jQuery("<button/>",{type:"button",class:"btn btn-default dropdown-toggle","data-toggle":"dropdown","aria-expanded":!1,"aria-label":Sao.i18n.gettext("Bookmarks"),id:"bookmarks"}).append(jQuery("<span/>",{class:"glyphicon glyphicon-bookmark","aria-hidden":!0}));var d=jQuery("<ul/>",{class:"dropdown-menu",role:"menu","aria-labelledby":"bookmarks"});if(this.but_bookmark.click(function(){d.children().remove();for(var a=this.bookmarks(),b=0;b<a.length;b++){var c=a[b][1],e=a[b][2];jQuery("<li/>",{role:"presentation"}).append(jQuery("<a/>",{role:"menuitem",href:"#",tabindex:-1}).append(c).click(e,this.bookmark_activate.bind(this))).appendTo(d)}}.bind(this)),this.but_star=jQuery("<button/>",{class:"btn btn-default",type:"button"}).append(jQuery("<span/>",{class:"glyphicon","aria-hidden":!0})).click(this.star_click.bind(this)),this.set_star(),jQuery("<div/>",{class:"input-group"}).append(jQuery("<span/>",{class:"input-group-btn"}).append(this.filter_button)).append(this.search_entry).append(this.search_list).append(jQuery("<span/>",{class:"input-group-btn"}).append(c).append(this.but_star).append(this.but_bookmark).append(d)).appendTo(jQuery("<div/>",{class:"col-sm-10 col-xs-12"}).appendTo(b)),this.but_prev=jQuery("<button/>",{type:"button",class:"btn btn-default","aria-label":Sao.i18n.gettext("Previous")}).append(jQuery("<span/>",{class:"glyphicon glyphicon-menu-left","aria-hidden":!0})),this.but_prev.click(this.search_prev.bind(this)),this.but_next=jQuery("<button/>",{type:"button",class:"btn btn-default","aria-label":Sao.i18n.gettext("Next")}).append(jQuery("<span/>",{class:"glyphicon glyphicon-menu-right","aria-hidden":!0})),this.but_next.click(this.search_next.bind(this)),jQuery("<div/>",{class:"btn-group",role:"group"}).append(this.but_prev).append(this.but_next).appendTo(jQuery("<div/>",{class:"col-sm-2 pull-right"}).appendTo(b)),this.content_box=jQuery("<div/>",{class:"content-box"}),jQuery.isEmptyObject(this.tab_domain))this.tab=null;else{this.tab=jQuery("<div/>",{class:"tab-domain"}).appendTo(this.el);var e=jQuery("<ul/>",{class:"nav nav-tabs",role:"tablist"}).appendTo(this.tab);jQuery("<div/>",{class:"tab-content"}).appendTo(this.tab);this.tab_domain.forEach(function(a,b){var c=a[0],d=jQuery("<span/>",{class:"badge"});jQuery("<li/>",{role:"presentation",id:"nav-"+b}).append(jQuery("<a/>",{"aria-controls":b,role:"tab","data-toggle":"tab",href:"#"+b}).append(c+" ").append(d)).appendTo(e);this.tab_counter.push(d)}.bind(this)),e.find("a:first").tab("show");var f=this;e.find("a").click(function(a){a.preventDefault(),jQuery(this).tab("show"),f.do_search(),f.screen.count_tab_domain()})}this.el.append(this.content_box)},set_text:function(a){this.search_entry.val(a),this.bookmark_match()},update:function(){var a=this.screen.domain_parser().completion(this.get_text());this.search_list.children().remove(),a.forEach(function(a){jQuery("<option/>",{value:a.trim()}).appendTo(this.search_list)},this)},set_star:function(a){var b=this.but_star.children("span.glyphicon");a?(b.removeClass("glyphicon-star-empty"),b.addClass("glyphicon-star"),this.but_star.attr("aria-label",Sao.i18n.gettext("Remove this bookmark"))):(b.removeClass("glyphicon-star"),b.addClass("glyphicon-star-empty"),this.but_star.attr("aria-label",Sao.i18n.gettext("Bookmark this filter")))},get_star:function(){return this.but_star.children("span.glyphicon").hasClass("glyphicon-star")},star_click:function(){var a=this.get_star(),b=this.screen.model_name,c=function(){this.bookmark_match(),this.but_bookmark.prop("disabled",jQuery.isEmptyObject(this.bookmarks()))}.bind(this);if(a){var d=this.bookmark_match();Sao.common.VIEW_SEARCH.remove(b,d).then(function(){c()})}else{var e=this.get_text();if(!e)return;Sao.common.ask.run(Sao.i18n.gettext("Bookmark Name:")).then(function(a){if(a){var d=this.screen.domain_parser().parse(e);Sao.common.VIEW_SEARCH.add(b,a,d).then(function(){c()}),this.set_text(this.screen.domain_parser().string(d))}}.bind(this))}},bookmarks:function(){return Sao.common.VIEW_SEARCH.get(this.screen.model_name).filter(function(a){return this.screen.domain_parser().stringable(a[2])}.bind(this))},
 bookmark_activate:function(a){var b=a.data;this.set_text(this.screen.domain_parser().string(b)),this.do_search()},bookmark_match:function(){var a=this.get_text();if(a){var b=this.screen.domain_parser().parse(a);this.but_star.prop("disabled",!a);for(var c=(this.get_star(),this.bookmarks()),d=0;d<c.length;d++){var e=c[d][0],f=(c[d][1],c[d][2]);if(this.screen.domain_parser().string(f)===a||Sao.common.compare(f,b))return this.set_star(!0),e}}this.set_star(!1)},search_prev:function(){this.screen.search_prev(this.get_text())},search_next:function(){this.screen.search_next(this.get_text())},get_tab_domain:function(){if(!this.tab)return[];var a=this.tab.find("li").index(this.tab.find("li.active"));return this.tab_domain[a][1]},set_tab_counter:function(a,b){if(!jQuery.isEmptyObject(this.tab_counter)&&this.tab&&(void 0!==b&&null!==b||(b=this.tab.find("li").index(this.tab.find("li.active"))),!(b<0))){var c=this.tab_counter[b];if(c.data("toggle","tooltip"),null===a)c.attr("title",""),c.text("");else{c.attr("title",a);var d=a;a>99&&(d="99+"),c.text(d)}c.tooltip()}},do_search:function(){return this.screen.search_filter(this.get_text())},key_press:function(a){window.setTimeout(function(){this.bookmark_match()}.bind(this))},set_screen:function(a){this.screen=a,this.but_bookmark.prop("disabled",jQuery.isEmptyObject(this.bookmarks())),this.bookmark_match()},show_filter:function(){this.filter_box.show(),this.tab&&this.tab.show()},hide_filter:function(){this.filter_box.hide(),this.tab&&this.tab.hide()},set:function(a){this.alternate_view?(this.alternate_viewport.children().detach(),this.alternate_viewport.append(a)):(this.content_box.children().detach(),this.content_box.append(a))},get_text:function(){return this.search_entry.val()},search_box:function(){var a=this.screen.domain_parser(),b=function(){this.search_modal.modal("hide");for(var b="",c=a.quote.bind(a),d=0;d<this.search_form.fields.length;d++){var e,f=this.search_form.fields[d][0],g=this.search_form.fields[d][1];switch(g.type){case"selection":case"date":case"datetime":case"time":e=g.get_value(c);break;default:e=c(g.val())}e&&(b+=c(f)+": "+e+" ")}this.set_text(b),this.do_search().then(function(){this.last_search_text=this.get_text()}.bind(this))}.bind(this);if(!this.search_modal){var c=new Sao.Dialog(Sao.i18n.gettext("Filters"),"","lg");this.search_modal=c.modal,this.search_form=c.content,this.search_form.addClass("form-horizontal"),this.search_form.submit(function(a){b(),a.preventDefault()});var d,e=[];for(var f in a.fields)d=a.fields[f],(d.searchable||void 0===d.searchable)&&e.push(d);var g=function(a){return function(b){jQuery("<option/>",{value:b,text:b}).appendTo(a)}},h="filter-"+this.screen.model_name+"-";this.search_form.fields=[];for(var i=0;i<e.length;i++){d=e[i];var j,k,l=jQuery("<div/>",{class:"form-group form-group-sm"}).append(jQuery("<label/>",{class:"col-sm-4 control-label",for:h+d.name,text:d.string})).appendTo(c.body);switch(d.type){case"boolean":k=j=jQuery("<select/>",{class:"form-control input-sm",id:h+d.name}),["",Sao.i18n.gettext("True"),Sao.i18n.gettext("False")].forEach(g(j));break;case"selection":k=new Sao.ScreenContainer.Selection(d.selection,h+d.name),j=k.el;break;case"date":case"datetime":case"time":var m,n=Sao.common.date_format();if("date"==d.type)m=n;else{var o=new Sao.PYSON.Decoder({}).decode(d.format);o=Sao.common.moment_format(o),"time"==d.type?m=o:"datetime"==d.type&&(m=n+" "+o)}k=new Sao.ScreenContainer.DateTimes(m,h+d.name),j=k.el;break;default:k=j=jQuery("<input/>",{class:"form-control input-sm",type:"text",placeholder:d.string,id:h+d.name})}jQuery("<div/>",{class:"col-sm-8"}).append(j).appendTo(l),this.search_form.fields.push([d.string,k,j])}jQuery("<button/>",{class:"btn btn-primary",type:"submit"}).append(Sao.i18n.gettext("Find")).click(b).appendTo(c.footer)}if(this.search_modal.modal("show"),this.last_search_text.trim()!==this.get_text().trim()){for(var p=0;p<this.search_form.fields.length;p++){var q=this.search_form.fields[p][1];switch(q.type){case"selection":q.set_value([]);break;case"date":case"datetime":case"time":q.set_value(null,null);break;default:q.val("")}}this.search_form.fields[0][2].focus()}}}),Sao.ScreenContainer.DateTimes=Sao.class_(Object,{type:"date",init:function(a,b){this.el=jQuery("<div/>",{class:"row",id:b});var c=function(c){var d=jQuery("<div/>",{class:"input-group input-group-sm"});return jQuery("<input/>",{class:"form-control input-sm",type:"text",placeholder:c,id:b+"-from"}).appendTo(d),jQuery("<span/>",{class:"input-group-btn"}).append(jQuery("<button/>",{class:"datepickerbutton btn btn-default",type:"button"}).append(jQuery("<span/>",{class:"glyphicon glyphicon-calendar"}))).appendTo(d),d.datetimepicker({locale:moment.locale()}),d.data("DateTimePicker").format(a),d};this.from=c("From").appendTo(jQuery("<div/>",{class:"col-md-5"}).appendTo(this.el)),jQuery("<p/>",{class:"text-center"}).append("..").appendTo(jQuery("<div/>",{class:"col-md-1"}).appendTo(this.el)),this.to=c("To").appendTo(jQuery("<div/>",{class:"col-md-5"}).appendTo(this.el))},_get_value:function(a){return a.find("input").val()},get_value:function(a){var b=this._get_value(this.from),c=this._get_value(this.to);return b&&c?b!==c?a(b)+".."+a(c):a(b):b?">="+a(b):c?"<="+a(c):void 0},set_value:function(a,b){this.from.data("DateTimePicker").date(a),this.to.data("DateTimePicker").date(b)}}),Sao.ScreenContainer.Selection=Sao.class_(Object,{type:"selection",init:function(a,b){this.el=jQuery("<select/>",{class:"form-control input-sm",multiple:!0,id:b}),a.forEach(function(a){jQuery("<option/>",{value:a[1],text:a[1]}).appendTo(this.el)}.bind(this))},get_value:function(a){var b=this.el.val();return b&&(b=jQuery.map(b,a).reduce(function(a,b){return a&&(a+=";"),a+b})),b},set_value:function(a){this.el.val(a)}}),Sao.Screen=Sao.class_(Object,{init:function(a,b){this.model_name=a,this.model=new Sao.Model(a,b),this.attributes=jQuery.extend({},b),this.view_ids=jQuery.extend([],b.view_ids),this.view_to_load=jQuery.extend([],b.mode||["tree","form"]),this.views=[],this.views_preload=b.views_preload||{},this.exclude_field=b.exclude_field,this.context=b.context||{},this.new_group(),this.current_view=null,this.current_record=null,this.domain=b.domain||[],this.context_domain=b.context_domain,this.size_limit=null,void 0===this.attributes.limit?this.limit=Sao.config.limit:this.limit=b.limit,this.offset=0,this.order=this.default_order=b.order;var c=Sao.common.MODELACCESS.get(a);c.write||c.create||(this.attributes.readonly=!0),this.search_count=0,this.screen_container=new Sao.ScreenContainer(b.tab_domain),this.context_screen=null,b.context_model&&(this.context_screen=new Sao.Screen(b.context_model,{mode:["form"],context:b.context}),this.context_screen_prm=this.context_screen.switch_view().then(function(){return jQuery("<div/>",{class:"row"}).append(jQuery("<div/>",{class:"col-md-12"}).append(this.context_screen.screen_container.el)).prependTo(this.screen_container.filter_box),this.context_screen.new_(!1).then(function(a){return a.default_get()})}.bind(this))),b.row_activate?this.row_activate=b.row_activate:this.row_activate=this.default_row_activate,this.tree_states={},this.tree_states_done=[],this.fields_view_tree={},this._domain_parser={},this.pre_validate=!1,this.tab=null,this.count_tab_domain()},load_next_view:function(){if(!jQuery.isEmptyObject(this.view_to_load)){var a;jQuery.isEmptyObject(this.view_ids)||(a=this.view_ids.shift());var b=this.view_to_load.shift();return this.add_view_id(a,b)}return jQuery.when()},add_view_id:function(a,b){var c;if(a&&this.views_preload[String(a)])c=this.views_preload[String(a)];else{if(a||!this.views_preload[b]){return this.model.execute("fields_view_get",[a,b],this.context).pipe(this.add_view.bind(this))}c=this.views_preload[b]}return this.add_view(c),jQuery.when()},add_view:function(a){var b=a.arch,c=a.fields,d=a.view_id,e=jQuery(jQuery.parseXML(b));"tree"==e.children().prop("tagName")&&(this.fields_view_tree[d]=a);var f="eager";"form"==e.children().prop("tagName")&&(f="lazy");for(var g in c)g in this.model.fields&&"eager"!=f?c[g].loading=this.model.fields[g].description.loading:c[g].loading=f;this.group.add_fields(c);var h=Sao.View.parse(this,e,a.field_childs);return h.view_id=d,this.views.push(h),h},number_of_views:function(){return this.views.length+this.view_to_load.length},switch_view:function(a){if(this.current_view){this.current_view.set_value(),this.current_record&&!~this.current_record.group.indexOf(this.current_record)&&(this.current_record=null);var b=this.current_view.get_fields();if(this.current_record&&this.current_view.editable&&!this.current_record.validate(b,!1,!1,!0))return this.screen_container.set(this.current_view.el),this.current_view.display().done(function(){this.set_cursor()}.bind(this))}var c=function(){if(!a||!this.current_view||this.current_view.view_type!=a)for(var b=function(){return this.current_view=this.views[this.views.length-1],c()}.bind(this),d=0;d<this.number_of_views();d++){if(this.view_to_load.length)return a||(a=this.view_to_load[0]),this.load_next_view().then(b);if(this.current_view=this.views[(this.views.indexOf(this.current_view)+1)%this.views.length],!a)break;if(this.current_view.view_type==a)break}return this.screen_container.set(this.current_view.el),this.display().done(function(){this.set_cursor()}.bind(this))}.bind(this);return c()},search_filter:function(a,b){if(b=b||!1,this.context_screen){if("pending"==this.context_screen_prm.state())return this.context_screen_prm.then(function(){return this.search_filter(a)}.bind(this));var c=this.context_screen.current_record;if(c&&!c.validate(null,!1,null,!0))return this.new_group([]),this.context_screen.display(!0),jQuery.when();this.context=jQuery.extend({},this.context,this.context_screen.get_on_change_value())}var d=this.search_domain(a,!0);if(this.context_domain){d=["AND",d,new Sao.PYSON.Decoder(this.context).decode(this.context_domain)]}var e=this.screen_container.get_tab_domain();jQuery.isEmptyObject(e)||(d=["AND",d,e]);var f=this.model.find(d,this.offset,this.limit,this.order,this.context),g=jQuery.when(this.search_count);return b||(g=this.model.execute("search_count",[d],this.context)),g.done(function(a){this.search_count=a}.bind(this)),f.done(this.set_group.bind(this)),f.done(this.display.bind(this)),jQuery.when(f,g).done(function(a,b){this.screen_container.but_next.prop("disabled",!(void 0!==this.limit&&a.length==this.limit&&b>this.limit+this.offset))}.bind(this)),this.screen_container.but_prev.prop("disabled",this.offset<=0),this.count_tab_domain(),f},search_domain:function(a,b){b=b||!1;var c=[];if(!this.group.parent&&this.domain_parser()){var d=this.domain_parser();c=a||""===a?d.parse(a):this.attributes.search_value,b&&this.screen_container.set_text(d.string(c))}else c=[["id","in",this.group.map(function(a){return a.id})]];return jQuery.isEmptyObject(c)?c=this.attributes.domain||[]:jQuery.isEmptyObject(this.attributes.domain)||(c=["AND",c,this.attributes.domain]),this.current_view&&"calendar"==this.current_view.view_type&&(c=jQuery.isEmptyObject(c)?this.current_view.current_domain():["AND",c,this.current_view.current_domain()]),c},count_tab_domain:function(){var a=this.search_domain(this.screen_container.get_text());this.screen_container.tab_domain.forEach(function(b,c){if(b[2]){var d=["AND",b[1],a];this.screen_container.set_tab_counter(null,c),this.group.model.execute("search_count",[d],this.context).then(function(a){this.screen_container.set_tab_counter(a,c)}.bind(this))}}.bind(this))},set_group:function(a){var b={};if(this.group){for(var c in this.group.model.fields)this.group.model.fields.hasOwnProperty(c)&&(b[c]=this.group.model.fields[c].description);this.group.screens.splice(this.group.screens.indexOf(this),1),jQuery.extend(a.on_write,this.group.on_write),a.on_write=a.on_write.filter(function(a,b,c){return b==c.indexOf(a)}),this.group.parent&&!a.parent&&(a.parent=this.group.parent)}a.screens.push(this),this.tree_states_done=[],this.group=a,this.model=a.model,a&&a.length?this.set_current_record(a[0]):this.set_current_record(null),this.group.add_fields(b)},new_group:function(a){var b=new Sao.Group(this.model,this.context,[]);b.set_readonly(this.attributes.readonly||!1),a&&b.load(a),this.set_group(b)},set_current_record:function(a){this.current_record=a,this.tab&&(a?(a.get_attachment_count().always(this.tab.attachment_count.bind(this.tab)),a.get_unread_note().always(this.tab.update_unread_note.bind(this.tab))):(this.tab.attachment_count(0),this.tab.update_unread_note(0)),this.tab.record_message())},display:function(a){var b=[];if(this.current_record&&~this.current_record.group.indexOf(this.current_record)||(this.group&&this.group.length&&"calendar"!=this.current_view.view_type?this.current_record=this.group[0]:this.current_record=null),this.views){var c=this.search_active(~["tree","graph","calendar"].indexOf(this.current_view.view_type));b.push(c);for(var d=0;d<this.views.length;d++)this.views[d]&&b.push(this.views[d].display())}return jQuery.when.apply(jQuery,b).then(function(){this.set_tree_state(),this.set_current_record(this.current_record),a&&this.set_cursor(!1,!1)}.bind(this))},display_next:function(){var a=this.current_view;if(a.set_value(),this.set_cursor(!1,!1),~["tree","form"].indexOf(a.view_type)&&this.current_record&&this.current_record.group){for(var b=this.current_record.group,c=this.current_record;b;){var d=b.indexOf(c);if(d<b.length-1){c=b[d+1];break}if(!b.parent||c.group.model_name!=b.parent.group.model_name)break;c=b.parent,b=b.parent.group}this.set_current_record(c)}else this.set_current_record(this.group[0]);this.set_cursor(!1,!1),a.display()},display_previous:function(){var a=this.current_view;if(a.set_value(),this.set_cursor(!1,!1),~["tree","form"].indexOf(a.view_type)&&this.current_record&&this.current_record.group){for(var b=this.current_record.group,c=this.current_record;b;){var d=b.indexOf(c);if(d>0){c=b[d-1];break}if(!b.parent||c.group.model_name!=b.parent.group.model_name)break;c=b.parent,b=b.parent.group}this.set_current_record(c)}else this.set_current_record(this.group[0]);this.set_cursor(!1,!1),a.display()},default_row_activate:function(){"tree"==this.current_view.view_type&&1==this.current_view.attributes.keyword_open?Sao.Action.exec_keyword("tree_open",{model:this.model_name,id:this.get_id(),ids:[this.get_id()]},jQuery.extend({},this.context),!1):this.modified()||this.switch_view("form")},get_id:function(){if(this.current_record)return this.current_record.id},new_:function(a,b){var c=this.current_view;void 0===a&&(a=!0);var d=jQuery.when();if("calendar"==this.current_view.view_type){var e=this.current_view.get_selected_date();d=this.switch_view("form")}return this.current_view&&("tree"==this.current_view.view_type&&!this.current_view.editable||"graph"==this.current_view.view_type)&&(d=this.switch_view("form")),d.then(function(){var d;d=this.current_record?this.current_record.group:this.group;var f,g=d.new_(!1,void 0,b);return f=a?g.default_get(b):jQuery.when(),f.then(function(){return d.add(g,this.new_model_position()),this.set_current_record(g),"calendar"==c.view_type&&c.set_default_date(g,e),this.display().done(function(){this.set_cursor(!0,!0)}.bind(this)),g}.bind(this))}.bind(this))},new_model_position:function(){var a=-1;return this.current_view&&"tree"==this.current_view.view_type&&"top"==this.current_view.attributes.editable&&(a=0),a},set_on_write:function(a){a&&(~this.group.on_write.indexOf(a)||this.group.on_write.push(a))},cancel_current:function(){var a=[];return this.current_record&&(this.current_record.cancel(),this.current_record.id<0&&a.push(this.remove(!1,!1,!1,[this.current_record]))),jQuery.when.apply(jQuery,a)},save_current:function(){var a=this.current_record;if(!a){if("tree"!=this.current_view.view_type||!this.group||!this.group.length)return jQuery.when();this.set_current_record(this.group[0])}this.current_view.set_value();var b=this.current_view.get_fields(),c=a.get_path(this.group),d=jQuery.Deferred();"tree"==this.current_view.view_type?d=this.group.save().then(function(){return this.current_record}.bind(this)):a.validate(b).then(function(b){b?a.save().then(function(){d.resolve(a)},d.reject):(this.current_view.display().done(this.set_cursor.bind(this)),d.reject())}.bind(this));var e=jQuery.Deferred();return d.then(function(a){return c&&a&&a.id&&c.splice(-1,1,[c[c.length-1][0],a.id]),this.group.get_by_path(c).then(function(a){this.set_current_record(a)}.bind(this))}.bind(this)).then(function(){this.display().always(e.resolve)}.bind(this),function(){this.display().always(e.reject)}.bind(this)),e.promise()},set_cursor:function(a,b){this.current_view&&~["tree","form"].indexOf(this.current_view.view_type)&&this.current_view.set_cursor(a,b)},modified:function(){var a=function(a){return a.has_changed()||a.id<0};if("tree"!=this.current_view.view_type){if(this.current_record&&a(this.current_record))return!0}else if(this.group.some(a))return!0;return!1},unremove:function(){this.current_view.selected_records().forEach(function(a){a.group.unremove(a)})},remove:function(a,b,c,d){var e=jQuery.when();if(d=d||this.current_view.selected_records(),jQuery.isEmptyObject(d))return e;a&&(e=this.model.delete_(d));var f=d[0],g=f.group,h=g.indexOf(f),i=f.get_path(this.group);return e.then(function(){d.forEach(function(a){a.group.remove(a,b,!0,c)});var e=[];if(a&&d.forEach(function(a){a.group.parent&&e.push(a.group.parent.save(!1)),~a.group.record_deleted.indexOf(a)&&a.group.record_deleted.splice(a.group.record_deleted.indexOf(a),1),~a.group.record_removed.indexOf(a)&&a.group.record_removed.splice(a.group.record_removed.indexOf(a),1)}),h>0){var f=g[h-1];i.splice(-1,1,[i[i.length-1][0],f.id])}else i.splice(-1,1);return jQuery.isEmptyObject(i)?this.group.length&&this.set_current_record(this.group[0]):e.push(this.group.get_by_path(i).then(function(a){this.set_current_record(a)}.bind(this))),jQuery.when.apply(jQuery,e).then(function(){this.display().done(function(){this.set_cursor()}.bind(this))}.bind(this))}.bind(this))},copy:function(){var a=jQuery.Deferred(),b=this.current_view.selected_records();return this.model.copy(b,this.context).then(function(b){this.group.load(b),jQuery.isEmptyObject(b)||this.set_current_record(this.group.get(b[0])),this.display().always(a.resolve)}.bind(this),a.reject),a.promise()},search_active:function(a){return a&&!this.group.parent?(this.screen_container.set_screen(this),this.screen_container.show_filter()):this.screen_container.hide_filter(),jQuery.when()},domain_parser:function(){var a,b,c;if((a=this.current_view?this.current_view.view_id:null)in this._domain_parser)return this._domain_parser[a];a in this.fields_view_tree?b=this.fields_view_tree[a]:(this.model.execute("fields_view_get",[!1,"tree"],this.context).then(function(b){this.fields_view_tree[a]=b,c.update_fields(b.fields)}.bind(this)),b={},b.fields={});var d=jQuery.extend({},b.fields),e=function(a){return function(b){a.selection=b}};for(var f in d){var g=d[f];"selection"!=g.type&&"reference"!=g.type||(g.selection instanceof Array||this.get_selection(g).then(e(g)))}if("arch"in b){var h=jQuery(jQuery.parseXML(b.arch)),i=h.find("tree").children().filter(function(a,b){return"field"==b.tagName}).map(function(a,b){return b.getAttribute("name")}),j={};i.each(function(a,b){j[b]=d[b]}),d=j}[["id",Sao.i18n.gettext("ID"),"integer"],["create_uid",Sao.i18n.gettext("Creation User"),"many2one"],["create_date",Sao.i18n.gettext("Creation Date"),"datetime"],["write_uid",Sao.i18n.gettext("Modification User"),"many2one"],["write_date",Sao.i18n.gettext("Modification Date"),"datetime"]].forEach(function(a){var b=a[0],c=a[1],e=a[2];b in d||(d[b]={string:c,name:b,type:e},"datetime"==e&&(d[b].format='"%H:%M:%S"'))});var k=jQuery.extend({},this.model.session.context,this.context);return c=new Sao.common.DomainParser(d,k),this._domain_parser[a]=c,c},get_selection:function(a){var b,c=a.selection_change_with;if(jQuery.isEmptyObject(c))b=this.model.execute(a.selection,[]);else{var d={};c.forEach(function(a){d[a]=null}),b=this.model.execute(a.selection,[d])}return b.then(function(a){return a.sort(function(a,b){return a[1].localeCompare(b[1])})})},search_prev:function(a){this.limit&&(this.offset-=this.limit),this.search_filter(a)},search_next:function(a){this.limit&&(this.offset+=this.limit),this.search_filter(a)},invalid_message:function(a){a||(a=this.current_record);var b={};for(var c in a.model.fields){var d=a.model.fields[c];b[c]=d.description}var e=new Sao.common.DomainParser(b),f=[],g=a.invalid_fields();return Object.keys(g).sort().forEach(function(b){var c=g[b],d=a.model.fields[b].description.string;"required"==c||Sao.common.compare(c,[[b,"!=",null]])?f.push(Sao.i18n.gettext('"%1" is required',d)):"domain"==c?f.push(Sao.i18n.gettext('"%1" is not valid according to its domain',d)):"children"==c?f.push(Sao.i18n.gettext('The values of "%1" are not valid',d)):e.stringable(c)?f.push(e.string(c)):f.push(Sao.i18n.gettext('"%1" is not valid according to its domain'),d)}),f.length>5&&(f.splice(5,f.length),f.push("...")),f.join("\n")},get:function(){return this.current_record?(this.current_view.set_value(),this.current_record.get()):null},get_on_change_value:function(){return this.current_record?(this.current_view.set_value(),this.current_record.get_on_change_value()):null},reload:function(a,b){this.group.reload(a),b&&this.group.written(a),this.group.parent&&this.group.parent.root_parent().reload(),this.display()},get_buttons:function(){var a=this.current_view.selected_records();if(jQuery.isEmptyObject(a))return[];var b=this.current_view.get_buttons();return a.forEach(function(a){b=b.filter(function(b){if(a.group.get_readonly()||a.readonly())return!1;if("instance"===b.attributes.type)return!1;var c=a.expr_eval(b.attributes.states||{});return!(c.invisible||c.readonly)})}),b},button:function(a){var b,c=function(a){this.reload(b,!0),"string"==typeof a?this.client_action(a):a&&Sao.Action.execute(a,{model:this.model_name,id:this.current_record.id,ids:b},null,this.context,!0)},d=this.current_view.selected_records();this.current_view.set_value();for(var e=this.current_view.get_fields(),f=[],g=function(a){return function(){this.display(!0),a.validate(e)}.bind(this)}.bind(this),h=0;h<d.length;h++){var i=d[h],j=i.expr_eval(a.states||{}).pre_validate||[];f.push(i.validate(e,!1,j))}jQuery.when.apply(jQuery,f).then(function(){for(var e,f=0;f<d.length;f++){e=d[f];if(!arguments[f])return void Sao.common.warning.run(this.invalid_message(e),Sao.i18n.gettext("Pre-validation")).then(g(e))}var h=jQuery.when();void 0!==a.confirm&&(h=Sao.common.sur.run(a.confirm)),h.then(function(){var e=this.current_record;if("instance"===a.type){var g=e.expr_eval(a.change||[]),h=e._get_on_change_args(g);e.model.execute(a.name,[h],this.context).then(function(a){e.set_on_change(a),e.group.root_group().screens.forEach(function(a){a.display()})})}else e.save(!1).done(function(){var g=jQuery.extend({},this.context);for(g._timestamp={},b=[],f=0;f<d.length;f++)e=d[f],jQuery.extend(g._timestamp,e.get_timestamp()),b.push(e.id);e.model.execute(a.name,[b],g).then(c.bind(this))}.bind(this))}.bind(this))}.bind(this))},client_action:function(a){var b=Sao.common.MODELACCESS.get(this.model_name);if("new"==a)b.create&&this.new_();else if("delete"==a)b.delete&&this.remove(!this.group.parent,!1,!this.group.parent);else if("remove"==a)b.write&&b.read&&this.group.parent&&this.remove(!1,!0,!1);else if("copy"==a)b.create&&this.copy();else if("next"==a)this.display_next();else if("previous"==a)this.display_previous();else if("close"==a)Sao.Tab.close_current();else if(a.startsWith("switch")){var c=a.split(" ")[1];this.switch_view(c)}else"reload"==a?~["tree","graph","calendar"].indexOf(this.current_view.view_type)&&!this.group.parent&&this.search_filter():"reload menu"==a?Sao.get_preferences().then(function(a){Sao.menu(a)}):"reload context"==a&&Sao.get_preferences()},save_tree_state:function(a){var b,c=[];a=void 0===a||a;var d,e,f,g,h,i,j=this.group.parent?this.group.parent.id:null,k=this.group.parent?this.group.parent._timestamp:null;for(d=0,e=this.views.length;d<e;d++)if(f=this.views[d],"form"==f.view_type){for(var l in f.widgets)if(f.widgets.hasOwnProperty(l))for(g=f.widgets[l],h=0,i=g.length;h<i;h++)g[h].screen&&(b=g[h].screen.save_tree_state(a),c.push(b));1==this.views.length&&this.current_record&&(j in this.tree_states||(this.tree_states[j]={}),this.tree_states[j][f.children_field||null]=[k,[],[[this.current_record.id]]])}else if("tree"==f.view_type){var m=f.get_expanded_paths(),n=f.get_selected_paths();if(j in this.tree_states||(this.tree_states[j]={}),this.tree_states[j][f.children_field||null]=[k,m,n],a&&f.attributes.tree_state){var o=new Sao.Model("ir.ui.view_tree_state");b=o.execute("set",[this.model_name,this.get_tree_domain(j),f.children_field,JSON.stringify(m),JSON.stringify(n)],{}),c.push(b)}}return jQuery.when.apply(jQuery,c)},get_tree_domain:function(a){var b;return b=a?(this.domain||[]).concat([[this.exclude_field,"=",a]]):this.domain,JSON.stringify(Sao.rpc.prepareObject(b))},set_tree_state:function(){var a,b,c,d,e,f=this.current_view;if(~["tree","form"].indexOf(f.view_type)&&!~this.tree_states_done.indexOf(f)&&("form"!=f.view_type||jQuery.isEmptyObject(this.tree_states_done))){if("tree"==f.view_type&&!f.attributes.tree_state)return void this.tree_states_done.push(f);a=this.group.parent?this.group.parent.id:null,a<0||(b=parent?parent._timestamp:null,a in this.tree_states||(this.tree_states[a]={}),c=this.tree_states[a][f.children_field||null],c&&b!=c[0]&&(c=void 0),void 0===c?(e=new Sao.Model("ir.ui.view_tree_state"),d=e.execute("get",[this.model_name,this.get_tree_domain(a),f.children_field],{}).then(function(a){return[b,JSON.parse(a[0]),JSON.parse(a[1])]})):d=jQuery.when(c),d.done(function(b){var c,d,e;if(this.tree_states[a][f.children_field||null]=b,c=b[1],d=b[2],"tree"==f.view_type)f.display(d,c);else if(!jQuery.isEmptyObject(d)){for(var g=0;g<d[0].length;g++){var h=this.group.get(d[0][g]);if(!h)break;e=h}e&&e!=this.current_record&&(this.set_current_record(e),f.display())}}.bind(this)),this.tree_states_done.push(f))}}})}(),function(){"use strict";Sao.View=Sao.class_(Object,{init:function(a,b){this.screen=a,this.view_type=null,this.el=null,this.view_id=null,this.fields={};var c=b.children()[0].attributes;this.attributes={};for(var d=0,e=c.length;d<e;d++){var f=c[d];this.attributes[f.name]=f.value}a.set_on_write(this.attributes.on_write)},set_value:function(){},get_fields:function(){return Object.keys(this.fields)},selected_records:function(){return[]},get_buttons:function(){return[]}}),Sao.View.idpath2path=function(a,b){var c,d=[];if(!b)return[];for(var e=0,f=a.rows.length;e<f;e++)if(a.rows[e].record.id==b[0]){d.push(e),c=Sao.View.idpath2path(a.rows[e],b.slice(1,b.length)),d=d.concat(c);break}return d},Sao.View.parse=function(a,b,c){switch(b.children().prop("tagName")){case"tree":return new Sao.View.Tree(a,b,c);case"form":return new Sao.View.Form(a,b);case"graph":return new Sao.View.Graph(a,b);case"calendar":return new Sao.View.Calendar(a,b)}},Sao.View.resize=function(a){a||(a=jQuery(document)),a.find(".treeview").each(function(){var a=jQuery(this);a.css("width","100%"),a.children(".tree").css("table-layout","fixed")}),a.find(".treeview").each(function(){var a=jQuery(this);a.width()&&(a.css("width",a.width()),a.children(".tree").css("table-layout","auto"))})},jQuery(window).resize(function(){Sao.View.resize()})}(),function(){"use strict";Sao.View.Form=Sao.class_(Sao.View,{editable:!0,init:function(a,b){Sao.View.Form._super.init.call(this,a,b),this.view_type="form",this.el=jQuery("<div/>",{class:"form"}),this.widgets={},this.widget_id=0,this.state_widgets=[],this.containers=[],this.notebooks=[];var c=b.children()[0],d=this.parse(a.model,c);this.el.append(d.el)},_parse_node:function(a,b,c,d,e){var f;switch(b.tagName){case"image":this._parse_image(a,b,c,d);break;case"separator":this._parse_separator(a,b,c,d);break;case"label":f=this._parse_label(a,b,c,d),d.name&&f&&(e[d.name]=f);break;case"newline":c.add_row();break;case"button":this._parse_button(b,c,d);break;case"notebook":this._parse_notebook(a,b,c,d);break;case"page":this._parse_page(a,b,c,d);break;case"field":if(f=this._parse_field(a,b,c,d),d.name in e&&f&&f.labelled){var g=e[d.name];g.el.uniqueId(),f.labelled.uniqueId(),f.labelled.attr("aria-labelledby",g.el.attr("id")),g.el.attr("for",f.labelled.attr("id"))}break;case"group":this._parse_group(a,b,c,d);break;case"hpaned":this._parse_paned(a,b,c,d,"horizontal");break;case"vpaned":this._parse_paned(a,b,c,d,"vertical");break;case"child":this._parse_child(a,b,c,d)}},parse:function(a,b,c){void 0===c&&(c=new Sao.View.Form.Container(Number(b.getAttribute("col")||4)),this.containers.push(c));var d={},e=function(b,e){for(var f={},g=0,h=e.attributes.length;g<h;g++){var i=e.attributes[g];f[i.name]=i.value}["readonly","invisible"].forEach(function(a){f[a]&&(f[a]=1==f[a])}),["yexpand","yfill","xexpand","xfill","colspan"].forEach(function(a){f[a]&&(f[a]=Number(f[a]))}),this._parse_node(a,e,c,f,d)};return jQuery(b).children().each(e.bind(this)),c},_parse_image:function(a,b,c,d){var e=new Sao.View.Form.Image_(d);this.state_widgets.push(e),c.add(d,e)},_parse_separator:function(a,b,c,d){var e=d.name,f=d.string;e in a.fields&&(!d.states&&e in a.fields&&(d.states=a.fields[e].description.states),f||(f=a.fields[e].description.string));var g=new Sao.View.Form.Separator(f,d);this.state_widgets.push(g),c.add(d,g)},_parse_label:function(a,b,c,d){var e=d.name,f=d.string;if(void 0===d.xexpand&&(d.xexpand=0),e in a.fields){if(e==this.screen.exclude_field)return void c.add(d);!d.states&&e in a.fields&&(d.states=a.fields[e].description.states),f||(f=a.fields[e].description.string+": "),void 0===d.xalign&&(d.xalign=1)}var g;return f&&(g=new Sao.View.Form.Label(f,d),this.state_widgets.push(g)),c.add(d,g),g},_parse_button:function(a,b,c){var d=new Sao.common.Button(c);this.state_widgets.push(d),b.add(c,d),d.el.click(d,this.button_clicked.bind(this))},_parse_notebook:function(a,b,c,d){void 0===d.colspan&&(d.colspan=4);var e=new Sao.View.Form.Notebook(d);this.notebooks.push(e),this.state_widgets.push(e),c.add(d,e),this.parse(a,b,e)},_parse_page:function(a,b,c,d){d.string;if(d.name in a.fields){var e=a.fields[d.name];if(d.name==this.screen.exclude_field)return;["states","string"].forEach(function(a){void 0===d[a]&&void 0!==e.description[a]&&(d[a]=e.description[a])})}var f=this.parse(a,b);f=new Sao.View.Form.Page(c.add(f.el,d.string),d),this.state_widgets.push(f)},_parse_field:function(a,b,c,d){var e=d.name;if(!(e in a.fields)||e==this.screen.exclude_field)return void c.add(d);d.widget||(d.widget=a.fields[e].description.type);var f=["relation","domain","selection","help","relation_field","string","views","add_remove","sort","context","size","filename","autocomplete","translate","create","delete","selection_change_with","schema_model"];for(var g in f){var h=f[g];h in a.fields[e].description&&null===b.getAttribute(h)&&(d[h]=a.fields[e].description[h])}var i=Sao.View.form_widget_get(d.widget);if(!i)return void c.add(d);var j=new i(e,a,d);return j.position=this.widget_id+=1,j.view=this,c.add(d,j),void 0===this.widgets[e]&&(this.widgets[e]=[]),this.widgets[e].push(j),this.fields[e]=!0,j},_parse_group:function(a,b,c,d){var e=new Sao.View.Form.Group(d);e.add(this.parse(a,b)),this.state_widgets.push(e),c.add(d,e)},_parse_paned:function(a,b,c,d,e){void 0===d.yexpand&&(d.yexpand=!0),void 0===d.yfill&&(d.yfill=!0);var f=new Sao.common.Paned(e);c.add(d,f),this.parse(a,b,f)},_parse_child:function(a,b,c,d){var e,f=this.parse(a,b);e=c.get_child1().children().length?c.get_child2():c.get_child1(),e.append(f.el)},get_buttons:function(){var a=[];for(var b in this.state_widgets){var c=this.state_widgets[b];c instanceof Sao.common.Button&&a.push(c)}return a},display:function(){var a,b,c=this.screen.current_record,d={};if(c){var e=[];for(b in c.model.fields)a=c.model.fields[b],e.push([b,a.description.loading||"eager"]);e.sort(function(a,b){return a[1].localeCompare(b[1])}),e.forEach(function(a){var b=a[0]
 ;d[b]=c.load(b)})}var f=function(a,b,c){var e=jQuery.when();c in d&&(e=d[c]),e.done(function(){b.set_state(a)})},g=function(a,b,c){return function(e){var f=jQuery.when();c in d&&(f=d[c]),f.done(function(){e.display(a,b)})}};for(b in this.widgets){var h=this.widgets[b];a=null,c&&(a=c.model.fields[b]),a&&f(c,a,b),h.forEach(g(c,a,b))}return jQuery.when.apply(jQuery,jQuery.map(d,function(a){return a})).done(function(){var a;for(a in this.state_widgets){this.state_widgets[a].set_state(c)}for(a in this.containers){this.containers[a].resize()}Sao.View.resize(this.el)}.bind(this))},set_value:function(){var a=this.screen.current_record;if(a){var b=function(b){b.set_value(a,this)};for(var c in this.widgets)if(c in a.model.fields){var d=this.widgets[c],e=a.model.fields[c];d.forEach(b,e)}}},button_clicked:function(a){var b=a.data;b.el.prop("disabled",!0);try{this.screen.button(b.attributes)}finally{b.el.prop("disabled",!1)}},selected_records:function(){return this.screen.current_record?[this.screen.current_record]:[]},set_cursor:function(a,b){var c,d,e,f,g,h,i,j,k,l=jQuery(document.activeElement),m=l.closest(this.el)>0;if(b||m){if(b)for(c=0;c<this.notebooks.length;c++)g=this.notebooks[c],g.set_current_page(0);this.attributes.cursor in this.widgets?f=Sao.common.find_focusable_child(this.widgets[this.attributes.cursor][0].el):(h=Sao.common.find_focusable_child(this.el))&&h.focus()}var n=this.screen.current_record;if(n){var o=[],p=this.el.find(".has-error"),q=n.invalid_fields();for(d in q)for(i=this.widgets[d],c=0;c<p.length;c++)for(j=jQuery(p[c]),e=0;e<i.length;e++)if(j.closest(i[e].el).length>0){o.push(j);break}o.length>0&&(f=Sao.common.find_first_focus_widget(this.el,o))}if(f){for(c=0;c<this.notebooks.length;c++)for(g=this.notebooks[c],k=g.get_n_pages(),e=0;e<k;e++)if(h=g.get_nth_page(e),jQuery(f).closest(h).length>0){g.set_current_page(e);break}jQuery(f).find("input,select,textarea").focus()}}}),Sao.View.Form.Container=Sao.class_(Object,{init:function(a){void 0===a&&(a=4),a<0&&(a=0),this.col=a,this.el=jQuery("<table/>",{class:"form-container responsive responsive-noheader"}),this.add_row()},add_row:function(){this.el.append(jQuery("<tr/>"))},rows:function(){return this.el.children().children("tr")},row:function(){return this.rows().last()},add:function(a,b){var c=a.colspan;void 0===c&&(c=1);var d=a.xfill;void 0===d&&(d=1);var e=a.xexpand;void 0===e&&(e=1);var f=this.row();if(this.col>0){var g=0;f.children().map(function(a,b){g+=Number(jQuery(b).attr("colspan")||1)}),g+c>this.col&&(this.add_row(),f=this.row())}var h;b&&(h=b.el);var i=jQuery("<td/>",{colspan:c,class:b?b.class_||"":""}).append(h);f.append(i),b&&(a.yfill&&i.css("vertical-align","top"),void 0!==a.xalign&&i.css("text-align",a.xalign>=.5?"right":"left"),e&&(i.addClass("xexpand"),i.css("width","100%")),d&&(i.addClass("xfill"),e&&h.css("width","100%")),a.help&&(b.el.data("toggle","tooltip"),b.el.attr("title",a.help),b.el.tooltip()))},resize:function(){var a,b,c=this.rows().toArray(),d=[],e=this.col,f=!1,g=function(b){b=jQuery(b);var c=[];return a=0,b.children().map(function(){var b=jQuery(this),d=Math.min(Number(b.attr("colspan")),e);b.hasClass("xexpand")&&!jQuery.isEmptyObject(b.children())&&"none"!=b.children(":not(.tooltip)").css("display")&&c.push([b,a]),a+=d}),c};c.sort(function(a,b){if(a=g(a),b=g(b),a.length==b.length){var c=function(a,b){var c=b[0];return a+Math.min(Number(c.attr("colspan")),e)};return a.reduce(c,0)-b.reduce(c,0)}return b.length-a.length}),c.forEach(function(c){c=jQuery(c);var h=g(c),i=100/h.length;h.forEach(function(c){var f=c[0];a=c[1];var g=Math.min(Number(f.attr("colspan")),e),h=0;for(b=0;b<g;b++)h+=d[a+b]||0;for(b=0;b<g;b++)if(h){if(h>i){var j=h-i;d[a+b]&&(d[a+b]-=j/(h/d[a+b]))}}else d[a+b]=i/g}),jQuery.isEmptyObject(h)||(f=!0)}),c.forEach(function(c){c=jQuery(c),a=0,c.children().map(function(){var c=jQuery(this),f=Math.min(Number(c.attr("colspan")),e);if(c.hasClass("xexpand")&&"none"!=c.children(":not(.tooltip)").css("display")){var g=0;for(b=0;b<f;b++)g+=d[a+b]||0;c.css("width",g+"%")}else c.css("width","");"none"==c.children().css("display")?c.css("visibility","collapse"):c.css("visibility","visible"),a+=f})}),f?this.el.css("width","100%"):this.el.css("width","")}}),Sao.View.Form.StateWidget=Sao.class_(Object,{init:function(a){this.attributes=a},set_state:function(a){var b;b=a?a.expr_eval(this.attributes.states||{}):{};var c=b.invisible;void 0===c&&(c=this.attributes.invisible),c?this.hide():this.show()},show:function(){this.el.show()},hide:function(){this.el.hide()}}),Sao.View.Form.LabelMixin=Sao.class_(Sao.View.Form.StateWidget,{set_state:function(a){Sao.View.Form.LabelMixin._super.set_state.call(this,a);var b;if(this.attributes.name&&a&&(b=a.model.fields[this.attributes.name]),void 0===this.attributes.string&&b){var c="";a&&(c=b.get_client(a)||""),this.label_el.val(c)}var d;d=a?a.expr_eval(this.attributes.states||{}):{},b&&b.description.readonly||d.readonly,Sao.common.apply_label_attributes(this.label_el,b&&b.description.readonly||d.readonly,b&&b.description.required||d.required)}}),Sao.View.Form.Separator=Sao.class_(Sao.View.Form.LabelMixin,{init:function(a,b){Sao.View.Form.Separator._super.init.call(this,b),this.el=jQuery("<div/>",{class:"form-separator"}),this.label_el=jQuery("<label/>"),a&&this.label_el.text(a),this.el.append(this.label_el),this.el.append(jQuery("<hr/>"))}}),Sao.View.Form.Label=Sao.class_(Sao.View.Form.LabelMixin,{class_:"form-label",init:function(a,b){Sao.View.Form.Label._super.init.call(this,b),this.el=this.label_el=jQuery("<label/>",{text:a,class:this.class_})}}),Sao.View.Form.Notebook=Sao.class_(Sao.View.Form.StateWidget,{class_:"form-notebook",init:function(a){Sao.View.Form.Notebook._super.init.call(this,a),this.el=jQuery("<div/>",{class:this.class_}),this.nav=jQuery("<ul/>",{class:"nav nav-tabs",role:"tablist"}).appendTo(this.el),this.panes=jQuery("<div/>",{class:"tab-content"}).appendTo(this.el),this.selected=!1},add:function(a,b){var c=jQuery("<div/>",{role:"tabpanel",class:"tab-pane"}).uniqueId(),d=c.attr("id"),e=jQuery("<li/>",{role:"presentation"}).append(jQuery("<a/>",{"aria-controls":d,role:"tab","data-toggle":"tab",href:"#"+d}).append(b).on("shown.bs.tab",function(){Sao.View.resize(a)})).appendTo(this.nav);return c.html(a).appendTo(this.panes),this.selected||(e.addClass("active"),c.addClass("active"),this.selected=!0),e},set_current_page:function(a){this.nav.find('li[role="presentation"]:eq('+a+") a").tab("show")},get_n_pages:function(){return this.nav.find("li[role='presentation']").length},get_nth_page:function(a){return jQuery(this.panes.find("div[role='tabpanel']")[a])}}),Sao.View.Form.Page=Sao.class_(Sao.View.Form.StateWidget,{init:function(a,b){Sao.View.Form.Page._super.init.call(this,b),this.el=a}}),Sao.View.Form.Group=Sao.class_(Sao.View.Form.StateWidget,{class_:"form-group_",init:function(a){Sao.View.Form.Group._super.init.call(this,a),this.el=jQuery("<div/>",{class:this.class_})},add:function(a){this.el.append(a.el)}}),Sao.View.Form.Image_=Sao.class_(Sao.View.Form.StateWidget,{class_:"form-image_",init:function(a){Sao.View.Form.Image_._super.init.call(this,a),this.el=jQuery("<div/>",{class_:this.class_}),this.img=jQuery("<img/>",{class:"center-block"}).appendTo(this.el),Sao.common.ICONFACTORY.register_icon(a.name).done(function(a){this.img.attr("src",a)}.bind(this))}}),Sao.View.form_widget_get=function(a){switch(a){case"char":return Sao.View.Form.Char;case"password":return Sao.View.Form.Password;case"date":return Sao.View.Form.Date;case"datetime":return Sao.View.Form.DateTime;case"time":return Sao.View.Form.Time;case"timedelta":return Sao.View.Form.TimeDelta;case"integer":case"biginteger":return Sao.View.Form.Integer;case"float":case"numeric":return Sao.View.Form.Float;case"selection":return Sao.View.Form.Selection;case"boolean":return Sao.View.Form.Boolean;case"text":return Sao.View.Form.Text;case"richtext":return Sao.View.Form.RichText;case"many2one":return Sao.View.Form.Many2One;case"one2one":return Sao.View.Form.One2One;case"reference":return Sao.View.Form.Reference;case"one2many":return Sao.View.Form.One2Many;case"many2many":return Sao.View.Form.Many2Many;case"binary":return Sao.View.Form.Binary;case"multiselection":return Sao.View.Form.MultiSelection;case"image":return Sao.View.Form.Image;case"url":return Sao.View.Form.URL;case"email":return Sao.View.Form.Email;case"callto":return Sao.View.Form.CallTo;case"sip":return Sao.View.Form.SIP;case"progressbar":return Sao.View.Form.ProgressBar;case"dict":return Sao.View.Form.Dict;case"pyson":return Sao.View.Form.PYSON}},Sao.View.Form.Widget=Sao.class_(Object,{init:function(a,b,c){this.field_name=a,this.model=b,this.view=null,this.attributes=c,this.el=null,this.position=0,this.visible=!0,this.labelled=null},display:function(a,b){var c=this.attributes.readonly,d=this.attributes.invisible,e=this.attributes.required;if(!b)return void 0===c&&(c=!0),void 0===d&&(d=!1),void 0===e&&(e=!1),this.set_readonly(c),this.set_invisible(d),void this.set_required(e);var f=b.get_state_attrs(a);void 0===c&&void 0===(c=f.readonly)&&(c=!1),void 0===e&&void 0===(e=f.required)&&(e=!1),this.view.screen.attributes.readonly&&(c=!0),this.set_readonly(c),this.set_required(e);var g=f.invalid;!c&&g?this.el.addClass("has-error"):this.el.removeClass("has-error"),void 0===d&&void 0===(d=b.get_state_attrs(a).invisible)&&(d=!1),this.set_invisible(d)},record:function(){if(this.view&&this.view.screen)return this.view.screen.current_record},field:function(){var a=this.record();if(a)return a.model.fields[this.field_name]},focus_out:function(){this.field()&&this.visible&&this.set_value(this.record(),this.field())},set_value:function(a,b){},set_readonly:function(a){this._readonly=a,this.el.prop("disabled",a)},set_required:function(a){},set_invisible:function(a){this.visible=!a,a?this.el.hide():this.el.show()}}),Sao.View.Form.TranslateDialog=Sao.class_(Object,{init:function(a,b){var c=new Sao.Dialog(Sao.i18n.gettext("Translate"),this.class_,this,a);c.modal.find(".modal-dialog").removeClass("modal-sm").addClass("modal-lg"),this.languages=a,this.read(b,c),jQuery("<button/>",{class:"btn btn-link",type:"button"}).append(Sao.i18n.gettext("Cancel")).click(function(){this.close(c)}.bind(this)).appendTo(c.footer),jQuery("<button/>",{class:"btn btn-primary",type:"button"}).append(Sao.i18n.gettext("OK")).click(this.write.bind(this,b,c)).appendTo(c.footer),c.content.submit(function(a){a.preventDefault(),c.footer.find("button.btn-primary").first().click()}),c.modal.modal("show"),c.modal.on("shown.bs.modal",function(){c.modal.find("input,select").filter(":visible").first().focus()})},close:function(a){a.modal.on("hidden.bs.modal",function(a){jQuery(this).remove()}),a.modal.modal("hide")},read:function(a,b){this.languages.forEach(function(c){var d={};d.language=c.code;var e,f=[[a.record().id],[a.field_name],d],g={method:"model."+a.model.name+".read",params:f},h=jQuery("<div/>",{class:"row form-group"}),i=a.translate_widget();i.attr("data-lang-id",c.id);var j=jQuery("<input/>",{type:"checkbox",title:Sao.i18n.gettext("Edit")});a._readonly&&j.attr("disabled",!0);var k=jQuery("<input/>",{type:"checkbox",disabled:!0,title:Sao.i18n.gettext("Fuzzy")}),l=Sao.rpc(g,a.model.session).then(function(b){e=b[0][a.field_name]}.bind(this));f=[[a.record().id],[a.field_name],d],d.fuzzy_translation=!0,g={method:"model."+a.model.name+".read",params:f},l.then(function(){Sao.rpc(g,a.model.session).then(function(b){e=b[0][a.field_name],a.translate_widget_set(i,e),k.attr("checked",b[0].name!=e)}.bind(this))}.bind(this)),j.click(function(){a.translate_widget_set_readonly(i)}),b.body.append(h),h.append(jQuery("<div/>",{class:"col-sm-3"}).append(c.name)),h.append(jQuery("<div/>",{class:"col-sm-6"}).append(i)),h.append(jQuery("<div/>",{class:"col-sm-1"}).append(j)),h.append(jQuery("<div/>",{class:"col-sm-1"}).append(k))}.bind(this))},write:function(a,b){var c=[];this.languages.forEach(function(b){var d=jQuery("[data-lang-id="+b.id+"]");if(!d.attr("readonly")){var e=a.model.session.context.language,f={};f.language=b.code,f.fuzzy_translation=!1;var g={};g[a.field_name]=d.val();var h=[[a.record().id],g,f],i={method:"model."+a.model.name+".write",params:h},j=Sao.rpc(i,a.model.session).then(function(){b.code==e&&a.view.display()});c.push(j)}}.bind(this)),this.close(b),jQuery.when.apply(jQuery,c).then(function(){a.record().cancel()})}}),Sao.View.Form.TranslateMixin={},Sao.View.Form.TranslateMixin.init=function(){this.translate=Sao.View.Form.TranslateMixin.translate.bind(this),this.translate_widget_set_readonly=Sao.View.Form.TranslateMixin.translate_widget_set_readonly.bind(this),this.translate_widget_set=Sao.View.Form.TranslateMixin.translate_widget_set.bind(this)},Sao.View.Form.TranslateMixin.translate=function(){if(this.record().id<0||this.record().has_changed()){var a=Sao.i18n.gettext("You need to save the record before adding translations.");return void Sao.common.message.run(a)}var b=this.model.session,c=[[["translatable","=",!0]]],d={method:"model.ir.lang.search",params:c.concat({})};Sao.rpc(d,b).then(function(a){if(jQuery.isEmptyObject(a))return void Sao.common.message.run(Sao.i18n.gettext("No other language available."));var c=[a,["code","name"]],d={method:"model.ir.lang.read",params:c.concat({})};Sao.rpc(d,b).then(function(a){new Sao.View.Form.TranslateDialog(a,this)}.bind(this))}.bind(this))},Sao.View.Form.TranslateMixin.translate_widget_set_readonly=function(a,b){a.attr("readonly")?a.removeAttr("readonly"):a.attr("readonly",!0)},Sao.View.Form.TranslateMixin.translate_widget_set=function(a,b){a.val(b||"")},Sao.View.Form.Char=Sao.class_(Sao.View.Form.Widget,{class_:"form-char",init:function(a,b,c){if(Sao.View.Form.Char._super.init.call(this,a,b,c),Sao.View.Form.TranslateMixin.init.call(this),this.el=jQuery("<div/>",{class:this.class_}),this.group=jQuery("<div/>",{class:"input-group input-group-sm"}).appendTo(this.el),this.input=this.labelled=jQuery("<input/>",{type:"text",class:"form-control input-sm"}).appendTo(this.group),jQuery.isEmptyObject(c.autocomplete)||(this.datalist=jQuery("<datalist/>").appendTo(this.el),this.datalist.uniqueId(),this.input.attr("list",this.datalist.attr("id"))),this.el.change(this.focus_out.bind(this)),c.size||this.group.css("width","100%"),this.attributes.translate){jQuery("<button/>",{class:"btn btn-default btn-sm form-control",type:"button","aria-label":Sao.i18n.gettext("Translate")}).append(jQuery("<span/>",{class:"glyphicon glyphicon-flag"})).appendTo(jQuery("<span/>",{class:"input-group-btn"}).appendTo(this.group)).click(this.translate.bind(this))}},get_client_value:function(a,b){var c="";return b&&(c=b.get_client(a)),c},display:function(a,b){if(Sao.View.Form.Char._super.display.call(this,a,b),this.datalist){this.datalist.children().remove();var c=function(){var b=[];a&&(b=a.autocompletion[this.field_name]||[]),b.forEach(function(a){jQuery("<option/>",{value:a}).appendTo(this.datalist)}.bind(this))}.bind(this);!a||this.field_name in a.autocompletion?c():a.do_autocomplete(this.field_name).done(c)}var d="",e="100%";a&&(d=a.expr_eval(this.attributes.size))>0&&(e=null),this.input.val(this.get_client_value(a,b)),this.input.attr("maxlength",d),this.input.attr("size",d),this.group.css("width",e)},set_value:function(a,b){b.set_client(a,this.input.val())},set_readonly:function(a){this.input.prop("readonly",a)},focus:function(){this.input.focus()},translate_widget:function(){return jQuery("<input/>",{class:"form-control",readonly:"readonly"})}}),Sao.View.Form.Password=Sao.class_(Sao.View.Form.Char,{class_:"form-password",init:function(a,b,c){Sao.View.Form.Password._super.init.call(this,a,b,c),this.input.prop("type","password"),this.button=jQuery("<button/>",{class:"btn btn-default btn-sm form-control",type:"button"}).appendTo(jQuery("<span/>",{class:"input-group-btn"}).appendTo(this.group)),this._set_password_label(),this.button.click(this.toggle_visibility.bind(this))},toggle_visibility:function(){"password"==this.input.prop("type")?(this.input.prop("type","text"),this.input.attr("autocomplete","off")):(this.input.prop("type","password"),this.input.removeAttr("autocomplete")),this._set_password_label()},_set_password_label:function(){"password"==this.input.prop("type")?this.button.text(Sao.i18n.gettext("Show")):this.button.text(Sao.i18n.gettext("Hide"))}}),Sao.View.Form.Date=Sao.class_(Sao.View.Form.Widget,{class_:"form-date",_width:"12em",init:function(a,b,c){Sao.View.Form.Date._super.init.call(this,a,b,c),this.el=jQuery("<div/>",{class:this.class_}),this.date=this.labelled=jQuery("<div/>",{class:"input-group input-group-sm"}).appendTo(this.el),this.input=jQuery("<input/>",{type:"text",class:"form-control input-sm"}).appendTo(this.date),jQuery("<span/>",{class:"input-group-btn"}).append(jQuery("<button/>",{class:"datepickerbutton btn btn-default",type:"button"}).append(jQuery("<span/>",{class:"glyphicon glyphicon-calendar"}))).appendTo(this.date),this.date.datetimepicker({locale:moment.locale()}),this.date.css("width",this._width),this.date.on("dp.change",this.focus_out.bind(this))},get_format:function(a,b){return b.date_format(a)},get_value:function(a,b){var c=this.date.data("DateTimePicker").date();return c&&(c.isDate=!0),c},display:function(a,b){a&&b&&this.date.data("DateTimePicker").format(Sao.common.moment_format(this.get_format(a,b))),Sao.View.Form.Date._super.display.call(this,a,b);var c;c=a?b.get_client(a):null,this.date.data("DateTimePicker").date(c)},focus:function(){this.input.focus()},set_value:function(a,b){b.set_client(a,this.get_value(a,b))},set_readonly:function(a){this.date.find("button").prop("disabled",a),this.date.find("input").prop("readonly",a)}}),Sao.View.Form.DateTime=Sao.class_(Sao.View.Form.Date,{class_:"form-datetime",_width:"25em",get_format:function(a,b){return b.date_format(a)+" "+b.time_format(a)},get_value:function(a,b){var c=this.date.data("DateTimePicker").date();return c&&(c.isDateTime=!0),c}}),Sao.View.Form.Time=Sao.class_(Sao.View.Form.Date,{class_:"form-time",_width:"10em",get_format:function(a,b){return b.time_format(a)},get_value:function(a,b){var c=this.date.data("DateTimePicker").date();return c&&(c.isTime=!0),c}}),Sao.View.Form.TimeDelta=Sao.class_(Sao.View.Form.Widget,{class_:"form-timedelta",init:function(a,b,c){Sao.View.Form.TimeDelta._super.init.call(this,a,b,c),this.el=jQuery("<div/>",{class:this.class_}),this.input=this.labelled=jQuery("<input/>",{type:"text",class:"form-control input-sm"}).appendTo(this.el),this.el.change(this.focus_out.bind(this))},display:function(a,b){if(Sao.View.Form.TimeDelta._super.display.call(this,a,b),a){var c=a.field_get_client(this.field_name);this.input.val(c||"")}else this.input.val("")},focus:function(){this.input.focus()},set_value:function(a,b){b.set_client(a,this.input.val())},set_readonly:function(a){this.input.prop("readonly",a)}}),Sao.View.Form.Integer=Sao.class_(Sao.View.Form.Char,{class_:"form-integer",init:function(a,b,c){Sao.View.Form.Integer._super.init.call(this,a,b,c),this.input.attr("type","text"),this.input.attr("width",8),this.group.css("width",""),this.factor=Number(c.factor||1)},set_value:function(a,b){b.set_client(a,this.input.val(),void 0,this.factor)},get_client_value:function(a,b){var c="";return b&&(c=b.get_client(a,this.factor)),c}}),Sao.View.Form.Float=Sao.class_(Sao.View.Form.Integer,{class_:"form-float"}),Sao.View.Form.Selection=Sao.class_(Sao.View.Form.Widget,{class_:"form-selection",init:function(a,b,c){Sao.View.Form.Selection._super.init.call(this,a,b,c),this.el=jQuery("<div/>",{class:this.class_}),this.select=this.labelled=jQuery("<select/>",{class:"form-control input-sm"}),this.el.append(this.select),this.select.change(this.focus_out.bind(this)),Sao.common.selection_mixin.init.call(this),this.init_selection()},init_selection:function(a){Sao.common.selection_mixin.init_selection.call(this,a,this.set_selection.bind(this))},update_selection:function(a,b,c){Sao.common.selection_mixin.update_selection.call(this,a,b,function(a){this.set_selection(a),c&&c()}.bind(this))},set_selection:function(a){var b=this.select;b.empty(),a.forEach(function(a){b.append(jQuery("<option/>",{value:JSON.stringify(a[0]),text:a[1]}))})},display_update_selection:function(a,b){this.update_selection(a,b,function(){if(!b)return void this.select.val("");for(var c,d=b.get(a),e=!1,f=0,g=this.selection.length;f<g;f++)if(this.selection[f][0]===d){e=!0;break}e?c=jQuery.when():(c=Sao.common.selection_mixin.get_inactive_selection.call(this,d),c.done(function(a){this.select.append(jQuery("<option/>",{value:JSON.stringify(a[0]),text:a[1],disabled:!0}))}.bind(this))),c.done(function(){this.select.val(JSON.stringify(d))}.bind(this))}.bind(this))},display:function(a,b){Sao.View.Form.Selection._super.display.call(this,a,b),this.display_update_selection(a,b)},focus:function(){this.select.focus()},value_get:function(){return JSON.parse(this.select.val())},set_value:function(a,b){var c=this.value_get();b.set_client(a,c)},set_readonly:function(a){this.select.prop("disabled",a)}}),Sao.View.Form.Boolean=Sao.class_(Sao.View.Form.Widget,{class_:"form-boolean",init:function(a,b,c){Sao.View.Form.Boolean._super.init.call(this,a,b,c),this.el=jQuery("<div/>",{class:this.class_}),this.input=this.labelled=jQuery("<input/>",{type:"checkbox",class:"form-control input-sm"}).appendTo(this.el),this.input.change(this.focus_out.bind(this)),this.input.click(function(){return!jQuery(this).prop("readonly")})},display:function(a,b){Sao.View.Form.Boolean._super.display.call(this,a,b),a?this.input.prop("checked",a.field_get(this.field_name)):this.input.prop("checked",!1)},focus:function(){this.input.focus()},set_value:function(a,b){var c=this.input.prop("checked");b.set_client(a,c)},set_readonly:function(a){this.input.prop("readonly",a)}}),Sao.View.Form.Text=Sao.class_(Sao.View.Form.Widget,{class_:"form-text",init:function(a,b,c){if(Sao.View.Form.Text._super.init.call(this,a,b,c),Sao.View.Form.TranslateMixin.init.call(this),this.el=jQuery("<div/>",{class:this.class_}),this.input=this.labelled=jQuery("<textarea/>",{class:"form-control input-sm"}).appendTo(this.el),this.input.change(this.focus_out.bind(this)),this.attributes.translate){var d=jQuery("<button/>",{class:"btn btn-default btn-sm form-control",type:"button","aria-label":Sao.i18n.gettext("Translate")}).appendTo(jQuery("<span/>",{class:"input-group-btn"}).appendTo(this.el));d.append(jQuery("<span/>",{class:"glyphicon glyphicon-flag"})),d.click(this.translate.bind(this))}},display:function(a,b){if(Sao.View.Form.Text._super.display.call(this,a,b),a){var c=a.field_get_client(this.field_name);this.input.val(c)}else this.input.val("")},focus:function(){this.input.focus()},set_value:function(a,b){var c=this.input.val()||"";b.set_client(a,c)},set_readonly:function(a){this.input.prop("readonly",a)},translate_widget:function(){return jQuery("<textarea/>",{class:"form-control",readonly:"readonly"})}}),Sao.View.Form.RichText=Sao.class_(Sao.View.Form.Widget,{class_:"form-richtext",init:function(a,b,c){Sao.View.Form.RichText._super.init.call(this,a,b,c),this.el=jQuery("<div/>",{class:this.class_+" panel panel-default"}),parseInt(c.toolbar||"1",10)&&this.get_toolbar().appendTo(this.el),this.input=this.labelled=jQuery("<div/>",{class:"richtext",contenteditable:!0}).appendTo(jQuery("<div/>",{class:"panel-body"}).appendTo(this.el)),this.el.focusout(this.focus_out.bind(this))},get_toolbar:function(){var a,b,c,d=jQuery("<div/>",{class:"btn-toolbar",role:"toolbar"}).appendTo(jQuery("<div/>",{class:"panel-heading"})),e=function(a){document.execCommand(a.data)},f=function(f){var g=jQuery("<div/>",{class:"btn-group",role:"group"}).appendTo(d);for(a in f)b=f[a],c=jQuery("<button/>",{class:"btn btn-default",type:"button"}).append(jQuery("<span/>",{class:"glyphicon glyphicon-"+b.icon})).appendTo(g),c.click(b.command,e)};f([{icon:"bold",command:"bold"},{icon:"italic",command:"italic"},{icon:"text-color",command:"underline"}]);var g=[{heading:Sao.i18n.gettext("Font"),options:["Normal","Serif","Sans","Monospace"],command:"fontname"},{heading:Sao.i18n.gettext("Size"),options:[1,2,3,4,5,6,7],command:"fontsize"}],h=function(a,b){return function(c){a.append(jQuery("<li/>").append(jQuery("<a/>",{href:"#"}).append(c).click(function(){document.execCommand(b.command,!1,c)})))}};for(a in g){b=g[a];var i=jQuery("<div/>",{class:"btn-group",role:"group"}).appendTo(d);c=jQuery("<button/>",{class:"btn btn-default dropdown-toggle",type:"button","data-toggle":"dropdown","aria-expanded":!1,"aria-haspopup":!0}).append(b.heading).append(jQuery("<span/>",{class:"caret"})).appendTo(i);var j=jQuery("<ul/>",{class:"dropdown-menu"}).appendTo(i);b.options.forEach(h(j,b))}return f([{icon:"align-left",command:"justifyLeft"},{icon:"align-center",command:"justifyCenter"},{icon:"align-right",command:"justifyRight"},{icon:"align-justify",command:"justifyFull"}]),[["foreColor","#000000"]].forEach(function(a){var b=a[0],c=a[1];jQuery("<input/>",{class:"btn btn-default",type:"color"}).appendTo(d).change(function(){document.execCommand(b,!1,jQuery(this).val())}).focusin(function(){document.execCommand(b,!1,jQuery(this).val())}).val(c)}),d},focus_out:function(){window.setTimeout(function(){0===this.el.find(":focus").length&&Sao.View.Form.RichText._super.focus_out.call(this)}.bind(this),0)},display:function(a,b){Sao.View.Form.RichText._super.display.call(this,a,b);var c="";a&&(c=a.field_get_client(this.field_name)),this.input.html(c)},focus:function(){this.input.focus()},set_value:function(a,b){this.input.find("div").each(function(a,b){if(b=jQuery(b),b.css("text-align")){var c=b.css("text-align").split("-").pop();b.attr("align",c),b.css("text-align","")}"start"==b.attr("align")&&b.attr("align","left")});var c=this.input.html()||"";b.set_client(a,c)},set_readonly:function(a){this.input.prop("contenteditable",!a),this.toolbar&&this.toolbar.find("button,select").prop("disabled",a)}}),Sao.View.Form.Many2One=Sao.class_(Sao.View.Form.Widget,{class_:"form-many2one",init:function(a,b,c){Sao.View.Form.Many2One._super.init.call(this,a,b,c),this.el=jQuery("<div/>",{class:this.class_});var d=jQuery("<div/>",{class:"input-group input-group-sm"}).appendTo(this.el);this.entry=this.labelled=jQuery("<input/>",{type:"input",class:"form-control input-sm"}).appendTo(d),this.entry.on("keydown",this.key_press.bind(this)),c.completion&&"1"!=c.completion||(Sao.common.get_completion(d,this._update_completion.bind(this),this._completion_match_selected.bind(this),this._completion_action_activated.bind(this)),this.wid_completion=!0),this.but_primary=jQuery("<button/>",{class:"btn btn-default",type:"button"}).append(jQuery("<span/>",{class:"glyphicon"})).appendTo(jQuery("<span/>",{class:"input-group-btn"}).prependTo(d)),this.but_secondary=jQuery("<button/>",{class:"btn btn-default",type:"button"}).append(jQuery("<span/>",{class:"glyphicon"})).appendTo(jQuery("<span/>",{class:"input-group-btn"}).appendTo(d)),this.but_primary.click("primary",this.edit.bind(this)),this.but_secondary.click("secondary",this.edit.bind(this)),this.el.change(this.focus_out.bind(this)),this._readonly=!1},get_screen:function(){var a=this.field().get_domain(this.record()),b=this.field().get_context(this.record());return new Sao.Screen(this.get_model(),{context:b,domain:a,mode:["form"],view_ids:(this.attributes.view_ids||"").split(","),views_preload:this.attributes.views,readonly:this._readonly})},set_text:function(a){jQuery.isEmptyObject(a)&&(a=""),this.entry.val(a)},get_text:function(){var a=this.record();return a?a.field_get_client(this.field_name):""},focus_out:function(){(this.attributes.completion&&"1"!=this.attributes.completion||!this.el.find(".dropdown").hasClass("open"))&&Sao.View.Form.Many2One._super.focus_out.call(this)},set_value:function(a,b){b.get_client(a)!=this.entry.val()&&(b.set_client(a,this.value_from_id(null,"")),this.entry.val(""))},display:function(a,b){var c=this.record();if(!c||!a||c.id==a.id){var d;if(Sao.View.Form.Many2One._super.display.call(this,a,b),this._set_button_sensitive(),this._set_completion(),!a)return void this.entry.val("");this.set_text(b.get_client(a));var e,f;d=b.get(a),this.has_target(d)?(e="glyphicon-folder-open",f="glyphicon-erase"):(e=null,f="glyphicon-search"),this.entry.prop("readonly")&&(f=null),[[e,this.but_primary],[f,this.but_secondary]].forEach(function(a){var b=a[0],c=a[1],d=c.find(".glyphicon");d.removeClass().addClass("glyphicon"),b?(c.parent().css("display","table-cell"),d.addClass(b)):c.parent().css("display","none")})}},focus:function(){this.entry.focus()},set_readonly:function(a){this._readonly=a,this._set_button_sensitive()},_set_button_sensitive:function(){this.entry.prop("readonly",this._readonly),this.but_primary.prop("disabled",!this.read_access()),this.but_secondary.prop("disabled",this._readonly)},get_access:function(a){var b=this.get_model();return!b||Sao.common.MODELACCESS.get(b)[a]},read_access:function(){return this.get_access("read")},create_access:function(){return this.attributes.create&&this.get_access("create")},id_from_value:function(a){return a},value_from_id:function(a,b){return void 0===b&&(b=""),[a,b]},get_model:function(){return this.attributes.relation},has_target:function(a){return void 0!==a&&null!==a},edit:function(a){var b=this.get_model();if(b&&Sao.common.MODELACCESS.get(b).read){var c,d=this.record(),e=d.field_get(this.field_name);if(a&&"secondary"==a.data&&!this._readonly&&this.has_target(e))return this.record().field_set_client(this.field_name,this.value_from_id(null,"")),void this.entry.val("");if(this.has_target(e)){var f=this.get_screen(),g=this.id_from_value(d.field_get(this.field_name));return f.new_group([g]),c=function(a){if(a){f.current_record.rec_name().done(function(a){var b=this.value_from_id(f.current_record.id,a);this.record().field_set_client(this.field_name,b,!0)}.bind(this))}},void new Sao.Window.Form(f,c.bind(this),{save_current:!0,title:this.attributes.string})}if(b){var h=this.field().get_domain(d),i=this.field().get_context(d),j=this.entry.val();c=function(a){if(!jQuery.isEmptyObject(a)){var b=this.value_from_id(a[0][0],a[0][1]);this.record().field_set_client(this.field_name,b,!0)}};var k=new Sao.common.DomainParser;return void new Sao.Window.Search(b,c.bind(this),{sel_multi:!1,context:i,domain:h,view_ids:(this.attributes.view_ids||"").split(","),views_preload:this.attributes.views||{},new_:this.create_access(),search_filter:k.quote(j),title:this.attributes.string})}}},new_:function(a){var b=this.get_model();if(b&&Sao.common.MODELACCESS.get(b).create){var c=this.get_screen(),d=function(a){if(a){c.current_record.rec_name().done(function(a){var b=this.value_from_id(c.current_record.id,a);this.record().field_set_client(this.field_name,b)}.bind(this))}};new Sao.Window.Form(c,d.bind(this),{new_:!0,save_current:!0,title:this.attributes.string,rec_name:this.entry.val()})}},key_press:function(a){var b=!this.entry.prop("readonly"),c=[Sao.common.TAB_KEYCODE],d=[Sao.common.BACKSPACE_KEYCODE,Sao.common.DELETE_KEYCODE];if(this.wid_completion||c.push(Sao.common.RETURN_KEYCODE),a.which==Sao.common.F3_KEYCODE&&b&&this.create_access())this.new_(),a.preventDefault();else if(a.which==Sao.common.F2_KEYCODE&&this.read_access())this.edit(),a.preventDefault();else if(~c.indexOf(a.which)&&b){if((!this.attributes.completion||"1"==this.attributes.completion)&&this.el.find(".dropdown").hasClass("open"))return;this.activate()}else if(this.has_target(this.record().field_get(this.field_name))&&b){var e=this.get_text();(e!=this.entry.val()||~d.indexOf(a.which))&&(this.entry.val(""),this.record().field_set_client(this.field_name,this.value_from_id(null,"")))}},activate:function(){var a=this.get_model();if(a&&Sao.common.MODELACCESS.get(a).read){var b=this.record(),c=b.field_get(this.field_name);new Sao.Model(a);if(a&&!this.has_target(c)){var d=this.entry.val();if(!this._readonly&&(d||this.field().get_state_attrs(this.record()).required)){var e=this.field().get_domain(b),f=this.field().get_context(b),g=function(a){if(jQuery.isEmptyObject(a))this.entry.val("");else{var b=this.value_from_id(a[0][0],a[0][1])
diff --git a/package.json b/package.json
index 7ef028b..c00ab48 100644
--- a/package.json
+++ b/package.json
@@ -2,7 +2,7 @@
   "name": "tryton-sao",
   "title": "sao",
   "description": "Tryton webclient",
-  "version": "4.4.6",
+  "version": "4.4.7",
   "homepage": "http://www.tryton.org/",
   "author": {
     "name": "Tryton"
diff --git a/src/model.js b/src/model.js
index 6733ba7..8f0d897 100644
--- a/src/model.js
+++ b/src/model.js
@@ -798,6 +798,11 @@
                     continue;
                 }
                 value[name] = field.get(this);
+                // Sending an empty x2MField breaks ModelFieldAccess.check
+                if ((field instanceof Sao.field.One2Many) &&
+                        (value[name].length === 0)) {
+                    delete value[name];
+                }
             }
             return value;
         },
-- 
tryton-sao



More information about the tryton-debian-vcs mailing list