From ca8ba43748e9cd24d1cbbf5d9ba071de3493bb28 Mon Sep 17 00:00:00 2001 From: =?utf8?q?S=C3=A9bastien=20CHAZALLET?= Date: Mon, 8 Jul 2013 14:36:33 +0200 Subject: [PATCH] Rajout des tests sur fields --- __init__.py | 3 +- __openerp__.py | 4 +- menu.xml | 76 --- testing.py | 168 ------- testing.sql | 1189 -------------------------------------------- testing_fields.py | 89 ++++ testing_inheritance.py | 168 +++++++ views/menu.xml | 11 + views/menu_fields.xml | 17 + views/menu_inheritance.xml | 73 +++ 10 files changed, 363 insertions(+), 1435 deletions(-) delete mode 100644 menu.xml delete mode 100644 testing.py delete mode 100644 testing.sql create mode 100644 testing_fields.py create mode 100644 testing_inheritance.py create mode 100644 views/menu.xml create mode 100644 views/menu_fields.xml create mode 100644 views/menu_inheritance.xml diff --git a/__init__.py b/__init__.py index d38f7c7..f9465d7 100644 --- a/__init__.py +++ b/__init__.py @@ -1 +1,2 @@ -import testing \ No newline at end of file +import testing_fields +import testing_inheritance \ No newline at end of file diff --git a/__openerp__.py b/__openerp__.py index 9c4f46a..3577d9f 100644 --- a/__openerp__.py +++ b/__openerp__.py @@ -9,7 +9,9 @@ # Vues associées aux assistants # Vues associées aux modèles # Menus - "menu.xml" + "views/menu.xml", + "views/menu_fields.xml", + "views/menu_inheritance.xml", # Données ], "demo": [ diff --git a/menu.xml b/menu.xml deleted file mode 100644 index c8e92b3..0000000 --- a/menu.xml +++ /dev/null @@ -1,76 +0,0 @@ - - - - - - - BaseA - testing.base.a - tree,form - - - - BaseB - testing.base.b - tree,form - - - - BaseC (ClassInheritance) - testing.base.c - tree,form - - - - BaseD (PrototypeInheritance) - testing.base.d - tree,form - - - - PrototypeInheritance (BaseD) - testing.inheritance.prototype - tree,form - - - - DelegationInheritance1 (BaseA) - testing.inheritance.delegation1 - tree,form - - - - DelegationInheritance2 (BaseA, BaseB) - testing.inheritance.delegation2 - tree,form - - - - DelegationInheritance3 (BaseA) - testing.inheritance.delegation3 - tree,form - - - - DelegationInheritance4 (BaseA, BaseB) - testing.inheritance.delegation4 - tree,form - - - - - - - - - - - - - - - - - - - diff --git a/testing.py b/testing.py deleted file mode 100644 index b0dc708..0000000 --- a/testing.py +++ /dev/null @@ -1,168 +0,0 @@ -#-*- coding: utf8 -*- -from openerp.osv import osv, fields - - -class BaseA(osv.Model): - """Classe parente A""" - - _name = "testing.base.a" - - _description = "BaseA" - - _columns = { - "name": fields.char(string="name", size=8, required=True), - "a1": fields.char(string="A1", size=8, required=True), - "a2": fields.char(string="A2", size=8, required=True), - } - - -class BaseB(osv.Model): - """Classe parente B""" - - _name = "testing.base.b" - - _description = "BaseB" - - _columns = { - "name": fields.char(string="name", size=8, required=True), - "b1": fields.char(string="B1", size=8, required=True), - "b2": fields.char(string="B2", size=8, required=True), - } - - -class BaseC(osv.Model): - """Classe parente C""" - - _name = "testing.base.c" - - _description = "BaseC" - - _columns = { - "name": fields.char(string="name", size=8, required=True), - "c1": fields.char(string="C1", size=8, required=True), - "c2": fields.char(string="C2", size=8, required=True), - } - - -class BaseD(osv.Model): - """Classe parente D""" - - _name = "testing.base.d" - - _description = "BaseD" - - _columns = { - "name": fields.char(string="name", size=8, required=True), - "d1": fields.char(string="D1", size=8, required=True), - "d2": fields.char(string="D2", size=8, required=True), - } - - -class ClassInheritance(osv.Model): - """Test d'héritage de classe""" - - _name = "testing.base.c" - - _description = "ClassInheritance" - - _inherit = "testing.base.c" - - _columns = { - "name": fields.char(string="name", size=8, required=True), - "c1": fields.char(string="C1", size=8, required=True), - "c3": fields.char(string="C3", size=8, required=True), - } - - -class PrototypeInheritance(osv.Model): - """Test d'héritage de prototype""" - - _name = "testing.inheritance.prototype" - - _description = "PrototypeInheritance" - - _inherit = "testing.base.d" - - _columns = { - "name": fields.char(string="name", size=8, required=True), - "d1": fields.char(string="D1", size=8, required=True), - "d3": fields.char(string="D3", size=8, required=True), - } - - -class DelegationInheritance1(osv.Model): - """Test d'héritage par délégation""" - - _name = "testing.inheritance.delegation1" - - _description = "DelegationInheritance1" - - _inherits = {"testing.base.a": "custom_base_a_id"} - - _columns = { - "name": fields.char(string="name", size=8, required=True), - "a1": fields.char(string="A1", size=8, required=True), - "a3": fields.char(string="A3", size=8, required=True), - } - - -class DelegationInheritance2(osv.Model): - """Test d'héritage par délégation""" - - _name = "testing.inheritance.delegation2" - - _description = "DelegationInheritance2" - - _inherits = { - "testing.base.a": "custom_base_a_id", - "testing.base.b": "custom_base_b_id", - } - - _columns = { - "name": fields.char(string="name", size=8, required=True), - "a1": fields.char(string="A1", size=8, required=True), - "a3": fields.char(string="A3", size=8, required=True), - "b1": fields.char(string="B1", size=8, required=True), - "b3": fields.char(string="B3", size=8, required=True), - } - - -class DelegationInheritance3(osv.Model): - """Test d'héritage par délégation""" - - _name = "testing.inheritance.delegation3" - - _description = "DelegationInheritance3" - - _inherits = {"testing.base.a": "custom_base_a_id"} - - _columns = { - "name": fields.char(string="name", size=8, required=True), - "custom_base_a_id": fields.many2one("testing.base.a", 'Base A', required=True, ondelete='CASCADE'), - "a1": fields.char(string="A1", size=8, required=True), - "a3": fields.char(string="A3", size=8, required=True), - } - - -class DelegationInheritance4(osv.Model): - """Test d'héritage par délégation""" - - _name = "testing.inheritance.delegation4" - - _description = "DelegationInheritance4" - - _inherits = { - "testing.base.a": "custom_base_a_id", - "testing.base.b": "custom_base_b_id", - } - - _columns = { - "name": fields.char(string="name", size=8, required=True), - "custom_base_a_id": fields.many2one("testing.base.a", 'Base A', required=True, ondelete='CASCADE'), - "custom_base_b_id": fields.many2one("testing.base.b", 'Base B', required=True, ondelete='CASCADE'), - "a1": fields.char(string="A1", size=8, required=True), - "a3": fields.char(string="A3", size=8, required=True), - "b1": fields.char(string="B1", size=8, required=True), - "b3": fields.char(string="B3", size=8, required=True), - } - diff --git a/testing.sql b/testing.sql deleted file mode 100644 index 8dd3538..0000000 --- a/testing.sql +++ /dev/null @@ -1,1189 +0,0 @@ --- --- Name: testing_base_a; Type: TABLE; Schema: public; Owner: openerp; Tablespace: --- - -CREATE TABLE testing_base_a ( - id integer NOT NULL, - create_uid integer, - create_date timestamp without time zone, - write_date timestamp without time zone, - write_uid integer, - a1 character varying(8) NOT NULL, - a2 character varying(8) NOT NULL, - name character varying(8) NOT NULL -); - - -ALTER TABLE public.testing_base_a OWNER TO openerp; - --- --- Name: TABLE testing_base_a; Type: COMMENT; Schema: public; Owner: openerp --- - -COMMENT ON TABLE testing_base_a IS 'BaseA'; - - --- --- Name: COLUMN testing_base_a.a1; Type: COMMENT; Schema: public; Owner: openerp --- - -COMMENT ON COLUMN testing_base_a.a1 IS 'A1'; - - --- --- Name: COLUMN testing_base_a.a2; Type: COMMENT; Schema: public; Owner: openerp --- - -COMMENT ON COLUMN testing_base_a.a2 IS 'A2'; - - --- --- Name: COLUMN testing_base_a.name; Type: COMMENT; Schema: public; Owner: openerp --- - -COMMENT ON COLUMN testing_base_a.name IS 'name'; - - --- --- Name: testing_base_a_id_seq; Type: SEQUENCE; Schema: public; Owner: openerp --- - -CREATE SEQUENCE testing_base_a_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - -ALTER TABLE public.testing_base_a_id_seq OWNER TO openerp; - --- --- Name: testing_base_a_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: openerp --- - -ALTER SEQUENCE testing_base_a_id_seq OWNED BY testing_base_a.id; - - --- --- Name: testing_base_b; Type: TABLE; Schema: public; Owner: openerp; Tablespace: --- - -CREATE TABLE testing_base_b ( - id integer NOT NULL, - create_uid integer, - create_date timestamp without time zone, - write_date timestamp without time zone, - write_uid integer, - name character varying(8) NOT NULL, - b2 character varying(8) NOT NULL, - b1 character varying(8) NOT NULL -); - - -ALTER TABLE public.testing_base_b OWNER TO openerp; - --- --- Name: TABLE testing_base_b; Type: COMMENT; Schema: public; Owner: openerp --- - -COMMENT ON TABLE testing_base_b IS 'BaseB'; - - --- --- Name: COLUMN testing_base_b.name; Type: COMMENT; Schema: public; Owner: openerp --- - -COMMENT ON COLUMN testing_base_b.name IS 'name'; - - --- --- Name: COLUMN testing_base_b.b2; Type: COMMENT; Schema: public; Owner: openerp --- - -COMMENT ON COLUMN testing_base_b.b2 IS 'B2'; - - --- --- Name: COLUMN testing_base_b.b1; Type: COMMENT; Schema: public; Owner: openerp --- - -COMMENT ON COLUMN testing_base_b.b1 IS 'B1'; - - --- --- Name: testing_base_b_id_seq; Type: SEQUENCE; Schema: public; Owner: openerp --- - -CREATE SEQUENCE testing_base_b_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - -ALTER TABLE public.testing_base_b_id_seq OWNER TO openerp; - --- --- Name: testing_base_b_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: openerp --- - -ALTER SEQUENCE testing_base_b_id_seq OWNED BY testing_base_b.id; - - --- --- Name: testing_base_c; Type: TABLE; Schema: public; Owner: openerp; Tablespace: --- - -CREATE TABLE testing_base_c ( - id integer NOT NULL, - create_uid integer, - create_date timestamp without time zone, - write_date timestamp without time zone, - write_uid integer, - c3 character varying(8) NOT NULL, - c2 character varying(8) NOT NULL, - c1 character varying(8) NOT NULL, - name character varying(8) NOT NULL -); - - -ALTER TABLE public.testing_base_c OWNER TO openerp; - --- --- Name: TABLE testing_base_c; Type: COMMENT; Schema: public; Owner: openerp --- - -COMMENT ON TABLE testing_base_c IS 'ClassInheritance'; - - --- --- Name: COLUMN testing_base_c.c3; Type: COMMENT; Schema: public; Owner: openerp --- - -COMMENT ON COLUMN testing_base_c.c3 IS 'C3'; - - --- --- Name: COLUMN testing_base_c.c2; Type: COMMENT; Schema: public; Owner: openerp --- - -COMMENT ON COLUMN testing_base_c.c2 IS 'C2'; - - --- --- Name: COLUMN testing_base_c.c1; Type: COMMENT; Schema: public; Owner: openerp --- - -COMMENT ON COLUMN testing_base_c.c1 IS 'C1'; - - --- --- Name: COLUMN testing_base_c.name; Type: COMMENT; Schema: public; Owner: openerp --- - -COMMENT ON COLUMN testing_base_c.name IS 'name'; - - --- --- Name: testing_base_c_id_seq; Type: SEQUENCE; Schema: public; Owner: openerp --- - -CREATE SEQUENCE testing_base_c_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - -ALTER TABLE public.testing_base_c_id_seq OWNER TO openerp; - --- --- Name: testing_base_c_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: openerp --- - -ALTER SEQUENCE testing_base_c_id_seq OWNED BY testing_base_c.id; - - --- --- Name: testing_base_d; Type: TABLE; Schema: public; Owner: openerp; Tablespace: --- - -CREATE TABLE testing_base_d ( - id integer NOT NULL, - create_uid integer, - create_date timestamp without time zone, - write_date timestamp without time zone, - write_uid integer, - d2 character varying(8) NOT NULL, - name character varying(8) NOT NULL, - d1 character varying(8) NOT NULL -); - - -ALTER TABLE public.testing_base_d OWNER TO openerp; - --- --- Name: TABLE testing_base_d; Type: COMMENT; Schema: public; Owner: openerp --- - -COMMENT ON TABLE testing_base_d IS 'BaseD'; - - --- --- Name: COLUMN testing_base_d.d2; Type: COMMENT; Schema: public; Owner: openerp --- - -COMMENT ON COLUMN testing_base_d.d2 IS 'D2'; - - --- --- Name: COLUMN testing_base_d.name; Type: COMMENT; Schema: public; Owner: openerp --- - -COMMENT ON COLUMN testing_base_d.name IS 'name'; - - --- --- Name: COLUMN testing_base_d.d1; Type: COMMENT; Schema: public; Owner: openerp --- - -COMMENT ON COLUMN testing_base_d.d1 IS 'D1'; - - --- --- Name: testing_base_d_id_seq; Type: SEQUENCE; Schema: public; Owner: openerp --- - -CREATE SEQUENCE testing_base_d_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - -ALTER TABLE public.testing_base_d_id_seq OWNER TO openerp; - --- --- Name: testing_base_d_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: openerp --- - -ALTER SEQUENCE testing_base_d_id_seq OWNED BY testing_base_d.id; - - --- --- Name: testing_inheritance_delegation1; Type: TABLE; Schema: public; Owner: openerp; Tablespace: --- - -CREATE TABLE testing_inheritance_delegation1 ( - id integer NOT NULL, - create_uid integer, - create_date timestamp without time zone, - write_date timestamp without time zone, - write_uid integer, - a1 character varying(8) NOT NULL, - a3 character varying(8) NOT NULL, - name character varying(8) NOT NULL, - custom_base_a_id integer NOT NULL -); - - -ALTER TABLE public.testing_inheritance_delegation1 OWNER TO openerp; - --- --- Name: TABLE testing_inheritance_delegation1; Type: COMMENT; Schema: public; Owner: openerp --- - -COMMENT ON TABLE testing_inheritance_delegation1 IS 'DelegationInheritance1'; - - --- --- Name: COLUMN testing_inheritance_delegation1.a1; Type: COMMENT; Schema: public; Owner: openerp --- - -COMMENT ON COLUMN testing_inheritance_delegation1.a1 IS 'A1'; - - --- --- Name: COLUMN testing_inheritance_delegation1.a3; Type: COMMENT; Schema: public; Owner: openerp --- - -COMMENT ON COLUMN testing_inheritance_delegation1.a3 IS 'A3'; - - --- --- Name: COLUMN testing_inheritance_delegation1.name; Type: COMMENT; Schema: public; Owner: openerp --- - -COMMENT ON COLUMN testing_inheritance_delegation1.name IS 'name'; - - --- --- Name: COLUMN testing_inheritance_delegation1.custom_base_a_id; Type: COMMENT; Schema: public; Owner: openerp --- - -COMMENT ON COLUMN testing_inheritance_delegation1.custom_base_a_id IS 'Automatically created field to link to parent testing.base.a'; - - --- --- Name: testing_inheritance_delegation1_id_seq; Type: SEQUENCE; Schema: public; Owner: openerp --- - -CREATE SEQUENCE testing_inheritance_delegation1_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - -ALTER TABLE public.testing_inheritance_delegation1_id_seq OWNER TO openerp; - --- --- Name: testing_inheritance_delegation1_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: openerp --- - -ALTER SEQUENCE testing_inheritance_delegation1_id_seq OWNED BY testing_inheritance_delegation1.id; - - --- --- Name: testing_inheritance_delegation2; Type: TABLE; Schema: public; Owner: openerp; Tablespace: --- - -CREATE TABLE testing_inheritance_delegation2 ( - id integer NOT NULL, - create_uid integer, - create_date timestamp without time zone, - write_date timestamp without time zone, - write_uid integer, - custom_base_a_id integer NOT NULL, - a1 character varying(8) NOT NULL, - a3 character varying(8) NOT NULL, - b1 character varying(8) NOT NULL, - b3 character varying(8) NOT NULL, - "custom_base_B_id" integer NOT NULL, - name character varying(8) NOT NULL -); - - -ALTER TABLE public.testing_inheritance_delegation2 OWNER TO openerp; - --- --- Name: TABLE testing_inheritance_delegation2; Type: COMMENT; Schema: public; Owner: openerp --- - -COMMENT ON TABLE testing_inheritance_delegation2 IS 'DelegationInheritance2'; - - --- --- Name: COLUMN testing_inheritance_delegation2.custom_base_a_id; Type: COMMENT; Schema: public; Owner: openerp --- - -COMMENT ON COLUMN testing_inheritance_delegation2.custom_base_a_id IS 'Automatically created field to link to parent testing.base.a'; - - --- --- Name: COLUMN testing_inheritance_delegation2.a1; Type: COMMENT; Schema: public; Owner: openerp --- - -COMMENT ON COLUMN testing_inheritance_delegation2.a1 IS 'A1'; - - --- --- Name: COLUMN testing_inheritance_delegation2.a3; Type: COMMENT; Schema: public; Owner: openerp --- - -COMMENT ON COLUMN testing_inheritance_delegation2.a3 IS 'A3'; - - --- --- Name: COLUMN testing_inheritance_delegation2.b1; Type: COMMENT; Schema: public; Owner: openerp --- - -COMMENT ON COLUMN testing_inheritance_delegation2.b1 IS 'B1'; - - --- --- Name: COLUMN testing_inheritance_delegation2.b3; Type: COMMENT; Schema: public; Owner: openerp --- - -COMMENT ON COLUMN testing_inheritance_delegation2.b3 IS 'B3'; - - --- --- Name: COLUMN testing_inheritance_delegation2."custom_base_B_id"; Type: COMMENT; Schema: public; Owner: openerp --- - -COMMENT ON COLUMN testing_inheritance_delegation2."custom_base_B_id" IS 'Automatically created field to link to parent testing.base.b'; - - --- --- Name: COLUMN testing_inheritance_delegation2.name; Type: COMMENT; Schema: public; Owner: openerp --- - -COMMENT ON COLUMN testing_inheritance_delegation2.name IS 'name'; - - --- --- Name: testing_inheritance_delegation2_id_seq; Type: SEQUENCE; Schema: public; Owner: openerp --- - -CREATE SEQUENCE testing_inheritance_delegation2_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - -ALTER TABLE public.testing_inheritance_delegation2_id_seq OWNER TO openerp; - --- --- Name: testing_inheritance_delegation2_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: openerp --- - -ALTER SEQUENCE testing_inheritance_delegation2_id_seq OWNED BY testing_inheritance_delegation2.id; - - --- --- Name: testing_inheritance_delegation3; Type: TABLE; Schema: public; Owner: openerp; Tablespace: --- - -CREATE TABLE testing_inheritance_delegation3 ( - id integer NOT NULL, - create_uid integer, - create_date timestamp without time zone, - write_date timestamp without time zone, - write_uid integer, - a1 character varying(8) NOT NULL, - a3 character varying(8) NOT NULL, - name character varying(8) NOT NULL, - custom_base_a_id integer NOT NULL -); - - -ALTER TABLE public.testing_inheritance_delegation3 OWNER TO openerp; - --- --- Name: TABLE testing_inheritance_delegation3; Type: COMMENT; Schema: public; Owner: openerp --- - -COMMENT ON TABLE testing_inheritance_delegation3 IS 'DelegationInheritance3'; - - --- --- Name: COLUMN testing_inheritance_delegation3.a1; Type: COMMENT; Schema: public; Owner: openerp --- - -COMMENT ON COLUMN testing_inheritance_delegation3.a1 IS 'A1'; - - --- --- Name: COLUMN testing_inheritance_delegation3.a3; Type: COMMENT; Schema: public; Owner: openerp --- - -COMMENT ON COLUMN testing_inheritance_delegation3.a3 IS 'A3'; - - --- --- Name: COLUMN testing_inheritance_delegation3.name; Type: COMMENT; Schema: public; Owner: openerp --- - -COMMENT ON COLUMN testing_inheritance_delegation3.name IS 'name'; - - --- --- Name: COLUMN testing_inheritance_delegation3.custom_base_a_id; Type: COMMENT; Schema: public; Owner: openerp --- - -COMMENT ON COLUMN testing_inheritance_delegation3.custom_base_a_id IS 'Base A'; - - --- --- Name: testing_inheritance_delegation3_id_seq; Type: SEQUENCE; Schema: public; Owner: openerp --- - -CREATE SEQUENCE testing_inheritance_delegation3_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - -ALTER TABLE public.testing_inheritance_delegation3_id_seq OWNER TO openerp; - --- --- Name: testing_inheritance_delegation3_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: openerp --- - -ALTER SEQUENCE testing_inheritance_delegation3_id_seq OWNED BY testing_inheritance_delegation3.id; - - --- --- Name: testing_inheritance_delegation4; Type: TABLE; Schema: public; Owner: openerp; Tablespace: --- - -CREATE TABLE testing_inheritance_delegation4 ( - id integer NOT NULL, - create_uid integer, - create_date timestamp without time zone, - write_date timestamp without time zone, - write_uid integer, - a1 character varying(8) NOT NULL, - a3 character varying(8) NOT NULL, - name character varying(8) NOT NULL, - b3 character varying(8) NOT NULL, - custom_base_b_id integer NOT NULL, - custom_base_a_id integer NOT NULL, - b1 character varying(8) NOT NULL -); - - -ALTER TABLE public.testing_inheritance_delegation4 OWNER TO openerp; - --- --- Name: TABLE testing_inheritance_delegation4; Type: COMMENT; Schema: public; Owner: openerp --- - -COMMENT ON TABLE testing_inheritance_delegation4 IS 'DelegationInheritance4'; - - --- --- Name: COLUMN testing_inheritance_delegation4.a1; Type: COMMENT; Schema: public; Owner: openerp --- - -COMMENT ON COLUMN testing_inheritance_delegation4.a1 IS 'A1'; - - --- --- Name: COLUMN testing_inheritance_delegation4.a3; Type: COMMENT; Schema: public; Owner: openerp --- - -COMMENT ON COLUMN testing_inheritance_delegation4.a3 IS 'A3'; - - --- --- Name: COLUMN testing_inheritance_delegation4.name; Type: COMMENT; Schema: public; Owner: openerp --- - -COMMENT ON COLUMN testing_inheritance_delegation4.name IS 'name'; - - --- --- Name: COLUMN testing_inheritance_delegation4.b3; Type: COMMENT; Schema: public; Owner: openerp --- - -COMMENT ON COLUMN testing_inheritance_delegation4.b3 IS 'B3'; - - --- --- Name: COLUMN testing_inheritance_delegation4.custom_base_b_id; Type: COMMENT; Schema: public; Owner: openerp --- - -COMMENT ON COLUMN testing_inheritance_delegation4.custom_base_b_id IS 'Base B'; - - --- --- Name: COLUMN testing_inheritance_delegation4.custom_base_a_id; Type: COMMENT; Schema: public; Owner: openerp --- - -COMMENT ON COLUMN testing_inheritance_delegation4.custom_base_a_id IS 'Base A'; - - --- --- Name: COLUMN testing_inheritance_delegation4.b1; Type: COMMENT; Schema: public; Owner: openerp --- - -COMMENT ON COLUMN testing_inheritance_delegation4.b1 IS 'B1'; - - --- --- Name: testing_inheritance_delegation4_id_seq; Type: SEQUENCE; Schema: public; Owner: openerp --- - -CREATE SEQUENCE testing_inheritance_delegation4_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - -ALTER TABLE public.testing_inheritance_delegation4_id_seq OWNER TO openerp; - --- --- Name: testing_inheritance_delegation4_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: openerp --- - -ALTER SEQUENCE testing_inheritance_delegation4_id_seq OWNED BY testing_inheritance_delegation4.id; - - --- --- Name: testing_inheritance_prototype; Type: TABLE; Schema: public; Owner: openerp; Tablespace: --- - -CREATE TABLE testing_inheritance_prototype ( - id integer NOT NULL, - create_uid integer, - create_date timestamp without time zone, - write_date timestamp without time zone, - write_uid integer, - d1 character varying(8) NOT NULL, - d2 character varying(8) NOT NULL, - name character varying(8) NOT NULL, - d3 character varying(8) NOT NULL -); - - -ALTER TABLE public.testing_inheritance_prototype OWNER TO openerp; - --- --- Name: TABLE testing_inheritance_prototype; Type: COMMENT; Schema: public; Owner: openerp --- - -COMMENT ON TABLE testing_inheritance_prototype IS 'PrototypeInheritance'; - - --- --- Name: COLUMN testing_inheritance_prototype.d1; Type: COMMENT; Schema: public; Owner: openerp --- - -COMMENT ON COLUMN testing_inheritance_prototype.d1 IS 'D1'; - - --- --- Name: COLUMN testing_inheritance_prototype.d2; Type: COMMENT; Schema: public; Owner: openerp --- - -COMMENT ON COLUMN testing_inheritance_prototype.d2 IS 'D2'; - - --- --- Name: COLUMN testing_inheritance_prototype.name; Type: COMMENT; Schema: public; Owner: openerp --- - -COMMENT ON COLUMN testing_inheritance_prototype.name IS 'name'; - - --- --- Name: COLUMN testing_inheritance_prototype.d3; Type: COMMENT; Schema: public; Owner: openerp --- - -COMMENT ON COLUMN testing_inheritance_prototype.d3 IS 'D3'; - - --- --- Name: testing_inheritance_prototype_id_seq; Type: SEQUENCE; Schema: public; Owner: openerp --- - -CREATE SEQUENCE testing_inheritance_prototype_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - -ALTER TABLE public.testing_inheritance_prototype_id_seq OWNER TO openerp; - --- --- Name: testing_inheritance_prototype_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: openerp --- - -ALTER SEQUENCE testing_inheritance_prototype_id_seq OWNED BY testing_inheritance_prototype.id; - - - - - - - - --- --- Name: id; Type: DEFAULT; Schema: public; Owner: openerp --- - -ALTER TABLE ONLY testing_base_a ALTER COLUMN id SET DEFAULT nextval('testing_base_a_id_seq'::regclass); - - --- --- Name: id; Type: DEFAULT; Schema: public; Owner: openerp --- - -ALTER TABLE ONLY testing_base_b ALTER COLUMN id SET DEFAULT nextval('testing_base_b_id_seq'::regclass); - - --- --- Name: id; Type: DEFAULT; Schema: public; Owner: openerp --- - -ALTER TABLE ONLY testing_base_c ALTER COLUMN id SET DEFAULT nextval('testing_base_c_id_seq'::regclass); - - --- --- Name: id; Type: DEFAULT; Schema: public; Owner: openerp --- - -ALTER TABLE ONLY testing_base_d ALTER COLUMN id SET DEFAULT nextval('testing_base_d_id_seq'::regclass); - - --- --- Name: id; Type: DEFAULT; Schema: public; Owner: openerp --- - -ALTER TABLE ONLY testing_inheritance_delegation1 ALTER COLUMN id SET DEFAULT nextval('testing_inheritance_delegation1_id_seq'::regclass); - - --- --- Name: id; Type: DEFAULT; Schema: public; Owner: openerp --- - -ALTER TABLE ONLY testing_inheritance_delegation2 ALTER COLUMN id SET DEFAULT nextval('testing_inheritance_delegation2_id_seq'::regclass); - - --- --- Name: id; Type: DEFAULT; Schema: public; Owner: openerp --- - -ALTER TABLE ONLY testing_inheritance_delegation3 ALTER COLUMN id SET DEFAULT nextval('testing_inheritance_delegation3_id_seq'::regclass); - - --- --- Name: id; Type: DEFAULT; Schema: public; Owner: openerp --- - -ALTER TABLE ONLY testing_inheritance_delegation4 ALTER COLUMN id SET DEFAULT nextval('testing_inheritance_delegation4_id_seq'::regclass); - - --- --- Name: id; Type: DEFAULT; Schema: public; Owner: openerp --- - -ALTER TABLE ONLY testing_inheritance_prototype ALTER COLUMN id SET DEFAULT nextval('testing_inheritance_prototype_id_seq'::regclass); - - - - - - - - - - --- --- Data for Name: testing_base_a; Type: TABLE DATA; Schema: public; Owner: openerp --- - -COPY testing_base_a (id, create_uid, create_date, write_date, write_uid, a1, a2, name) FROM stdin; -\. - - --- --- Name: testing_base_a_id_seq; Type: SEQUENCE SET; Schema: public; Owner: openerp --- - -SELECT pg_catalog.setval('testing_base_a_id_seq', 1, false); - - --- --- Data for Name: testing_base_b; Type: TABLE DATA; Schema: public; Owner: openerp --- - -COPY testing_base_b (id, create_uid, create_date, write_date, write_uid, name, b2, b1) FROM stdin; -\. - - --- --- Name: testing_base_b_id_seq; Type: SEQUENCE SET; Schema: public; Owner: openerp --- - -SELECT pg_catalog.setval('testing_base_b_id_seq', 1, false); - - --- --- Data for Name: testing_base_c; Type: TABLE DATA; Schema: public; Owner: openerp --- - -COPY testing_base_c (id, create_uid, create_date, write_date, write_uid, c3, c2, c1, name) FROM stdin; -\. - - --- --- Name: testing_base_c_id_seq; Type: SEQUENCE SET; Schema: public; Owner: openerp --- - -SELECT pg_catalog.setval('testing_base_c_id_seq', 1, false); - - --- --- Data for Name: testing_base_d; Type: TABLE DATA; Schema: public; Owner: openerp --- - -COPY testing_base_d (id, create_uid, create_date, write_date, write_uid, d2, name, d1) FROM stdin; -\. - - --- --- Name: testing_base_d_id_seq; Type: SEQUENCE SET; Schema: public; Owner: openerp --- - -SELECT pg_catalog.setval('testing_base_d_id_seq', 1, false); - - --- --- Data for Name: testing_inheritance_delegation1; Type: TABLE DATA; Schema: public; Owner: openerp --- - -COPY testing_inheritance_delegation1 (id, create_uid, create_date, write_date, write_uid, a1, a3, name, custom_base_a_id) FROM stdin; -\. - - --- --- Name: testing_inheritance_delegation1_id_seq; Type: SEQUENCE SET; Schema: public; Owner: openerp --- - -SELECT pg_catalog.setval('testing_inheritance_delegation1_id_seq', 1, false); - - --- --- Data for Name: testing_inheritance_delegation2; Type: TABLE DATA; Schema: public; Owner: openerp --- - -COPY testing_inheritance_delegation2 (id, create_uid, create_date, write_date, write_uid, custom_base_a_id, a1, a3, b1, b3, "custom_base_B_id", name) FROM stdin; -\. - - --- --- Name: testing_inheritance_delegation2_id_seq; Type: SEQUENCE SET; Schema: public; Owner: openerp --- - -SELECT pg_catalog.setval('testing_inheritance_delegation2_id_seq', 1, false); - - --- --- Data for Name: testing_inheritance_delegation3; Type: TABLE DATA; Schema: public; Owner: openerp --- - -COPY testing_inheritance_delegation3 (id, create_uid, create_date, write_date, write_uid, a1, a3, name, custom_base_a_id) FROM stdin; -\. - - --- --- Name: testing_inheritance_delegation3_id_seq; Type: SEQUENCE SET; Schema: public; Owner: openerp --- - -SELECT pg_catalog.setval('testing_inheritance_delegation3_id_seq', 1, false); - - --- --- Data for Name: testing_inheritance_delegation4; Type: TABLE DATA; Schema: public; Owner: openerp --- - -COPY testing_inheritance_delegation4 (id, create_uid, create_date, write_date, write_uid, a1, a3, name, b3, custom_base_b_id, custom_base_a_id, b1) FROM stdin; -\. - - --- --- Name: testing_inheritance_delegation4_id_seq; Type: SEQUENCE SET; Schema: public; Owner: openerp --- - -SELECT pg_catalog.setval('testing_inheritance_delegation4_id_seq', 1, false); - - --- --- Data for Name: testing_inheritance_prototype; Type: TABLE DATA; Schema: public; Owner: openerp --- - -COPY testing_inheritance_prototype (id, create_uid, create_date, write_date, write_uid, d1, d2, name, d3) FROM stdin; -\. - - --- --- Name: testing_inheritance_prototype_id_seq; Type: SEQUENCE SET; Schema: public; Owner: openerp --- - -SELECT pg_catalog.setval('testing_inheritance_prototype_id_seq', 1, false); - - - - - - - - - - --- --- Name: testing_base_a_pkey; Type: CONSTRAINT; Schema: public; Owner: openerp; Tablespace: --- - -ALTER TABLE ONLY testing_base_a - ADD CONSTRAINT testing_base_a_pkey PRIMARY KEY (id); - - --- --- Name: testing_base_b_pkey; Type: CONSTRAINT; Schema: public; Owner: openerp; Tablespace: --- - -ALTER TABLE ONLY testing_base_b - ADD CONSTRAINT testing_base_b_pkey PRIMARY KEY (id); - - --- --- Name: testing_base_c_pkey; Type: CONSTRAINT; Schema: public; Owner: openerp; Tablespace: --- - -ALTER TABLE ONLY testing_base_c - ADD CONSTRAINT testing_base_c_pkey PRIMARY KEY (id); - - --- --- Name: testing_base_d_pkey; Type: CONSTRAINT; Schema: public; Owner: openerp; Tablespace: --- - -ALTER TABLE ONLY testing_base_d - ADD CONSTRAINT testing_base_d_pkey PRIMARY KEY (id); - - --- --- Name: testing_inheritance_delegation1_pkey; Type: CONSTRAINT; Schema: public; Owner: openerp; Tablespace: --- - -ALTER TABLE ONLY testing_inheritance_delegation1 - ADD CONSTRAINT testing_inheritance_delegation1_pkey PRIMARY KEY (id); - - --- --- Name: testing_inheritance_delegation2_pkey; Type: CONSTRAINT; Schema: public; Owner: openerp; Tablespace: --- - -ALTER TABLE ONLY testing_inheritance_delegation2 - ADD CONSTRAINT testing_inheritance_delegation2_pkey PRIMARY KEY (id); - - --- --- Name: testing_inheritance_delegation3_pkey; Type: CONSTRAINT; Schema: public; Owner: openerp; Tablespace: --- - -ALTER TABLE ONLY testing_inheritance_delegation3 - ADD CONSTRAINT testing_inheritance_delegation3_pkey PRIMARY KEY (id); - - --- --- Name: testing_inheritance_delegation4_pkey; Type: CONSTRAINT; Schema: public; Owner: openerp; Tablespace: --- - -ALTER TABLE ONLY testing_inheritance_delegation4 - ADD CONSTRAINT testing_inheritance_delegation4_pkey PRIMARY KEY (id); - - --- --- Name: testing_inheritance_prototype_pkey; Type: CONSTRAINT; Schema: public; Owner: openerp; Tablespace: --- - -ALTER TABLE ONLY testing_inheritance_prototype - ADD CONSTRAINT testing_inheritance_prototype_pkey PRIMARY KEY (id); - - - - - - - - - - --- --- Name: testing_base_a_create_uid_fkey; Type: FK CONSTRAINT; Schema: public; Owner: openerp --- - -ALTER TABLE ONLY testing_base_a - ADD CONSTRAINT testing_base_a_create_uid_fkey FOREIGN KEY (create_uid) REFERENCES res_users(id) ON DELETE SET NULL; - - --- --- Name: testing_base_a_write_uid_fkey; Type: FK CONSTRAINT; Schema: public; Owner: openerp --- - -ALTER TABLE ONLY testing_base_a - ADD CONSTRAINT testing_base_a_write_uid_fkey FOREIGN KEY (write_uid) REFERENCES res_users(id) ON DELETE SET NULL; - - --- --- Name: testing_base_b_create_uid_fkey; Type: FK CONSTRAINT; Schema: public; Owner: openerp --- - -ALTER TABLE ONLY testing_base_b - ADD CONSTRAINT testing_base_b_create_uid_fkey FOREIGN KEY (create_uid) REFERENCES res_users(id) ON DELETE SET NULL; - - --- --- Name: testing_base_b_write_uid_fkey; Type: FK CONSTRAINT; Schema: public; Owner: openerp --- - -ALTER TABLE ONLY testing_base_b - ADD CONSTRAINT testing_base_b_write_uid_fkey FOREIGN KEY (write_uid) REFERENCES res_users(id) ON DELETE SET NULL; - - --- --- Name: testing_base_c_create_uid_fkey; Type: FK CONSTRAINT; Schema: public; Owner: openerp --- - -ALTER TABLE ONLY testing_base_c - ADD CONSTRAINT testing_base_c_create_uid_fkey FOREIGN KEY (create_uid) REFERENCES res_users(id) ON DELETE SET NULL; - - --- --- Name: testing_base_c_write_uid_fkey; Type: FK CONSTRAINT; Schema: public; Owner: openerp --- - -ALTER TABLE ONLY testing_base_c - ADD CONSTRAINT testing_base_c_write_uid_fkey FOREIGN KEY (write_uid) REFERENCES res_users(id) ON DELETE SET NULL; - - --- --- Name: testing_base_d_create_uid_fkey; Type: FK CONSTRAINT; Schema: public; Owner: openerp --- - -ALTER TABLE ONLY testing_base_d - ADD CONSTRAINT testing_base_d_create_uid_fkey FOREIGN KEY (create_uid) REFERENCES res_users(id) ON DELETE SET NULL; - - --- --- Name: testing_base_d_write_uid_fkey; Type: FK CONSTRAINT; Schema: public; Owner: openerp --- - -ALTER TABLE ONLY testing_base_d - ADD CONSTRAINT testing_base_d_write_uid_fkey FOREIGN KEY (write_uid) REFERENCES res_users(id) ON DELETE SET NULL; - - --- --- Name: testing_inheritance_delegation1_create_uid_fkey; Type: FK CONSTRAINT; Schema: public; Owner: openerp --- - -ALTER TABLE ONLY testing_inheritance_delegation1 - ADD CONSTRAINT testing_inheritance_delegation1_create_uid_fkey FOREIGN KEY (create_uid) REFERENCES res_users(id) ON DELETE SET NULL; - - --- --- Name: testing_inheritance_delegation1_custom_base_a_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: openerp --- - -ALTER TABLE ONLY testing_inheritance_delegation1 - ADD CONSTRAINT testing_inheritance_delegation1_custom_base_a_id_fkey FOREIGN KEY (custom_base_a_id) REFERENCES testing_base_a(id) ON DELETE CASCADE; - - --- --- Name: testing_inheritance_delegation1_write_uid_fkey; Type: FK CONSTRAINT; Schema: public; Owner: openerp --- - -ALTER TABLE ONLY testing_inheritance_delegation1 - ADD CONSTRAINT testing_inheritance_delegation1_write_uid_fkey FOREIGN KEY (write_uid) REFERENCES res_users(id) ON DELETE SET NULL; - - --- --- Name: testing_inheritance_delegation2_create_uid_fkey; Type: FK CONSTRAINT; Schema: public; Owner: openerp --- - -ALTER TABLE ONLY testing_inheritance_delegation2 - ADD CONSTRAINT testing_inheritance_delegation2_create_uid_fkey FOREIGN KEY (create_uid) REFERENCES res_users(id) ON DELETE SET NULL; - - --- --- Name: testing_inheritance_delegation2_custom_base_B_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: openerp --- - -ALTER TABLE ONLY testing_inheritance_delegation2 - ADD CONSTRAINT "testing_inheritance_delegation2_custom_base_B_id_fkey" FOREIGN KEY ("custom_base_B_id") REFERENCES testing_base_b(id) ON DELETE CASCADE; - - --- --- Name: testing_inheritance_delegation2_custom_base_a_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: openerp --- - -ALTER TABLE ONLY testing_inheritance_delegation2 - ADD CONSTRAINT testing_inheritance_delegation2_custom_base_a_id_fkey FOREIGN KEY (custom_base_a_id) REFERENCES testing_base_a(id) ON DELETE CASCADE; - - --- --- Name: testing_inheritance_delegation2_write_uid_fkey; Type: FK CONSTRAINT; Schema: public; Owner: openerp --- - -ALTER TABLE ONLY testing_inheritance_delegation2 - ADD CONSTRAINT testing_inheritance_delegation2_write_uid_fkey FOREIGN KEY (write_uid) REFERENCES res_users(id) ON DELETE SET NULL; - - --- --- Name: testing_inheritance_delegation3_create_uid_fkey; Type: FK CONSTRAINT; Schema: public; Owner: openerp --- - -ALTER TABLE ONLY testing_inheritance_delegation3 - ADD CONSTRAINT testing_inheritance_delegation3_create_uid_fkey FOREIGN KEY (create_uid) REFERENCES res_users(id) ON DELETE SET NULL; - - --- --- Name: testing_inheritance_delegation3_custom_base_a_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: openerp --- - -ALTER TABLE ONLY testing_inheritance_delegation3 - ADD CONSTRAINT testing_inheritance_delegation3_custom_base_a_id_fkey FOREIGN KEY (custom_base_a_id) REFERENCES testing_base_a(id) ON DELETE CASCADE; - - --- --- Name: testing_inheritance_delegation3_write_uid_fkey; Type: FK CONSTRAINT; Schema: public; Owner: openerp --- - -ALTER TABLE ONLY testing_inheritance_delegation3 - ADD CONSTRAINT testing_inheritance_delegation3_write_uid_fkey FOREIGN KEY (write_uid) REFERENCES res_users(id) ON DELETE SET NULL; - - --- --- Name: testing_inheritance_delegation4_create_uid_fkey; Type: FK CONSTRAINT; Schema: public; Owner: openerp --- - -ALTER TABLE ONLY testing_inheritance_delegation4 - ADD CONSTRAINT testing_inheritance_delegation4_create_uid_fkey FOREIGN KEY (create_uid) REFERENCES res_users(id) ON DELETE SET NULL; - - --- --- Name: testing_inheritance_delegation4_custom_base_a_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: openerp --- - -ALTER TABLE ONLY testing_inheritance_delegation4 - ADD CONSTRAINT testing_inheritance_delegation4_custom_base_a_id_fkey FOREIGN KEY (custom_base_a_id) REFERENCES testing_base_a(id) ON DELETE CASCADE; - - --- --- Name: testing_inheritance_delegation4_custom_base_b_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: openerp --- - -ALTER TABLE ONLY testing_inheritance_delegation4 - ADD CONSTRAINT testing_inheritance_delegation4_custom_base_b_id_fkey FOREIGN KEY (custom_base_b_id) REFERENCES testing_base_b(id) ON DELETE CASCADE; - - --- --- Name: testing_inheritance_delegation4_write_uid_fkey; Type: FK CONSTRAINT; Schema: public; Owner: openerp --- - -ALTER TABLE ONLY testing_inheritance_delegation4 - ADD CONSTRAINT testing_inheritance_delegation4_write_uid_fkey FOREIGN KEY (write_uid) REFERENCES res_users(id) ON DELETE SET NULL; - - --- --- Name: testing_inheritance_prototype_create_uid_fkey; Type: FK CONSTRAINT; Schema: public; Owner: openerp --- - -ALTER TABLE ONLY testing_inheritance_prototype - ADD CONSTRAINT testing_inheritance_prototype_create_uid_fkey FOREIGN KEY (create_uid) REFERENCES res_users(id) ON DELETE SET NULL; - - --- --- Name: testing_inheritance_prototype_write_uid_fkey; Type: FK CONSTRAINT; Schema: public; Owner: openerp --- - -ALTER TABLE ONLY testing_inheritance_prototype - ADD CONSTRAINT testing_inheritance_prototype_write_uid_fkey FOREIGN KEY (write_uid) REFERENCES res_users(id) ON DELETE SET NULL; diff --git a/testing_fields.py b/testing_fields.py new file mode 100644 index 0000000..00bac93 --- /dev/null +++ b/testing_fields.py @@ -0,0 +1,89 @@ +#-*- coding: utf8 -*- +from openerp.osv import osv, fields + + +class FieldTesting(osv.Model): + """Classe permettant de tester les principaux types de données""" + + # Nom de la table dans la base de données + _name= "testing.fieldtesting" + + # Description de la table + _description = "FieldTesting" + + # Utile pour le champs sélection à venir + SELECTION = [ + ('key1', 'value1'), + ('key2', 'value2'), + ('key3', 'value3'), + ] + + # Utile pour le champs fonction à venir + def _func_test_proc(self, cr, uid, ids, field, arg, context=None): + """ + Champs fonction : + à haut niveau, il semble être un champs de la base comme un autre + à bas niveau, il est en réalité calculé + + Il faut comprendre la signature de la méthode, la clé de l'ORM de OpenERP : + cr = curseur vers la bdd PGSQL, passé à toutes les méthodes en première position + uid = uid de l'utilisateur courant (permet de savoir s'il a le droit d'être là, par rapport à des permissions (hors périmètre), passé à toutes les méthodes en seconde position + ids = liste des id pour lesquels le champs fonction est calculé (plusieurs dans une vue liste, un seul dans une vue formulaire) + field = nom du champs associé + arg = éventuel argument donné dans la déclaration du champs fonction + context = contexte, objet non obligatoire donné en paramètre dans les fonctions d'OpenERP, il n'est pas forcément utilisé, mais peut contenir le contexte utilisateur (langue, par exemple, ...) + + On utilise ici un self.browse, ce qui va faire une requête sur tous les champs dans la base et va permettre de les parcourir. + """ + # On crée un dictionnaire, qui va contenir chaque id en tant que clé et chaque valeur calculée en tant que valeur + result={} + # Si j'ai une liste de X ids, le browse va me ramener X enregistrement. + for test_obj in self.browse(cr, uid, ids, context=context): + # Pour chaque enregistrement, on réalise l'association entre l'identifiant et la valeur du champs + result[test_obj.id] = test_obj.float + test_obj.integer + return result + + # Utile pour le champs fonction à venir + def _func_test_fonc(self, cr, uid, ids, field, arg, context=None): + """ + Ce qui suit est exactement identique à la fonction précédente, + mais écrit en utilsant le paradigme fonctionnel + """ + # On utilise normalement des noms de variables plus courts dans une écriture fonctionnelle, + # mais pour illustrer le fait qu'il s'agit du même algo, on a laissé des noms identiques. + + # les accolades délimitent ici un dictionnaire, et les deux points la séparation entre clé et valeur. + # Ce qui suit après le for décrit l'itération. + #return {test_obj.id: test_obj.float + test_obj.integer for test_obj in self.browse(cr, uid, ids, context=context)} + return dict((test_obj.id, test_obj.float + test_obj.integer) for test_obj in self.browse(cr, uid, ids, context=context)) + + _columns = { + # Par défaut, on a toujours un id, pas besoin de le préciser. + + # Voici quelques champs classiques + "char": fields.char(string="Champs principal", size=8, required=True, select=True), + "bool": fields.boolean(string='Champs booléen', required=True), + "date": fields.date(string='Champs date'), + "datetime": fields.datetime(string='Champs date', select=True), + "float": fields.float(string="Champs flottant", digits=(6,2), required=True), + "integer": fields.integer(string="Champs entier", required=True), + "selection": fields.selection(selection=SELECTION, string="Champs sélection"), + + # Voici des clés étrangères + "parent": fields.many2one(obj="testing.fieldtesting", string="Parent"), + "freres": fields.many2many(obj="testing.fieldtesting", rel="testing_fieldtesting_association", id1="gauche", id2="droite", string="Frères"), + + # Voici un champs fonction + "function_proc": fields.function(_func_test_proc, type="float", string="Champs fonction"), + "function_fonc": fields.function(_func_test_fonc, type="float", store=True, string="Champs fonction"), + } + + # par défaut, il faut toujours un champs "name", il s'agit du champs principal + # Comme ce n'est pas le cas ici, on doit dire quel est le champs qui est le champs principal + _rec_name = "char" + + _defaults = { + "date": fields.date.today(), + "datetime": fields.datetime.now(), + } + diff --git a/testing_inheritance.py b/testing_inheritance.py new file mode 100644 index 0000000..b0dc708 --- /dev/null +++ b/testing_inheritance.py @@ -0,0 +1,168 @@ +#-*- coding: utf8 -*- +from openerp.osv import osv, fields + + +class BaseA(osv.Model): + """Classe parente A""" + + _name = "testing.base.a" + + _description = "BaseA" + + _columns = { + "name": fields.char(string="name", size=8, required=True), + "a1": fields.char(string="A1", size=8, required=True), + "a2": fields.char(string="A2", size=8, required=True), + } + + +class BaseB(osv.Model): + """Classe parente B""" + + _name = "testing.base.b" + + _description = "BaseB" + + _columns = { + "name": fields.char(string="name", size=8, required=True), + "b1": fields.char(string="B1", size=8, required=True), + "b2": fields.char(string="B2", size=8, required=True), + } + + +class BaseC(osv.Model): + """Classe parente C""" + + _name = "testing.base.c" + + _description = "BaseC" + + _columns = { + "name": fields.char(string="name", size=8, required=True), + "c1": fields.char(string="C1", size=8, required=True), + "c2": fields.char(string="C2", size=8, required=True), + } + + +class BaseD(osv.Model): + """Classe parente D""" + + _name = "testing.base.d" + + _description = "BaseD" + + _columns = { + "name": fields.char(string="name", size=8, required=True), + "d1": fields.char(string="D1", size=8, required=True), + "d2": fields.char(string="D2", size=8, required=True), + } + + +class ClassInheritance(osv.Model): + """Test d'héritage de classe""" + + _name = "testing.base.c" + + _description = "ClassInheritance" + + _inherit = "testing.base.c" + + _columns = { + "name": fields.char(string="name", size=8, required=True), + "c1": fields.char(string="C1", size=8, required=True), + "c3": fields.char(string="C3", size=8, required=True), + } + + +class PrototypeInheritance(osv.Model): + """Test d'héritage de prototype""" + + _name = "testing.inheritance.prototype" + + _description = "PrototypeInheritance" + + _inherit = "testing.base.d" + + _columns = { + "name": fields.char(string="name", size=8, required=True), + "d1": fields.char(string="D1", size=8, required=True), + "d3": fields.char(string="D3", size=8, required=True), + } + + +class DelegationInheritance1(osv.Model): + """Test d'héritage par délégation""" + + _name = "testing.inheritance.delegation1" + + _description = "DelegationInheritance1" + + _inherits = {"testing.base.a": "custom_base_a_id"} + + _columns = { + "name": fields.char(string="name", size=8, required=True), + "a1": fields.char(string="A1", size=8, required=True), + "a3": fields.char(string="A3", size=8, required=True), + } + + +class DelegationInheritance2(osv.Model): + """Test d'héritage par délégation""" + + _name = "testing.inheritance.delegation2" + + _description = "DelegationInheritance2" + + _inherits = { + "testing.base.a": "custom_base_a_id", + "testing.base.b": "custom_base_b_id", + } + + _columns = { + "name": fields.char(string="name", size=8, required=True), + "a1": fields.char(string="A1", size=8, required=True), + "a3": fields.char(string="A3", size=8, required=True), + "b1": fields.char(string="B1", size=8, required=True), + "b3": fields.char(string="B3", size=8, required=True), + } + + +class DelegationInheritance3(osv.Model): + """Test d'héritage par délégation""" + + _name = "testing.inheritance.delegation3" + + _description = "DelegationInheritance3" + + _inherits = {"testing.base.a": "custom_base_a_id"} + + _columns = { + "name": fields.char(string="name", size=8, required=True), + "custom_base_a_id": fields.many2one("testing.base.a", 'Base A', required=True, ondelete='CASCADE'), + "a1": fields.char(string="A1", size=8, required=True), + "a3": fields.char(string="A3", size=8, required=True), + } + + +class DelegationInheritance4(osv.Model): + """Test d'héritage par délégation""" + + _name = "testing.inheritance.delegation4" + + _description = "DelegationInheritance4" + + _inherits = { + "testing.base.a": "custom_base_a_id", + "testing.base.b": "custom_base_b_id", + } + + _columns = { + "name": fields.char(string="name", size=8, required=True), + "custom_base_a_id": fields.many2one("testing.base.a", 'Base A', required=True, ondelete='CASCADE'), + "custom_base_b_id": fields.many2one("testing.base.b", 'Base B', required=True, ondelete='CASCADE'), + "a1": fields.char(string="A1", size=8, required=True), + "a3": fields.char(string="A3", size=8, required=True), + "b1": fields.char(string="B1", size=8, required=True), + "b3": fields.char(string="B3", size=8, required=True), + } + diff --git a/views/menu.xml b/views/menu.xml new file mode 100644 index 0000000..94b94dc --- /dev/null +++ b/views/menu.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/views/menu_fields.xml b/views/menu_fields.xml new file mode 100644 index 0000000..9b389bb --- /dev/null +++ b/views/menu_fields.xml @@ -0,0 +1,17 @@ + + + + + + + FieldTesting + testing.fieldtesting + tree,form + + + + + + + + diff --git a/views/menu_inheritance.xml b/views/menu_inheritance.xml new file mode 100644 index 0000000..7442739 --- /dev/null +++ b/views/menu_inheritance.xml @@ -0,0 +1,73 @@ + + + + + + + BaseA + testing.base.a + tree,form + + + + BaseB + testing.base.b + tree,form + + + + BaseC (ClassInheritance) + testing.base.c + tree,form + + + + BaseD (PrototypeInheritance) + testing.base.d + tree,form + + + + PrototypeInheritance (BaseD) + testing.inheritance.prototype + tree,form + + + + DelegationInheritance1 (BaseA) + testing.inheritance.delegation1 + tree,form + + + + DelegationInheritance2 (BaseA, BaseB) + testing.inheritance.delegation2 + tree,form + + + + DelegationInheritance3 (BaseA) + testing.inheritance.delegation3 + tree,form + + + + DelegationInheritance4 (BaseA, BaseB) + testing.inheritance.delegation4 + tree,form + + + + + + + + + + + + + + + + -- 1.7.10.4