Ejemplo n.º 1
0
        public void Create()
        {
            Name = Name.Replace(".", "_");

            List <PropertyData> listOfPropertyData_Code   = new List <PropertyData>();
            List <PropertyData> listOfPropertyData_Name   = new List <PropertyData>();
            List <PropertyData> listOfPropertyData_Others = new List <PropertyData>();

            foreach (PropertyData propertyData in ListOfProperties)
            {
                if (propertyData.Name.Equals("code"))
                {
                    listOfPropertyData_Code.Add(propertyData);
                }
                else if (propertyData.Name.Equals("name"))
                {
                    listOfPropertyData_Name.Add(propertyData);
                }
                else
                {
                    listOfPropertyData_Others.Add(propertyData);
                }
            }

            ListOfProperties = new List <PropertyData>();
            ListOfProperties.AddRange(listOfPropertyData_Code);
            ListOfProperties.AddRange(listOfPropertyData_Name);
            ListOfProperties.AddRange(listOfPropertyData_Others);


            ListOfGroups = new Dictionary <string, GroupData>();

            ListOfGroupsReport     = new Dictionary <string, GroupData>();
            ListOfPropertiesReport = new List <PropertyData>();

            GroupData rootGroupData = new GroupData("default");

            rootGroupData.Root      = true;
            rootGroupData.ClassData = this;
            rootGroupData.Report    = false;
            ListOfGroups.Add("default", rootGroupData);

            GroupData rootReportGroupData = new GroupData("default");

            rootReportGroupData.Root      = true;
            rootReportGroupData.ClassData = this;
            rootReportGroupData.Report    = true;


            string sel = "";
            List <PropertyData> listOfDates = new List <PropertyData>();

            foreach (PropertyData propertyData in ListOfProperties)
            {
                if (propertyData.Typage.Equals("date") || propertyData.Typage.Equals("datetime") || propertyData.Typage.Equals("time"))
                {
                    listOfDates.Add(propertyData);
                    ListOfPropertiesReport.Add(propertyData);
                }
            }

            if (listOfDates.Count > 0)
            {
                sel += "('date', 'Date'),";
            }

            if (!sel.Equals(""))
            {
                PropertyData property = new PropertyData();
                property.Name   = "filtrerpar";
                property.Alias  = "Filtrer par";
                property.Typage = "selection";

                sel = sel.Substring(0, sel.Length - 1);
                property.Selection = "[" + sel + "]";


                PageData pageFilter = new PageData("Filtres");
                pageFilter.ListOfGroups["default"]           = new GroupData("default");
                pageFilter.ListOfGroups["default"].ClassData = this;
                pageFilter.ListOfGroups["default"].ListOfProperties.Add(property);
                ListOfPropertiesReport.Add(property);

                if (listOfDates.Count > 0)
                {
                    pageFilter.ListOfGroups["default"].ListOfGroups.Add("dates", new GroupData("Dates", this));
                    pageFilter.ListOfGroups["default"].ListOfGroups["dates"].ListOfProperties = listOfDates;
                }

                rootReportGroupData.ListOfPages.Add("filter", pageFilter);
            }


            rootReportGroupData.ListOfPages.Add("avances", new PageData("Avancés"));
            rootReportGroupData.ListOfPages.Add("options", new PageData("Options"));

            ListOfGroupsReport.Add("default", rootReportGroupData);

            foreach (PropertyData propertyData in ListOfProperties)
            {
                bool dontthread = false;

                if (!propertyData.Name.Equals(Name + "_id"))
                {
                    propertyData.Update();


                    if ((propertyData.Name.Equals("state")) && (propertyData.Typage.Equals("selection")))
                    {
                        dontthread    = true;
                        StateWorkflow = true;
                        StateProperty = propertyData;

                        propertyData.Readonly = "1";
                        propertyData.Select   = "1";

                        ListOfWorkFlowButton   = new Dictionary <string, ButtonData>();
                        ListOfWorkFlowFunction = new Dictionary <string, OperationData>();
                        foreach (KeyValuePair <string, string> KeyValue in propertyData.SelectionData.ListOfValues)
                        {
                            OperationData operationData = GetOperation(propertyData.TypageInitial, KeyValue.Key);

                            if (operationData != null)
                            {
                                ButtonData buttonData = new ButtonData();
                                buttonData.States = KeyValue.Key;

                                if (operationData.CallBy.Equals("button"))
                                {
                                    buttonData.Text = KeyValue.Value;
                                    buttonData.Name = operationData.Name;
                                }
                                else if (operationData.CallBy.Equals(""))
                                {
                                    buttonData.RenderXML = false;
                                    ListOfWorkFlowFunction.Add(KeyValue.Key, operationData);

                                    operationData.ReturnType = "boolean";
                                }

                                ListOfWorkFlowButton.Add(KeyValue.Key, buttonData);
                            }
                        }
                    }
                    else if (propertyData.Name.Equals("name"))
                    {
                        //
                    }
                    else if (propertyData.Name.Equals("code"))
                    {
                        if (!Code.Equals(""))
                        {
                            CodeProperty      = propertyData;
                            propertyData.Uniq = true;
                        }
                    }
                    else if (propertyData.Name.Equals("sequence"))
                    {
                        //
                    }
                    else if (propertyData.Name.Equals("parent_id"))
                    {
                        //
                    }



                    if (!dontthread)
                    {
                        if (propertyData.Typage.Equals("text"))
                        {
                            if (propertyData.Group.Equals("") && propertyData.Page.Equals(""))
                            {
                                propertyData.Page      = propertyData.Alias;
                                propertyData.ColSpan   = "6";
                                propertyData.ShowLabel = false;
                            }
                        }
                        else if (propertyData.Typage.Equals("selection") || (propertyData.LinkData != null))
                        {
                            ListOfGroupsReport["default"].ListOfProperties.Add(propertyData);
                            ListOfPropertiesReport.Add(propertyData);
                        }


                        if (propertyData.Group.Equals(string.Empty) && propertyData.Page.Equals(string.Empty))
                        {
                            ListOfGroups["default"].ListOfProperties.Add(propertyData);
                        }
                        else if (!propertyData.Group.Equals(string.Empty) && propertyData.Page.Equals(string.Empty))
                        {
                            if (!ListOfGroups["default"].ListOfGroups.ContainsKey(propertyData.Group))
                            {
                                ListOfGroups["default"].ListOfGroups.Add(propertyData.Group, new GroupData(propertyData.Group, this));
                            }

                            ListOfGroups["default"].ListOfGroups[propertyData.Group].ListOfProperties.Add(propertyData);
                        }
                        else if (propertyData.Group.Equals(string.Empty) && !propertyData.Page.Equals(string.Empty))
                        {
                            if (!ListOfGroups["default"].ListOfPages.ContainsKey(propertyData.Page))
                            {
                                ListOfGroups["default"].ListOfPages.Add(propertyData.Page, new PageData(propertyData.Page));
                                ListOfGroups["default"].ListOfPages[propertyData.Page].ListOfGroups.Add("default", new GroupData("default", this));
                            }

                            ListOfGroups["default"].ListOfPages[propertyData.Page].ListOfGroups["default"].ListOfProperties.Add(propertyData);
                        }
                        else if (!propertyData.Group.Equals(string.Empty) && !propertyData.Page.Equals(string.Empty))
                        {
                            if (!ListOfGroups["default"].ListOfPages.ContainsKey(propertyData.Page))
                            {
                                ListOfGroups["default"].ListOfPages.Add(propertyData.Page, new PageData(propertyData.Page));
                                ListOfGroups["default"].ListOfPages[propertyData.Page].ListOfGroups.Add("default", new GroupData("default", this));
                            }

                            if (!ListOfGroups["default"].ListOfPages[propertyData.Page].ListOfGroups.ContainsKey(propertyData.Group))
                            {
                                ListOfGroups["default"].ListOfPages[propertyData.Page].ListOfGroups.Add(propertyData.Group, new GroupData(propertyData.Group, this));
                            }

                            ListOfGroups["default"].ListOfPages[propertyData.Page].ListOfGroups[propertyData.Group].ListOfProperties.Add(propertyData);
                        }
                    }
                    else
                    {
                        if (propertyData.Typage.Equals("selection") || (propertyData.LinkData != null))
                        {
                            ListOfGroupsReport["default"].ListOfProperties.Add(propertyData);
                            ListOfPropertiesReport.Add(propertyData);
                        }
                    }
                }
            }

            foreach (PropertyData propertyData in ListOfProperties)
            {
                if (propertyData.Typage.Equals("one2many"))
                {
                    foreach (PropertyData property in ListOfProperties)
                    {
                        if (!propertyData.Equals(property))
                        {
                            if (!property.ShareTo.Equals(""))
                            {
                                string[] shareto = property.ShareTo.Split(new char[] { '.' });

                                string clssppt = Parent.ClassicName + "." + shareto[0];

                                if (clssppt.Equals(propertyData.LinkManyClass))
                                {
                                    ClassData clssData = Parent.GetClass(propertyData.LinkManyClass.Split(new char[] { '.' })[1]);

                                    PropertyData propData = clssData.GetProperty(shareto[1]);

                                    propData.MaxUse = Name + "." + propData.Name;
                                }
                            }
                        }
                    }
                }
            }

            Dictionary <string, PageData> ListOfPages  = new Dictionary <string, PageData>();
            Dictionary <string, PageData> ListOfPages2 = new Dictionary <string, PageData>();

            foreach (KeyValuePair <string, PageData> pageData in ListOfGroups["default"].ListOfPages)
            {
                if ((pageData.Value.ListOfGroups != null) && (pageData.Value.ListOfGroups.Count > 0) &&
                    (pageData.Value.ListOfGroups.ContainsKey("default")) && (pageData.Value.ListOfGroups["default"].ListOfProperties != null) &&
                    (pageData.Value.ListOfGroups["default"].ListOfProperties.Count > 0) && (pageData.Value.ListOfGroups["default"].ListOfProperties[0].Typage.Equals("text")))
                {
                    ListOfPages2.Add(pageData.Value.Label, pageData.Value);
                }
                else
                {
                    ListOfPages.Add(pageData.Value.Label, pageData.Value);
                }
            }

            foreach (KeyValuePair <string, PageData> pageData in ListOfPages2)
            {
                ListOfPages.Add(pageData.Value.Label, pageData.Value);
            }

            ListOfGroups["default"].ListOfPages = ListOfPages;

            ListOfButton = new List <ButtonData>();
            foreach (KeyValuePair <string, OperationData> operationDataKV in ListOfOperations)
            {
                OperationData operationData = operationDataKV.Value;

                if ((operationData.CallBy.Equals("button")) && (operationData.State.Equals("")))
                {
                    ButtonData buttonData = new ButtonData(operationData);

                    ListOfButton.Add(buttonData);
                }
                else if ((operationData.CallBy.Equals("button")) && (!operationData.State.Equals("")))
                {
                    FunctionModel pythonCode = Utils.GetFunctionModel("function_caller_action_wkf", FunctionUsage.Classic);

                    string[] states = operationData.State.Split(new char[] { '.' });

                    string state = states[1].Trim(); //GetNextState(states[1].Trim());

                    if (!state.Equals(""))
                    {
                        /*Dictionary<string, string> pythonCode_values = new Dictionary<string, string>();
                         * pythonCode_values["function_name"] = operationData.Name;
                         * pythonCode_values["action_wkf"] = "action_" + state + "_wkf";
                         *
                         * pythonCode.Content = Utils.replaceValues(pythonCode.Content, pythonCode_values) + "\r\n\t";*/

                        pythonCode.ReplaceValues(operationData.Name, "action_" + state + "_wkf");

                        operationData.PythonCode = pythonCode.Content;
                    }
                }
                else if (!operationData.CallBy.Equals("button") && !operationData.CallBy.Equals(""))
                {
                    PropertyData propertyData = GetProperty(operationData.CallBy);

                    string param = "";
                    foreach (ParameterData parameterData in operationData.ListOfParameter)
                    {
                        param += parameterData.Name + ", ";
                    }

                    if (!param.Equals(""))
                    {
                        param = param.Substring(0, param.Length - 2);
                    }

                    propertyData.OnChange = operationData.Name + "(" + param + ")";
                }
            }

            ListOfGroups["default"].ListOfButtons = ListOfButton;

            PyGenerator.CreateClass(this);
            PyGenerator.CreateReportModel(this);
            PyGenerator.CreateReportWizardModel(this);

            XmlGenerator.CreateView(this);
            XmlGenerator.CreateReportView(this);
            XmlGenerator.CreateWizardReportView(this, MenuRapport);

            if (CodeProperty != null)
            {
                XmlGenerator.CreateDatas(this);
            }

            if (StateWorkflow)
            {
                XmlGenerator.CreateWorkFlow(this);
            }

            XslGenerator.CreateReport(this);
        }
        public string Create()
        {
            string AddonPath = this.Parent.AddonsPath;

            string moduleDirectory = AddonPath + "/" + NameDirectory;

            if (Directory.Exists(moduleDirectory))
            {
                Directory.Delete(moduleDirectory, true);
            }

            Directory.CreateDirectory(moduleDirectory);

            DirectoryInfo_Base      = Directory.CreateDirectory(moduleDirectory);
            DirectoryInfo_I18n      = Directory.CreateDirectory(moduleDirectory + "/i18n");
            DirectoryInfo_Process   = Directory.CreateDirectory(moduleDirectory + "/process");
            DirectoryInfo_Report    = Directory.CreateDirectory(moduleDirectory + "/report");
            DirectoryInfo_Security  = Directory.CreateDirectory(moduleDirectory + "/security");
            DirectoryInfo_Static    = Directory.CreateDirectory(moduleDirectory + "/static/src/img");
            DirectoryInfo_Wizard    = Directory.CreateDirectory(moduleDirectory + "/wizard");
            DirectoryInfo_View      = Directory.CreateDirectory(moduleDirectory + "/view");
            DirectoryInfo_Demo      = Directory.CreateDirectory(moduleDirectory + "/demo");
            DirectoryInfo_Workflow  = Directory.CreateDirectory(moduleDirectory + "/workflow");
            DirectoryInfo_Images    = Directory.CreateDirectory(moduleDirectory + "/images");
            DirectoryInfo_Sequences = Directory.CreateDirectory(moduleDirectory + "/data");

            Utils.MakeFileFromModel("openerp_security.xml.model", DirectoryInfo_Security.FullName + "/groups.xml");
            Utils.MakeFileFromModel("ir.model.access.csv.model", DirectoryInfo_Security.FullName + "/ir.model.access.csv");

            Dashboard = "";

            foreach (ClassData classData in ListOfClass)
            {
                if (classData.InDashBoard)
                {
                    Dashboard += "\t\t<record id=\"" + classData.DashboardAction["id"] + "\" model=\"ir.actions.act_window\">\r\n";
                    Dashboard += "\t\t\t<field name=\"name\">" + classData.DashboardAction["name"] + "</field>\r\n";
                    Dashboard += "\t\t\t<field name=\"type\">ir.actions.act_window</field>\r\n";
                    Dashboard += "\t\t\t<field name=\"res_model\">" + classData.DashboardAction["res_model"] + "</field>\r\n";
                    Dashboard += "\t\t\t<field name=\"view_type\">" + classData.DashboardAction["view_type"] + "</field>\r\n";
                    Dashboard += "\t\t\t<field name=\"view_mode\">" + classData.DashboardAction["view_mode"] + "</field>\r\n";
                    //Dashboard += "\t\t\t<field name=\"context\">" + classData.DashboardAction["context"] + "</field>\r\n";
                    Dashboard += "\t\t\t<field name=\"view_id\" ref=\"" + classData.DashboardAction["view_id"] + "\"/>\r\n";
                    //Dashboard += "\t\t\t<field name=\"domain\">" + classData.DashboardAction["domain"] + "</field>\r\n";
                    Dashboard += "\t\t</record>\r\n";

                    Dashboard += "\r\n";
                }
            }

            string board_style = "1";

            foreach (ClassData classData in ListOfClass)
            {
                if (classData.InDashBoard)
                {
                    if (!classData.DashboardAction["position"].Equals("1"))
                    {
                        board_style = "2-1";
                    }
                }
            }


            Dashboard += "\t\t<record id=\"dashboard_" + ClassicName + "_form\" model=\"ir.ui.view\">\r\n";
            Dashboard += "\t\t\t<field name=\"name\">dashboard." + ClassicName + ".form</field>\r\n";
            Dashboard += "\t\t\t<field name=\"model\">board.board</field>\r\n";
            Dashboard += "\t\t\t<field name=\"type\">form</field>\r\n";
            Dashboard += "\t\t\t<field name=\"arch\" type=\"xml\">\r\n";

            Dashboard += "\t\t\t\t<form string=\"Tableau de bord : " + Alias + "\">\r\n";
            Dashboard += "\t\t\t\t\t<board style=\"" + board_style + "\">\r\n";

            Dashboard += "\t\t\t\t\t\t<column>\r\n";
            foreach (ClassData classData in ListOfClass)
            {
                if ((classData.InDashBoard) && (classData.DashboardAction["position"].Equals("1")))
                {
                    Dashboard += "\t\t\t\t\t\t\t<action name=\"%(" + classData.DashboardAction["id"] + ")d\" creatable=\"true\" string=\"" + classData.Alias + "\"/>\r\n";
                }
            }
            Dashboard += "\t\t\t\t\t\t</column>\r\n";

            if (board_style.Equals("2-1"))
            {
                Dashboard += "\t\t\t\t\t\t<column>\r\n";
                foreach (ClassData classData in ListOfClass)
                {
                    if ((classData.InDashBoard) && (classData.DashboardAction["position"].Equals("2")))
                    {
                        Dashboard += "\t\t\t\t\t\t\t<action name=\"%(" + classData.DashboardAction["id"] + ")d\" creatable=\"true\" string=\"" + classData.Alias + "\"/>\r\n";
                    }
                }
                Dashboard += "\t\t\t\t\t\t</column>\r\n";
            }

            Dashboard += "\t\t\t\t\t</board>\r\n";
            Dashboard += "\t\t\t\t</form>\r\n";

            Dashboard += "\t\t\t</field>\r\n";
            Dashboard += "\t\t</record>\r\n";

            Dashboard += "\r\n";

            Dashboard += "\t\t<record id=\"open_dashboard_" + ClassicName + "\" model=\"ir.actions.act_window\">\r\n";
            Dashboard += "\t\t\t<field name=\"name\">Tableau de bord : " + Alias + "</field>\r\n";
            Dashboard += "\t\t\t<field name=\"res_model\">board.board</field>\r\n";
            Dashboard += "\t\t\t<field name=\"view_type\">form</field>\r\n";
            Dashboard += "\t\t\t<field name=\"view_mode\">form</field>\r\n";
            Dashboard += "\t\t\t<field name=\"usage\">menu</field>\r\n";
            Dashboard += "\t\t\t<field name=\"view_id\" ref=\"dashboard_" + ClassicName + "_form\"/>\r\n";
            Dashboard += "\t\t</record>\r\n";

            Dashboard += "\r\n";

            Dashboard += "\t\t<menuitem name=\"" + Alias + "\" id=\"" + ClassicName + ".menu_" + ClassicName + "\" action=\"open_dashboard_" + ClassicName + "\"/>\r\n";

            Dashboard = Dashboard.Substring(2);

            Dictionary <string, string> __module_dashboard_Values__ = new Dictionary <string, string>();

            __module_dashboard_Values__["classview"] = Dashboard;

            Utils.MakeFileFromModel("openerp_class_view.xml.model", DirectoryInfo_Base.FullName + "/" + ClassicName + "_dashboard_view.xml", __module_dashboard_Values__);



            Dictionary <string, string> __module_Values__ = new Dictionary <string, string>();

            __module_Values__["classview"] = Menus;

            Utils.MakeFileFromModel("openerp_class_view.xml.model", DirectoryInfo_Base.FullName + "/" + ClassicName + "_view.xml", __module_Values__);



            string imports        = "";
            string report_imports = "";
            string wizard_imports = "";
            string updateXml      = "";
            string demoXml        = "";
            string images         = "";
            string test           = "";
            string depends        = "";

            foreach (ClassData classData in ListOfClass)
            {
                classData.GetLinkData();
            }

            string updateWorkflowXml = "";
            string updateReportXml   = "";
            string updateWizardXml   = "";
            string updateDataXml     = "";
            string updateProcessXml  = "";

            foreach (ClassData classData in ListOfClass)
            {
                if (!((classData.AssociationClass) && (classData.ListOfProperties.Count <= 1)))
                {
                    classData.Create();

                    imports += "import " + ClassicName + "_" + classData.Name + "\r\n";

                    report_imports += "import report_" + ClassicName + "_" + classData.Name + "\r\n";

                    wizard_imports += "import wizard_" + ClassicName + "_" + classData.Name + "\r\n";

                    updateXml       += "'view/" + ClassicName + "_" + classData.Name + "_view.xml',\r\n\t";
                    updateReportXml += "'report/report_" + ClassicName + "_" + classData.Name + ".xml',\r\n\t";
                    updateWizardXml += "'wizard/wizard_" + ClassicName + "_" + classData.Name + ".xml',\r\n\t";

                    if (classData.StateWorkflow)
                    {
                        updateWorkflowXml += "'workflow/workflow_" + ClassicName + "_" + classData.Name + ".xml',\r\n\t";
                    }

                    if (classData.CodeProperty != null)
                    {
                        updateDataXml += "'data/data_" + ClassicName + "_" + classData.Name + ".xml',\r\n\t";
                    }

                    if (classData.Process)
                    {
                        updateProcessXml += "'process/process_" + ClassicName + "_" + classData.Name + ".xml',\r\n\t";
                    }


                    Program.Form.SetTaskText(Program.Form.GetTaskText() + " \\ " + classData.Name);

                    Application.DoEvents();
                }
            }

            imports += "\r\n";
            imports += "import report\r\n";
            imports += "import wizard\r\n";


            updateXml += updateReportXml;
            updateXml += updateWizardXml;
            updateXml += updateWorkflowXml;
            updateXml += updateDataXml;
            updateXml += updateProcessXml;

            if (updateXml.Length > 3)
            {
                updateXml = updateXml.Substring(0, updateXml.Length - 3);
            }

            if (Depends.Count > 0)
            {
                foreach (string depend in Depends)
                {
                    depends += "\r\n\t'" + depend + "',";
                }

                depends += "\r\n\t";
            }


            this.Data["imports"]        = imports;
            this.Data["report_imports"] = report_imports;
            this.Data["wizard_imports"] = wizard_imports;
            this.Data["update_xml"]     = updateXml;
            this.Data["demo_xml"]       = demoXml;
            this.Data["images"]         = images;
            this.Data["category"]       = Category;
            this.Data["depends"]        = depends;
            this.Data["test"]           = test;


            PyGenerator.CreateInit(this);
            PyGenerator.CreateReportInit(this);
            PyGenerator.CreateWizardInit(this);
            PyGenerator.CreateOpenERP(this);

            XmlGenerator.CreateView(this);

            foreach (ClassData classData in ListOfClass)
            {
                if (classData.Process)
                {
                    XmlGenerator.CreateProcess(classData);
                }
            }

            PoGenerator.CreateLanguage(this);

            Utils.CopyIcons(DirectoryInfo_Base.FullName + "/images/");
            Utils.CopyIcon(DirectoryInfo_Static.FullName);

            return((new DirectoryInfo(AddonPath + "/" + NameDirectory)).FullName);
        }