示例#1
0
        //public List<string> GetUomCodes()
        //{
        //    ArrayList filter = new ArrayList(1);
        //    filter.Add(new ArrayList(3) { "code", "!=", false });
        //    ArrayList ids = oObject.Search("product.uom", filter);
        //    ArrayList records = oObject.Read("product.uom", ids, new ArrayList(1) { "code" });

        //    List<string> uoms = new List<string>();
        //    foreach (Hashtable record in records)
        //    {
        //        if (!uoms.Contains((string)record["code"]))
        //            uoms.Add((string)record["code"]);
        //    }
        //    return uoms;
        //}

        public List <string> GetRouteTemplates()
        {
            ArrayList filter = new ArrayList(1);

            filter.Add(new ArrayList(3)
            {
                "name", "like", "_template"
            });
            ArrayList ids     = oObject.Search("mrp.routing", filter);
            ArrayList records = oObject.Read("mrp.routing", ids, new ArrayList(1)
            {
                "name"
            });

            List <string> routes = new List <string>();

            foreach (Hashtable record in records)
            {
                if (!routes.Contains((string)record["name"]))
                {
                    routes.Add((string)record["name"]);
                }
            }
            routes.Sort();
            return(routes);
        }
示例#2
0
        public void Refresh()
        {
            this.HasProduct = false;
            productTable    = scaffold.OdooTable;
            DataRow dr = productTable.NewRow();

            productTable.Rows.Add(dr);

            if (this.engCode == null || productCode == null)
            {
                return;
            }

            // Get product versions
            ArrayList filter = new ArrayList();

            filter.Add(new ArrayList(3)
            {
                "eng_code", "=", this.engCode
            });
            filter.Add("|");
            filter.Add(new ArrayList(3)
            {
                "active", "=", true
            });
            filter.Add(new ArrayList(3)
            {
                "active", "=", false
            });
            this.versionIds = oClient.Search("product.product", filter);

            // Build eco datatable
            GetEcos();

            // Get product.product data
            filter = new ArrayList();
            filter.Add(new ArrayList(3)
            {
                "default_code", "=", productCode
            });
            filter.Add("|");
            filter.Add(new ArrayList(3)
            {
                "active", "=", true
            });
            filter.Add(new ArrayList(3)
            {
                "active", "=", false
            });
            ArrayList records = oClient.Browse("product.product", filter, this.prodFields);

            if (records == null || records.Count == 0)
            {
                latestException = oClient.LatestException;
                return;
            }
            this.productRecord = (Hashtable)records[0];
            this.productId     = (int)this.productRecord["id"];

            // Get product.template data
            this.templateId = (int)((ArrayList)this.productRecord["product_tmpl_id"])[0];
            filter          = new ArrayList();
            filter.Add(new ArrayList(3)
            {
                "id", "=", this.templateId
            });
            filter.Add("|");
            filter.Add(new ArrayList(3)
            {
                "active", "=", true
            });
            filter.Add(new ArrayList(3)
            {
                "active", "=", false
            });
            records = oClient.Browse("product.template", filter, this.tmplFields);
            if (records == null)
            {
                latestException = oClient.LatestException;
                return;
            }
            this.templateRecord = (Hashtable)records[0];

            // Fill Odoo DataRow
            foreach (DataRow drField in scaffold.FieldDefs.Select("odoo_field is not null"))
            {
                string colName      = drField["field"].ToString();
                string type         = drField["dt_type"].ToString();
                string field        = drField["odoo_field"].ToString();
                string model        = drField["odoo_model"].ToString();
                string refModel     = drField["odoo_ref_model"].ToString();
                string refField     = drField["odoo_ref_field"].ToString();
                bool   refInactives = (long)drField["ref_inactives"] != 0;
                object rawValue;
                if (model == "product.product")
                {
                    rawValue = productRecord[field];
                }
                else
                {
                    rawValue = templateRecord[field];
                }
                if (rawValue == null)
                {
                    continue;
                }

                if (refField != "" && rawValue.GetType() != Type.GetType("System.Boolean"))
                {
                    // this field references another, and we have a reference id
                    int refId = (int)((ArrayList)rawValue)[0];
                    dr[colName] = GetRefValue(refModel, refField, refId, refInactives);
                }
                else if (type != "System.Boolean" && rawValue.GetType() == Type.GetType("System.Boolean"))
                {
                    // Odoo returned a null value for this field
                    dr[colName] = System.DBNull.Value;
                }
                //else if (type == "System.Decimal" || type == "System.Int32" && rawValue.ToString() == "0")
                //    // This is a number field that is zero
                //    dr[colName] = System.DBNull.Value;
                else
                {
                    dr[colName] = rawValue;
                }
            }
            // Transform UOM
            scaffold.UomMapping.TryGetValue(dr["Uom"].ToString(), out string uom);
            dr["Uom"] = uom;

            this.HasProduct = true;
        }