Browse Source

:Dec 15 [UPDT] Feature Updated 'instant_import'

17.0
Risvana Cybro 1 day ago
parent
commit
62532f70d6
  1. 28
      instant_import/hooks.py
  2. 47
      instant_import/static/description/index.html
  3. 1968
      instant_import/wizard/import_wizard.py

28
instant_import/hooks.py

@ -22,7 +22,7 @@
def setup_db_level_functions(env): def setup_db_level_functions(env):
env.cr.execute( env.cr.execute(
""" """
CREATE OR REPLACE FUNCTION process_m2m_mapping() CREATE OR REPLACE FUNCTION process_m2m_mapping()
RETURNS TRIGGER AS $$ RETURNS TRIGGER AS $$
DECLARE DECLARE
col record; col record;
@ -35,7 +35,7 @@ def setup_db_level_functions(env):
column_type text; column_type text;
field_config jsonb; field_config jsonb;
BEGIN BEGIN
-- Get the mapping configuration from TG_ARGV[0] -- Get the mapping configuration from TG_ARGV[0]
-- Expected format: -- Expected format:
-- { -- {
-- "m2m__field1": {"data_table": "table1", "mapping_table": "map1", "column1": "col1", "column2": "col2"}, -- "m2m__field1": {"data_table": "table1", "mapping_table": "map1", "column1": "col1", "column2": "col2"},
@ -45,8 +45,8 @@ def setup_db_level_functions(env):
-- Loop through all columns of the table -- Loop through all columns of the table
FOR col IN ( FOR col IN (
SELECT column_name SELECT column_name
FROM information_schema.columns FROM information_schema.columns
WHERE table_name = TG_TABLE_NAME::text WHERE table_name = TG_TABLE_NAME::text
AND column_name LIKE 'm2m__%' AND column_name LIKE 'm2m__%'
) LOOP ) LOOP
@ -62,9 +62,9 @@ def setup_db_level_functions(env):
-- Get the data type of the name column -- Get the data type of the name column
EXECUTE format( EXECUTE format(
'SELECT data_type 'SELECT data_type
FROM information_schema.columns FROM information_schema.columns
WHERE table_name = %L WHERE table_name = %L
AND column_name = ''name''', AND column_name = ''name''',
field_config->>'data_table' field_config->>'data_table'
) INTO column_type; ) INTO column_type;
@ -104,8 +104,8 @@ def setup_db_level_functions(env):
-- Insert into mapping table if both IDs are found -- Insert into mapping table if both IDs are found
IF id1 IS NOT NULL AND id2 IS NOT NULL THEN IF id1 IS NOT NULL AND id2 IS NOT NULL THEN
EXECUTE format( EXECUTE format(
'INSERT INTO %I (%I, %I) 'INSERT INTO %I (%I, %I)
VALUES (%L, %L) VALUES (%L, %L)
ON CONFLICT (%I, %I) DO NOTHING', ON CONFLICT (%I, %I) DO NOTHING',
field_config->>'mapping_table', field_config->>'mapping_table',
field_config->>'column1', field_config->>'column1',
@ -153,24 +153,24 @@ def setup_db_level_functions(env):
-- Log the record data for debugging -- Log the record data for debugging
RAISE NOTICE 'Record data: %', record_data; RAISE NOTICE 'Record data: %', record_data;
SELECT SELECT
string_agg(quote_ident(c.column_name), ', '), string_agg(quote_ident(c.column_name), ', '),
string_agg( string_agg(
CASE CASE
WHEN c.data_type IN ('integer', 'bigint') THEN format('CAST(($2->>%L) AS INTEGER)', c.column_name) WHEN c.data_type IN ('integer', 'bigint') THEN format('CAST(($2->>%L) AS INTEGER)', c.column_name)
WHEN c.data_type = 'numeric' THEN format('CAST(($2->>%L) AS NUMERIC)', c.column_name) WHEN c.data_type = 'numeric' THEN format('CAST(($2->>%L) AS NUMERIC)', c.column_name)
WHEN c.data_type = 'double precision' THEN format('CAST(($2->>%L) AS DOUBLE PRECISION)', c.column_name) WHEN c.data_type = 'double precision' THEN format('CAST(($2->>%L) AS DOUBLE PRECISION)', c.column_name)
WHEN c.data_type = 'boolean' THEN format('CAST(($2->>%L) AS BOOLEAN)', c.column_name) WHEN c.data_type = 'boolean' THEN format('CAST(($2->>%L) AS BOOLEAN)', c.column_name)
WHEN c.data_type = 'date' THEN format('CAST(($2->>%L) AS DATE)', c.column_name) WHEN c.data_type = 'date' THEN format('CAST(($2->>%L) AS DATE)', c.column_name)
-- FIXED: Handle all timestamp variations -- FIXED: Handle all timestamp variations
WHEN c.data_type IN ('timestamp without time zone', 'timestamp with time zone') WHEN c.data_type IN ('timestamp without time zone', 'timestamp with time zone')
THEN format('CAST(($2->>%L) AS TIMESTAMP)', c.column_name) THEN format('CAST(($2->>%L) AS TIMESTAMP)', c.column_name)
WHEN c.data_type = 'datetime' THEN format('CAST(($2->>%L) AS TIMESTAMP)', c.column_name) WHEN c.data_type = 'datetime' THEN format('CAST(($2->>%L) AS TIMESTAMP)', c.column_name)
ELSE format('$2->>%L', c.column_name) ELSE format('$2->>%L', c.column_name)
END, END,
', ' ', '
) )
INTO INTO
column_list, column_list,
value_list value_list
FROM information_schema.columns c FROM information_schema.columns c

47
instant_import/static/description/index.html

@ -169,7 +169,7 @@
<span <span
class="pl-2" class="pl-2"
style=" font-size: 16px; vertical-align: middle" style=" font-size: 16px; vertical-align: middle"
>Email Us</span >Email Us</span
> >
</a> </a>
<a href="skype:cybroopenerp?chat" <a href="skype:cybroopenerp?chat"
@ -212,6 +212,44 @@
<img src="./assets/icons/patter.svg"> <img src="./assets/icons/patter.svg">
</div> </div>
</div> </div>
<section class="oe_container">
<div class="mt64 mb64">
<div class="col-sm-12 py-4">
<div class="alert alert-primary mt-4"
style="color: #000;background-color: #f8f8f8;border: 1px solid #dcdcdc;border-radius: 16px;">
This module uses some external python dependencies :
pandas. Before
installing the module install the python
package
first. The required python packages can be installed using the
following commands.
<br>
<br/>
<code class="d-block mt-2"
style="background-color:#4e4e4e;color: #fff;padding: 6px 8px; border-radius: 5px;">pip
install pandas</code>
<br>
<br/>
For smoother performance during limit handling and bulk imports, you may optionally
increase processing time in <span><b>odoo.conf</b></span> by adjusting <span><b>limit_time_cpu</b></span>
and <span><b>limit_time_real</b></span>.
<br>
<code class="d-block mt-2"
style="background-color:#4e4e4e;color: #fff; border-radius: 5px; padding: 6px 8px;">limit_time_cpu
= 600<br>
limit_time_real = 9999<br/>
</code><br>
The ability to update existing records during import is not yet implemented.
Currently, the importer supports only the creation of new records,
Updates to existing entries will be available in a future release.
</div>
</div>
</div>
</section>
<!-- key-highlight --> <!-- key-highlight -->
<div class="" style="border-radius: 16px; <div class="" style="border-radius: 16px;
padding: 60px 40px; padding: 60px 40px;
@ -568,7 +606,8 @@
style="color:#fff; font-size:14px"></i> style="color:#fff; font-size:14px"></i>
</div> </div>
<p style="color:#1A202C; font-weight:600; font-size:1.2rem; margin-bottom:2px"> <p style="color:#1A202C; font-weight:600; font-size:1.2rem; margin-bottom:2px">
Ensures clean and consistent import for Many2one, One2many and Many2many relational fields. Ensures clean and consistent import for Many2one, One2many and Many2many
relational fields.
</p> </p>
</div> </div>
@ -885,7 +924,9 @@
</div> </div>
</a> </a>
</div> </div>
</div></section></div> </div>
</section>
</div>
<!-- licence --> <!-- licence -->
<div class="tab-pane fade" id="profile" role="tabpanel" <div class="tab-pane fade" id="profile" role="tabpanel"
aria-labelledby="profile-tab"> aria-labelledby="profile-tab">

1968
instant_import/wizard/import_wizard.py

File diff suppressed because it is too large
Loading…
Cancel
Save