Browse Source

add related options into model field options to map the odoo relation

robert2206 8 years ago
parent
commit
4d19cb4e93
3 changed files with 23 additions and 2 deletions
  1. 20 0
      src/base/base-view.ts
  2. 1 1
      src/odoo/models/res.partner.ts
  3. 2 1
      src/odoo/options/field-options.ts

+ 20 - 0
src/base/base-view.ts

@@ -18,14 +18,18 @@ export abstract class BaseView<T> {
 
     type: T = {} as T;
     model: any = {};
+    fields: Array<any>;
     injector: any = {};
     title: string;
 
     constructor(c: { new (): T; }, ...injectables: any[]) {
         this.type = new c();
         this.model = getMetadataStorage().models.filterByTarget(this.type.constructor).items.shift();
+        this.fields = getMetadataStorage().fields.filterByTarget(this.type.constructor).items;
         this.injector = ReflectiveInjector.resolveAndCreate(injectables);
         this.title = "Sin título";
+
+        console.log(this.getFieldsRelated());
     }
 
     // ------------------------------------------------------------
@@ -77,6 +81,22 @@ export abstract class BaseView<T> {
         return this.getModel().name;
     }
 
+    /**
+     * 
+     */
+    getFields(): Array<any> {
+        return this.fields;
+    }
+
+    /**
+     * 
+     */
+    getFieldsRelated(): Array<any> {
+        return this.getFields().filter(field => {
+            return !!field.options.related;
+        });
+    }
+
     /**
      * 
      */

+ 1 - 1
src/odoo/models/res.partner.ts

@@ -7,7 +7,7 @@ import { Base } from "./base";
 @OdooModel("res.partner", [["active", "=", true]])
 export class Partner extends Base {
 
-    @OdooField(FieldTypes.ONE2MANY)
+    @OdooField({ type: FieldTypes.ONE2MANY, related: Partner })
     child_ids: any;
 
     @OdooField(FieldTypes.CHAR)

+ 2 - 1
src/odoo/options/field-options.ts

@@ -15,5 +15,6 @@ import { FieldType } from "../types/field";
 export class FieldOptions {
 
     readonly name?: string;
-    readonly type?: FieldType
+    readonly type?: FieldType;
+    readonly related?: Function;
 }